feat(testing): project generator should accept baseUrl
This commit is contained in:
parent
98a1701886
commit
3aafa8bb6a
@ -21,7 +21,7 @@ The path of the Cypress configuration json file.
|
||||
|
||||
Type: `string`
|
||||
|
||||
Use this to pass directly the address of your distant server address with the port running your application
|
||||
The address (with the port) which your application is running on
|
||||
|
||||
### browser
|
||||
|
||||
|
||||
@ -35,6 +35,12 @@ Type: `string`
|
||||
|
||||
Name of the E2E Project
|
||||
|
||||
### baseUrl
|
||||
|
||||
Type: `string`
|
||||
|
||||
The address (with the port) which your application is running on
|
||||
|
||||
### directory
|
||||
|
||||
Type: `string`
|
||||
|
||||
@ -21,7 +21,7 @@ The path of the Cypress configuration json file.
|
||||
|
||||
Type: `string`
|
||||
|
||||
Use this to pass directly the address of your distant server address with the port running your application
|
||||
The address (with the port) which your application is running on
|
||||
|
||||
### browser
|
||||
|
||||
|
||||
@ -35,6 +35,12 @@ Type: `string`
|
||||
|
||||
Name of the E2E Project
|
||||
|
||||
### baseUrl
|
||||
|
||||
Type: `string`
|
||||
|
||||
The address (with the port) which your application is running on
|
||||
|
||||
### directory
|
||||
|
||||
Type: `string`
|
||||
|
||||
@ -21,7 +21,7 @@ The path of the Cypress configuration json file.
|
||||
|
||||
Type: `string`
|
||||
|
||||
Use this to pass directly the address of your distant server address with the port running your application
|
||||
The address (with the port) which your application is running on
|
||||
|
||||
### browser
|
||||
|
||||
|
||||
@ -35,6 +35,12 @@ Type: `string`
|
||||
|
||||
Name of the E2E Project
|
||||
|
||||
### baseUrl
|
||||
|
||||
Type: `string`
|
||||
|
||||
The address (with the port) which your application is running on
|
||||
|
||||
### directory
|
||||
|
||||
Type: `string`
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nrwl/nx-source",
|
||||
"version": "13.4.2",
|
||||
"version": "13.4.3-beta.1",
|
||||
"description": "Smart, Fast and Extensible Build System",
|
||||
"homepage": "https://nx.dev",
|
||||
"private": true,
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
},
|
||||
"baseUrl": {
|
||||
"type": "string",
|
||||
"description": "Use this to pass directly the address of your distant server address with the port running your application"
|
||||
"description": "The address (with the port) which your application is running on"
|
||||
},
|
||||
"browser": {
|
||||
"type": "string",
|
||||
|
||||
@ -119,6 +119,36 @@ describe('schematic:cypress-project', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should add update `workspace.json` file (baseUrl)', async () => {
|
||||
await cypressProjectGenerator(tree, {
|
||||
name: 'my-app-e2e',
|
||||
project: 'my-app',
|
||||
baseUrl: 'http://localhost:3000',
|
||||
linter: Linter.TsLint,
|
||||
standaloneConfig: false,
|
||||
});
|
||||
const workspaceJson = readJson(tree, 'workspace.json');
|
||||
const project = workspaceJson.projects['my-app-e2e'];
|
||||
|
||||
expect(project.root).toEqual('apps/my-app-e2e');
|
||||
|
||||
expect(project.architect.lint).toEqual({
|
||||
builder: '@angular-devkit/build-angular:tslint',
|
||||
options: {
|
||||
tsConfig: ['apps/my-app-e2e/tsconfig.json'],
|
||||
exclude: ['**/node_modules/**', '!apps/my-app-e2e/**/*'],
|
||||
},
|
||||
});
|
||||
expect(project.architect.e2e).toEqual({
|
||||
builder: '@nrwl/cypress:cypress',
|
||||
options: {
|
||||
cypressConfig: 'apps/my-app-e2e/cypress.json',
|
||||
baseUrl: 'http://localhost:3000',
|
||||
tsConfig: 'apps/my-app-e2e/tsconfig.json',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should add update `workspace.json` file for a project with a defaultConfiguration', async () => {
|
||||
const originalProject = readProjectConfiguration(tree, 'my-app');
|
||||
originalProject.targets.serve.defaultConfiguration = 'development';
|
||||
@ -321,6 +351,7 @@ describe('schematic:cypress-project', () => {
|
||||
await cypressProjectGenerator(tree, {
|
||||
...defaultOptions,
|
||||
name: 'my-app-e2e',
|
||||
baseUrl: 'http://localhost:7788',
|
||||
});
|
||||
|
||||
const workspaceJson = readJson<WorkspaceJsonConfiguration>(
|
||||
|
||||
@ -57,39 +57,64 @@ function createFiles(tree: Tree, options: CypressProjectSchema) {
|
||||
}
|
||||
|
||||
function addProject(tree: Tree, options: CypressProjectSchema) {
|
||||
let devServerTarget: string = `${options.project}:serve`;
|
||||
if (options.project) {
|
||||
const project = readProjectConfiguration(tree, options.project);
|
||||
devServerTarget =
|
||||
project.targets.serve && project.targets.serve.defaultConfiguration
|
||||
? `${options.project}:serve:${project.targets.serve.defaultConfiguration}`
|
||||
: devServerTarget;
|
||||
}
|
||||
|
||||
const project: ProjectConfiguration = {
|
||||
root: options.projectRoot,
|
||||
sourceRoot: joinPathFragments(options.projectRoot, 'src'),
|
||||
projectType: 'application',
|
||||
targets: {
|
||||
e2e: {
|
||||
executor: '@nrwl/cypress:cypress',
|
||||
options: {
|
||||
cypressConfig: joinPathFragments(options.projectRoot, 'cypress.json'),
|
||||
devServerTarget,
|
||||
},
|
||||
configurations: {
|
||||
production: {
|
||||
devServerTarget: `${options.project}:serve:production`,
|
||||
let e2eProjectConfig: ProjectConfiguration;
|
||||
if (options.baseUrl) {
|
||||
e2eProjectConfig = {
|
||||
root: options.projectRoot,
|
||||
sourceRoot: joinPathFragments(options.projectRoot, 'src'),
|
||||
projectType: 'application',
|
||||
targets: {
|
||||
e2e: {
|
||||
executor: '@nrwl/cypress:cypress',
|
||||
options: {
|
||||
cypressConfig: joinPathFragments(
|
||||
options.projectRoot,
|
||||
'cypress.json'
|
||||
),
|
||||
baseUrl: options.baseUrl,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
tags: [],
|
||||
implicitDependencies: options.project ? [options.project] : undefined,
|
||||
};
|
||||
tags: [],
|
||||
implicitDependencies: options.project ? [options.project] : undefined,
|
||||
};
|
||||
} else if (options.project) {
|
||||
const project = readProjectConfiguration(tree, options.project);
|
||||
const devServerTarget =
|
||||
project.targets.serve && project.targets.serve.defaultConfiguration
|
||||
? `${options.project}:serve:${project.targets.serve.defaultConfiguration}`
|
||||
: `${options.project}:serve`;
|
||||
e2eProjectConfig = {
|
||||
root: options.projectRoot,
|
||||
sourceRoot: joinPathFragments(options.projectRoot, 'src'),
|
||||
projectType: 'application',
|
||||
targets: {
|
||||
e2e: {
|
||||
executor: '@nrwl/cypress:cypress',
|
||||
options: {
|
||||
cypressConfig: joinPathFragments(
|
||||
options.projectRoot,
|
||||
'cypress.json'
|
||||
),
|
||||
devServerTarget,
|
||||
},
|
||||
configurations: {
|
||||
production: {
|
||||
devServerTarget: `${options.project}:serve:production`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
tags: [],
|
||||
implicitDependencies: options.project ? [options.project] : undefined,
|
||||
};
|
||||
} else {
|
||||
throw new Error(`Either project or baseUrl should be specified.`);
|
||||
}
|
||||
|
||||
const detectedCypressVersion = installedCypressVersion() ?? cypressVersion;
|
||||
if (detectedCypressVersion < 7) {
|
||||
project.targets.e2e.options.tsConfig = joinPathFragments(
|
||||
e2eProjectConfig.targets.e2e.options.tsConfig = joinPathFragments(
|
||||
options.projectRoot,
|
||||
'tsconfig.json'
|
||||
);
|
||||
@ -97,7 +122,7 @@ function addProject(tree: Tree, options: CypressProjectSchema) {
|
||||
addProjectConfiguration(
|
||||
tree,
|
||||
options.projectName,
|
||||
project,
|
||||
e2eProjectConfig,
|
||||
options.standaloneConfig
|
||||
);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ import { Linter } from '@nrwl/linter';
|
||||
|
||||
export interface Schema {
|
||||
project?: string;
|
||||
baseUrl?: string;
|
||||
name: string;
|
||||
directory?: string;
|
||||
linter?: Linter;
|
||||
|
||||
@ -12,6 +12,10 @@
|
||||
"$source": "projectName"
|
||||
}
|
||||
},
|
||||
"baseUrl": {
|
||||
"type": "string",
|
||||
"description": "The address (with the port) which your application is running on"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "Name of the E2E Project",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user