cleanup(testing): switch cypress tests to use project name and root as-provided format by default (#18927)

This commit is contained in:
Leosvel Pérez Espinosa 2023-08-31 15:00:50 +01:00 committed by GitHub
parent 1abe35c52b
commit a2493b92f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 252 additions and 230 deletions

View File

@ -4,7 +4,7 @@ exports[`Cypress Project < v7 --linter eslint should add eslint-plugin-cypress 1
{ {
"extends": [ "extends": [
"plugin:cypress/recommended", "plugin:cypress/recommended",
"../../.eslintrc.json", "../.eslintrc.json",
], ],
"ignorePatterns": [ "ignorePatterns": [
"!**/*", "!**/*",
@ -42,17 +42,17 @@ exports[`Cypress Project < v7 nested should update configuration 1`] = `
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"cypressConfig": "apps/my-dir/my-app-e2e/cypress.json", "cypressConfig": "my-dir/my-app-e2e/cypress.json",
"devServerTarget": "my-dir-my-app:serve", "devServerTarget": "my-dir-my-app:serve",
"testingType": "e2e", "testingType": "e2e",
"tsConfig": "apps/my-dir/my-app-e2e/tsconfig.json", "tsConfig": "my-dir/my-app-e2e/tsconfig.json",
}, },
}, },
"lint": { "lint": {
"executor": "@nx/linter:eslint", "executor": "@nx/linter:eslint",
"options": { "options": {
"lintFilePatterns": [ "lintFilePatterns": [
"apps/my-dir/my-app-e2e/**/*.{js,ts}", "my-dir/my-app-e2e/**/*.{js,ts}",
], ],
}, },
"outputs": [ "outputs": [
@ -71,8 +71,8 @@ exports[`Cypress Project < v7 project with directory in its name should set righ
"supportFile": "./src/support/index.ts", "supportFile": "./src/support/index.ts",
"pluginsFile": "./src/plugins/index", "pluginsFile": "./src/plugins/index",
"video": true, "video": true,
"videosFolder": "../../../dist/cypress/apps/my-dir/my-app-e2e/videos", "videosFolder": "../../dist/cypress/my-dir/my-app-e2e/videos",
"screenshotsFolder": "../../../dist/cypress/apps/my-dir/my-app-e2e/screenshots", "screenshotsFolder": "../../dist/cypress/my-dir/my-app-e2e/screenshots",
"chromeWebSecurity": false "chromeWebSecurity": false
} }
" "
@ -88,17 +88,17 @@ exports[`Cypress Project < v7 project with directory in its name should update c
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"cypressConfig": "apps/my-dir/my-app-e2e/cypress.json", "cypressConfig": "my-dir/my-app-e2e/cypress.json",
"devServerTarget": "my-dir-my-app:serve", "devServerTarget": "my-dir-my-app:serve",
"testingType": "e2e", "testingType": "e2e",
"tsConfig": "apps/my-dir/my-app-e2e/tsconfig.json", "tsConfig": "my-dir/my-app-e2e/tsconfig.json",
}, },
}, },
"lint": { "lint": {
"executor": "@nx/linter:eslint", "executor": "@nx/linter:eslint",
"options": { "options": {
"lintFilePatterns": [ "lintFilePatterns": [
"apps/my-dir/my-app-e2e/**/*.{js,ts}", "my-dir/my-app-e2e/**/*.{js,ts}",
], ],
}, },
"outputs": [ "outputs": [
@ -108,22 +108,22 @@ exports[`Cypress Project < v7 project with directory in its name should update c
} }
`; `;
exports[`Cypress Project < v7 should update configuration (baseUrl) 1`] = ` exports[`Cypress Project < v7 should update project configuration (baseUrl) 1`] = `
{ {
"e2e": { "e2e": {
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"baseUrl": "http://localhost:3000", "baseUrl": "http://localhost:3000",
"cypressConfig": "apps/my-app-e2e/cypress.json", "cypressConfig": "my-app-e2e/cypress.json",
"testingType": "e2e", "testingType": "e2e",
"tsConfig": "apps/my-app-e2e/tsconfig.json", "tsConfig": "my-app-e2e/tsconfig.json",
}, },
}, },
"lint": { "lint": {
"executor": "@nx/linter:eslint", "executor": "@nx/linter:eslint",
"options": { "options": {
"lintFilePatterns": [ "lintFilePatterns": [
"apps/my-app-e2e/**/*.{js,ts}", "my-app-e2e/**/*.{js,ts}",
], ],
}, },
"outputs": [ "outputs": [
@ -133,7 +133,7 @@ exports[`Cypress Project < v7 should update configuration (baseUrl) 1`] = `
} }
`; `;
exports[`Cypress Project < v7 should update configuration 1`] = ` exports[`Cypress Project < v7 should update project configuration 1`] = `
{ {
"e2e": { "e2e": {
"configurations": { "configurations": {
@ -143,17 +143,17 @@ exports[`Cypress Project < v7 should update configuration 1`] = `
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"cypressConfig": "apps/my-app-e2e/cypress.json", "cypressConfig": "my-app-e2e/cypress.json",
"devServerTarget": "my-app:serve", "devServerTarget": "my-app:serve",
"testingType": "e2e", "testingType": "e2e",
"tsConfig": "apps/my-app-e2e/tsconfig.json", "tsConfig": "my-app-e2e/tsconfig.json",
}, },
}, },
"lint": { "lint": {
"executor": "@nx/linter:eslint", "executor": "@nx/linter:eslint",
"options": { "options": {
"lintFilePatterns": [ "lintFilePatterns": [
"apps/my-app-e2e/**/*.{js,ts}", "my-app-e2e/**/*.{js,ts}",
], ],
}, },
"outputs": [ "outputs": [
@ -163,7 +163,7 @@ exports[`Cypress Project < v7 should update configuration 1`] = `
} }
`; `;
exports[`Cypress Project < v7 should update configuration 2`] = ` exports[`Cypress Project < v7 should update target configurations 1`] = `
{ {
"e2e": { "e2e": {
"configurations": { "configurations": {
@ -173,17 +173,17 @@ exports[`Cypress Project < v7 should update configuration 2`] = `
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"cypressConfig": "apps/my-app-e2e/cypress.json", "cypressConfig": "my-app-e2e/cypress.json",
"devServerTarget": "my-app:serve:development", "devServerTarget": "my-app:serve:development",
"testingType": "e2e", "testingType": "e2e",
"tsConfig": "apps/my-app-e2e/tsconfig.json", "tsConfig": "my-app-e2e/tsconfig.json",
}, },
}, },
"lint": { "lint": {
"executor": "@nx/linter:eslint", "executor": "@nx/linter:eslint",
"options": { "options": {
"lintFilePatterns": [ "lintFilePatterns": [
"apps/my-app-e2e/**/*.{js,ts}", "my-app-e2e/**/*.{js,ts}",
], ],
}, },
"outputs": [ "outputs": [
@ -219,14 +219,14 @@ exports[`Cypress Project > v10 nested should set right path names in \`tsconfig.
{ {
"compilerOptions": { "compilerOptions": {
"allowJs": true, "allowJs": true,
"outDir": "../../../dist/out-tsc", "outDir": "../../dist/out-tsc",
"sourceMap": false, "sourceMap": false,
"types": [ "types": [
"cypress", "cypress",
"node", "node",
], ],
}, },
"extends": "../../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"include": [ "include": [
"src/**/*.ts", "src/**/*.ts",
"src/**/*.js", "src/**/*.js",
@ -249,14 +249,14 @@ exports[`Cypress Project > v10 should set right path names in \`tsconfig.e2e.jso
{ {
"compilerOptions": { "compilerOptions": {
"allowJs": true, "allowJs": true,
"outDir": "../../dist/out-tsc", "outDir": "../dist/out-tsc",
"sourceMap": false, "sourceMap": false,
"types": [ "types": [
"cypress", "cypress",
"node", "node",
], ],
}, },
"extends": "../../tsconfig.base.json", "extends": "../tsconfig.base.json",
"include": [ "include": [
"src/**/*.ts", "src/**/*.ts",
"src/**/*.js", "src/**/*.js",
@ -270,7 +270,7 @@ exports[`Cypress Project > v10 should update configuration when eslint is passed
"executor": "@nx/linter:eslint", "executor": "@nx/linter:eslint",
"options": { "options": {
"lintFilePatterns": [ "lintFilePatterns": [
"apps/my-app-e2e/**/*.{js,ts}", "my-app-e2e/**/*.{js,ts}",
], ],
}, },
"outputs": [ "outputs": [

View File

@ -58,21 +58,27 @@ describe('Cypress Project', () => {
it('should call init if cypress is not installed', async () => { it('should call init if cypress is not installed', async () => {
mockedInstalledCypressVersion.mockReturnValue(null); mockedInstalledCypressVersion.mockReturnValue(null);
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
expect(mockInitCypress).toHaveBeenCalled(); expect(mockInitCypress).toHaveBeenCalled();
}); });
it('should call not init if cypress is installed', async () => { it('should call not init if cypress is installed', async () => {
mockedInstalledCypressVersion.mockReturnValue(10); mockedInstalledCypressVersion.mockReturnValue(10);
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
expect(mockInitCypress).not.toHaveBeenCalled(); expect(mockInitCypress).not.toHaveBeenCalled();
}); });
@ -86,19 +92,15 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
expect(tree.exists('apps/my-app-e2e/cypress.config.ts')).toBeTruthy(); expect(tree.exists('my-app-e2e/cypress.config.ts')).toBeTruthy();
expect(tree.exists('my-app-e2e/src/fixtures/example.json')).toBeTruthy();
expect( expect(tree.exists('my-app-e2e/src/e2e/app.cy.ts')).toBeTruthy();
tree.exists('apps/my-app-e2e/src/fixtures/example.json') expect(tree.exists('my-app-e2e/src/support/app.po.ts')).toBeTruthy();
).toBeTruthy(); expect(tree.exists('my-app-e2e/src/support/commands.ts')).toBeTruthy();
expect(tree.exists('apps/my-app-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('my-app-e2e/src/support/e2e.ts')).toBeTruthy();
expect(tree.exists('apps/my-app-e2e/src/support/app.po.ts')).toBeTruthy();
expect(
tree.exists('apps/my-app-e2e/src/support/commands.ts')
).toBeTruthy();
expect(tree.exists('apps/my-app-e2e/src/support/e2e.ts')).toBeTruthy();
}); });
it('should update configuration when eslint is passed', async () => { it('should update configuration when eslint is passed', async () => {
@ -106,7 +108,9 @@ describe('Cypress Project', () => {
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
linter: Linter.EsLint, linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
}); });
const project = readProjectConfiguration(tree, 'my-app-e2e'); const project = readProjectConfiguration(tree, 'my-app-e2e');
expect(project.targets.lint).toMatchSnapshot(); expect(project.targets.lint).toMatchSnapshot();
}); });
@ -116,7 +120,9 @@ describe('Cypress Project', () => {
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
linter: Linter.None, linter: Linter.None,
projectNameAndRootFormat: 'as-provided',
}); });
const project = readProjectConfiguration(tree, 'my-app-e2e'); const project = readProjectConfiguration(tree, 'my-app-e2e');
expect(project.targets.lint).toBeUndefined(); expect(project.targets.lint).toBeUndefined();
}); });
@ -126,6 +132,7 @@ describe('Cypress Project', () => {
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
linter: Linter.EsLint, linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
}); });
const project = readProjectConfiguration(tree, 'my-app-e2e'); const project = readProjectConfiguration(tree, 'my-app-e2e');
@ -138,11 +145,10 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
const cypressConfig = tree.read(
'apps/my-app-e2e/cypress.config.ts', const cypressConfig = tree.read('my-app-e2e/cypress.config.ts', 'utf-8');
'utf-8'
);
expect(cypressConfig).toMatchSnapshot(); expect(cypressConfig).toMatchSnapshot();
}); });
@ -151,8 +157,10 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
const tsconfigJson = readJson(tree, 'apps/my-app-e2e/tsconfig.json');
const tsconfigJson = readJson(tree, 'my-app-e2e/tsconfig.json');
expect(tsconfigJson).toMatchSnapshot(); expect(tsconfigJson).toMatchSnapshot();
}); });
@ -161,10 +169,11 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
const tsConfig = readJson(tree, 'apps/my-app-e2e/tsconfig.json'); const tsConfig = readJson(tree, 'my-app-e2e/tsconfig.json');
expect(tsConfig.extends).toBe('../../tsconfig.base.json'); expect(tsConfig.extends).toBe('../tsconfig.base.json');
}); });
it('should support a root tsconfig.json instead of tsconfig.base.json', async () => { it('should support a root tsconfig.json instead of tsconfig.base.json', async () => {
@ -174,10 +183,11 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
const tsConfig = readJson(tree, 'apps/my-app-e2e/tsconfig.json'); const tsConfig = readJson(tree, 'my-app-e2e/tsconfig.json');
expect(tsConfig.extends).toBe('../../tsconfig.json'); expect(tsConfig.extends).toBe('../tsconfig.json');
}); });
describe('for bundler:vite', () => { describe('for bundler:vite', () => {
@ -187,9 +197,11 @@ describe('Cypress Project', () => {
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
bundler: 'vite', bundler: 'vite',
projectNameAndRootFormat: 'as-provided',
}); });
const cypressConfig = tree.read( const cypressConfig = tree.read(
'apps/my-app-e2e/cypress.config.ts', 'my-app-e2e/cypress.config.ts',
'utf-8' 'utf-8'
); );
expect(cypressConfig).toMatchSnapshot(); expect(cypressConfig).toMatchSnapshot();
@ -202,11 +214,12 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-dir-my-app', project: 'my-dir-my-app',
directory: 'my-dir', directory: 'my-dir/my-app-e2e',
projectNameAndRootFormat: 'as-provided',
}); });
const cypressConfig = tree.read( const cypressConfig = tree.read(
'apps/my-dir/my-app-e2e/cypress.config.ts', 'my-dir/my-app-e2e/cypress.config.ts',
'utf-8' 'utf-8'
); );
expect(cypressConfig).toMatchSnapshot(); expect(cypressConfig).toMatchSnapshot();
@ -217,13 +230,11 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-dir-my-app', project: 'my-dir-my-app',
directory: 'my-dir', directory: 'my-dir/my-app-e2e',
projectNameAndRootFormat: 'as-provided',
}); });
const tsconfigJson = readJson(
tree,
'apps/my-dir/my-app-e2e/tsconfig.json'
);
const tsconfigJson = readJson(tree, 'my-dir/my-app-e2e/tsconfig.json');
expect(tsconfigJson).toMatchSnapshot(); expect(tsconfigJson).toMatchSnapshot();
}); });
@ -232,11 +243,12 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
directory: 'my-dir', directory: 'my-dir/my-app-e2e',
projectNameAndRootFormat: 'as-provided',
}); });
const tsConfig = readJson(tree, 'apps/my-dir/my-app-e2e/tsconfig.json'); const tsConfig = readJson(tree, 'my-dir/my-app-e2e/tsconfig.json');
expect(tsConfig.extends).toBe('../../../tsconfig.base.json'); expect(tsConfig.extends).toBe('../../tsconfig.base.json');
}); });
it('should support a root tsconfig.json instead of tsconfig.base.json', async () => { it('should support a root tsconfig.json instead of tsconfig.base.json', async () => {
@ -246,24 +258,26 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
directory: 'my-dir', directory: 'my-dir/my-app-e2e',
projectNameAndRootFormat: 'as-provided',
}); });
const tsConfig = readJson(tree, 'apps/my-dir/my-app-e2e/tsconfig.json'); const tsConfig = readJson(tree, 'my-dir/my-app-e2e/tsconfig.json');
expect(tsConfig.extends).toBe('../../../tsconfig.json'); expect(tsConfig.extends).toBe('../../tsconfig.json');
}); });
describe('root project', () => { describe('root project', () => {
it('should generate in option.name when root project detected', async () => { it('should generate in option.name when root project detected', async () => {
addProjectConfiguration(tree, 'root', { addProjectConfiguration(tree, 'root', { root: '.' });
root: '.',
});
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
...defaultOptions, ...defaultOptions,
name: 'e2e-tests', name: 'e2e-tests',
baseUrl: 'http://localhost:1234', baseUrl: 'http://localhost:1234',
project: 'root', project: 'root',
projectNameAndRootFormat: 'as-provided',
}); });
expect(tree.listChanges().map((c) => c.path)).toEqual( expect(tree.listChanges().map((c) => c.path)).toEqual(
expect.arrayContaining([ expect.arrayContaining([
'e2e-tests/cypress.config.ts', 'e2e-tests/cypress.config.ts',
@ -278,27 +292,26 @@ describe('Cypress Project', () => {
}); });
it('should not generate a root project when the passed in project is not the root project', async () => { it('should not generate a root project when the passed in project is not the root project', async () => {
addProjectConfiguration(tree, 'root', { addProjectConfiguration(tree, 'root', { root: '.' });
root: '.', addProjectConfiguration(tree, 'my-cool-app', { root: 'my-cool-app' });
});
addProjectConfiguration(tree, 'my-cool-app', {
root: 'apps/my-app',
});
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
...defaultOptions, ...defaultOptions,
name: 'e2e-tests', name: 'e2e-tests',
baseUrl: 'http://localhost:1234', baseUrl: 'http://localhost:1234',
project: 'my-app', project: 'my-cool-app',
projectNameAndRootFormat: 'as-provided',
}); });
expect(tree.listChanges().map((c) => c.path)).toEqual( expect(tree.listChanges().map((c) => c.path)).toEqual(
expect.arrayContaining([ expect.arrayContaining([
'apps/e2e-tests/cypress.config.ts', 'e2e-tests/cypress.config.ts',
'apps/e2e-tests/src/e2e/app.cy.ts', 'e2e-tests/src/e2e/app.cy.ts',
'apps/e2e-tests/src/fixtures/example.json', 'e2e-tests/src/fixtures/example.json',
'apps/e2e-tests/src/support/app.po.ts', 'e2e-tests/src/support/app.po.ts',
'apps/e2e-tests/src/support/commands.ts', 'e2e-tests/src/support/commands.ts',
'apps/e2e-tests/src/support/e2e.ts', 'e2e-tests/src/support/e2e.ts',
'apps/e2e-tests/tsconfig.json', 'e2e-tests/tsconfig.json',
]) ])
); );
}); });
@ -312,6 +325,7 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
baseUrl: 'http://localhost:7788', baseUrl: 'http://localhost:7788',
projectNameAndRootFormat: 'as-provided',
}); });
const projectConfig = readProjectConfiguration(tree, 'my-app-e2e'); const projectConfig = readProjectConfiguration(tree, 'my-app-e2e');
@ -323,12 +337,13 @@ describe('Cypress Project', () => {
it('should not throw an error when --project does not have targets', async () => { it('should not throw an error when --project does not have targets', async () => {
const projectConf = readProjectConfiguration(tree, 'my-app'); const projectConf = readProjectConfiguration(tree, 'my-app');
delete projectConf.targets; delete projectConf.targets;
updateProjectConfiguration(tree, 'my-app', projectConf); updateProjectConfiguration(tree, 'my-app', projectConf);
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
linter: Linter.EsLint, linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
}); });
const projectConfig = readProjectConfiguration(tree, 'my-app-e2e'); const projectConfig = readProjectConfiguration(tree, 'my-app-e2e');
@ -339,12 +354,31 @@ describe('Cypress Project', () => {
}); });
it('should generate in the correct folder', async () => { it('should generate in the correct folder', async () => {
await cypressProjectGenerator(tree, {
...defaultOptions,
name: 'one-two-other-e2e',
project: 'my-app',
directory: 'one/two/other-e2e',
projectNameAndRootFormat: 'as-provided',
});
const project = readProjectConfiguration(tree, 'one-two-other-e2e');
expect(project).toBeDefined();
[
'one/two/other-e2e/cypress.config.ts',
'one/two/other-e2e/src/e2e/app.cy.ts',
].forEach((path) => expect(tree.exists(path)).toBeTruthy());
});
it('should generate in the correct folder when --project-name-and-root-format=derived', async () => {
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
...defaultOptions, ...defaultOptions,
name: 'other-e2e', name: 'other-e2e',
project: 'my-app', project: 'my-app',
directory: 'one/two', directory: 'one/two',
projectNameAndRootFormat: 'derived',
}); });
const project = readProjectConfiguration(tree, 'one-two-other-e2e'); const project = readProjectConfiguration(tree, 'one-two-other-e2e');
expect(project).toBeDefined(); expect(project).toBeDefined();
[ [
@ -369,6 +403,7 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
const e2eConfig = readProjectConfiguration(tree, 'my-app-e2e'); const e2eConfig = readProjectConfiguration(tree, 'my-app-e2e');
@ -388,6 +423,7 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
const e2eConfig = readProjectConfiguration(tree, 'my-app-e2e'); const e2eConfig = readProjectConfiguration(tree, 'my-app-e2e');
@ -400,26 +436,23 @@ describe('Cypress Project', () => {
beforeEach(() => { beforeEach(() => {
mockedInstalledCypressVersion.mockReturnValue(9); mockedInstalledCypressVersion.mockReturnValue(9);
}); });
it('should generate files', async () => { it('should generate files', async () => {
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
expect(tree.exists('apps/my-app-e2e/cypress.json')).toBeTruthy(); expect(tree.exists('my-app-e2e/cypress.json')).toBeTruthy();
expect(tree.exists('my-app-e2e/src/fixtures/example.json')).toBeTruthy();
expect( expect(
tree.exists('apps/my-app-e2e/src/fixtures/example.json') tree.exists('my-app-e2e/src/integration/app.spec.ts')
).toBeTruthy(); ).toBeTruthy();
expect( expect(tree.exists('my-app-e2e/src/support/app.po.ts')).toBeTruthy();
tree.exists('apps/my-app-e2e/src/integration/app.spec.ts') expect(tree.exists('my-app-e2e/src/support/commands.ts')).toBeTruthy();
).toBeTruthy(); expect(tree.exists('my-app-e2e/src/support/index.ts')).toBeTruthy();
expect(tree.exists('apps/my-app-e2e/src/support/app.po.ts')).toBeTruthy();
expect(
tree.exists('apps/my-app-e2e/src/support/commands.ts')
).toBeTruthy();
expect(tree.exists('apps/my-app-e2e/src/support/index.ts')).toBeTruthy();
}); });
}); });
@ -433,39 +466,40 @@ describe('Cypress Project', () => {
...defaultOptions, ...defaultOptions,
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
projectNameAndRootFormat: 'as-provided',
}); });
expect(tree.exists('apps/my-app-e2e/src/plugins/index.js')).toBeTruthy(); expect(tree.exists('my-app-e2e/src/plugins/index.js')).toBeTruthy();
}); });
it('should update configuration', async () => { it('should update project configuration', async () => {
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
linter: Linter.EsLint, linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
}); });
const project = readProjectConfiguration(tree, 'my-app-e2e'); const project = readProjectConfiguration(tree, 'my-app-e2e');
expect(project.root).toEqual('my-app-e2e');
expect(project.root).toEqual('apps/my-app-e2e');
expect(project.targets).toMatchSnapshot(); expect(project.targets).toMatchSnapshot();
}); });
it('should update configuration (baseUrl)', async () => { it('should update project configuration (baseUrl)', async () => {
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
baseUrl: 'http://localhost:3000', baseUrl: 'http://localhost:3000',
linter: Linter.EsLint, linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
}); });
const project = readProjectConfiguration(tree, 'my-app-e2e'); const project = readProjectConfiguration(tree, 'my-app-e2e');
expect(project.root).toEqual('apps/my-app-e2e'); expect(project.root).toEqual('my-app-e2e');
expect(project.targets).toMatchSnapshot(); expect(project.targets).toMatchSnapshot();
}); });
it('should update configuration', async () => { it('should update target configurations', async () => {
const originalProject = readProjectConfiguration(tree, 'my-app'); const originalProject = readProjectConfiguration(tree, 'my-app');
originalProject.targets.serve.defaultConfiguration = 'development'; originalProject.targets.serve.defaultConfiguration = 'development';
originalProject.targets.serve.configurations.development = {}; originalProject.targets.serve.configurations.development = {};
@ -475,22 +509,22 @@ describe('Cypress Project', () => {
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
linter: Linter.EsLint, linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
}); });
const project = readProjectConfiguration(tree, 'my-app-e2e'); const project = readProjectConfiguration(tree, 'my-app-e2e');
expect(project.root).toEqual('my-app-e2e');
expect(project.root).toEqual('apps/my-app-e2e');
expect(project.targets).toMatchSnapshot(); expect(project.targets).toMatchSnapshot();
}); });
describe('nested', () => { describe('nested', () => {
it('should update configuration', async () => { it('should update configuration', async () => {
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
name: 'my-app-e2e', name: 'my-dir-my-app-e2e',
project: 'my-dir-my-app', project: 'my-dir-my-app',
directory: 'my-dir', directory: 'my-dir/my-app-e2e',
linter: Linter.EsLint, linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
}); });
const projectConfig = readProjectConfiguration( const projectConfig = readProjectConfiguration(
@ -509,13 +543,14 @@ describe('Cypress Project', () => {
name: 'my-app-e2e', name: 'my-app-e2e',
project: 'my-app', project: 'my-app',
linter: Linter.EsLint, linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
}); });
const packageJson = readJson(tree, 'package.json'); const packageJson = readJson(tree, 'package.json');
expect( expect(
packageJson.devDependencies['eslint-plugin-cypress'] packageJson.devDependencies['eslint-plugin-cypress']
).toBeTruthy(); ).toBeTruthy();
const eslintrcJson = readJson(tree, 'my-app-e2e/.eslintrc.json');
const eslintrcJson = readJson(tree, 'apps/my-app-e2e/.eslintrc.json');
expect(eslintrcJson).toMatchSnapshot(); expect(eslintrcJson).toMatchSnapshot();
}); });
}); });
@ -524,9 +559,11 @@ describe('Cypress Project', () => {
describe('project with directory in its name', () => { describe('project with directory in its name', () => {
beforeEach(async () => { beforeEach(async () => {
await cypressProjectGenerator(tree, { await cypressProjectGenerator(tree, {
name: 'my-dir/my-app-e2e', name: 'my-dir-my-app-e2e',
project: 'my-dir-my-app', project: 'my-dir-my-app',
directory: 'my-dir/my-app-e2e',
linter: Linter.EsLint, linter: Linter.EsLint,
projectNameAndRootFormat: 'as-provided',
}); });
}); });
@ -547,10 +584,9 @@ describe('Cypress Project', () => {
it('should set right path names in `cypress.json`', async () => { it('should set right path names in `cypress.json`', async () => {
const cypressConfig = tree.read( const cypressConfig = tree.read(
'apps/my-dir/my-app-e2e/cypress.json', 'my-dir/my-app-e2e/cypress.json',
'utf-8' 'utf-8'
); );
expect(cypressConfig).toMatchSnapshot(); expect(cypressConfig).toMatchSnapshot();
}); });
}); });

View File

@ -8,8 +8,8 @@ const cypressJsonConfig = {
fileServerFolder: '.', fileServerFolder: '.',
fixturesFolder: './src/fixtures', fixturesFolder: './src/fixtures',
video: true, video: true,
videosFolder: '../../dist/cypress/apps/app-e2e/videos', videosFolder: '../dist/cypress/app-e2e/videos',
screenshotsFolder: '../../dist/cypress/apps/app-e2e/screenshots', screenshotsFolder: '../dist/cypress/app-e2e/screenshots',
chromeWebSecurity: false, chromeWebSecurity: false,
specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}', specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'src/support/e2e.ts', supportFile: 'src/support/e2e.ts',
@ -31,8 +31,8 @@ const cypressJsonConfig = {
fileServerFolder: '.', fileServerFolder: '.',
fixturesFolder: './src/fixtures', fixturesFolder: './src/fixtures',
video: true, video: true,
videosFolder: '../../dist/cypress/apps/app-e2e/videos', videosFolder: '../dist/cypress/app-e2e/videos',
screenshotsFolder: '../../dist/cypress/apps/app-e2e/screenshots', screenshotsFolder: '../dist/cypress/app-e2e/screenshots',
chromeWebSecurity: false, chromeWebSecurity: false,
specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}', specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'src/support/e2e.ts', supportFile: 'src/support/e2e.ts',
@ -58,7 +58,7 @@ exports[`convertToCypressTen convertCypressProject should handle multiple config
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"cypressConfig": "apps/app-e2e/cypress.config.ts", "cypressConfig": "app-e2e/cypress.config.ts",
"devServerTarget": "app:serve", "devServerTarget": "app:serve",
"testingType": "e2e", "testingType": "e2e",
}, },
@ -73,8 +73,8 @@ const cypressJsonConfig = {
fileServerFolder: '.', fileServerFolder: '.',
fixturesFolder: './src/fixtures', fixturesFolder: './src/fixtures',
video: true, video: true,
videosFolder: '../../dist/cypress/apps/app-e2e/videos', videosFolder: '../dist/cypress/app-e2e/videos',
screenshotsFolder: '../../dist/cypress/apps/app-e2e/screenshots', screenshotsFolder: '../dist/cypress/app-e2e/screenshots',
chromeWebSecurity: false, chromeWebSecurity: false,
specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}', specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'src/support/e2e.ts', supportFile: 'src/support/e2e.ts',
@ -92,12 +92,12 @@ exports[`convertToCypressTen convertCypressProject should handle multiple config
{ {
"configurations": { "configurations": {
"production": { "production": {
"cypressConfig": "apps/app-e2e/cypress.production.config.ts", "cypressConfig": "app-e2e/cypress.production.config.ts",
"devServerTarget": "target:serve:production", "devServerTarget": "target:serve:production",
}, },
"static": { "static": {
"baseUrl": "http://localhost:3000", "baseUrl": "http://localhost:3000",
"cypressConfig": "apps/app-e2e/cypress.config.ts", "cypressConfig": "app-e2e/cypress.config.ts",
}, },
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
@ -137,8 +137,8 @@ const cypressJsonConfig = {
fileServerFolder: '.', fileServerFolder: '.',
fixturesFolder: './src/fixtures', fixturesFolder: './src/fixtures',
video: true, video: true,
videosFolder: '../../dist/cypress/apps/app-e2e/videos', videosFolder: '../dist/cypress/app-e2e/videos',
screenshotsFolder: '../../dist/cypress/apps/app-e2e/screenshots', screenshotsFolder: '../dist/cypress/app-e2e/screenshots',
chromeWebSecurity: false, chromeWebSecurity: false,
specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}', specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'src/support/e2e.ts', supportFile: 'src/support/e2e.ts',
@ -162,7 +162,7 @@ exports[`convertToCypressTen convertCypressProject should infer targets with --a
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"cypressConfig": "apps/app-e2e/cypress.config.ts", "cypressConfig": "app-e2e/cypress.config.ts",
"devServerTarget": "app:serve", "devServerTarget": "app:serve",
"testingType": "e2e", "testingType": "e2e",
}, },
@ -175,7 +175,7 @@ exports[`convertToCypressTen convertCypressProject should infer targets with --a
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"cypressConfig": "apps/app-e2e/cypress.config.ts", "cypressConfig": "app-e2e/cypress.config.ts",
"devServerTarget": "app:serve", "devServerTarget": "app:serve",
"testingType": "e2e", "testingType": "e2e",
}, },
@ -184,7 +184,7 @@ exports[`convertToCypressTen convertCypressProject should infer targets with --a
"executor": "@nx/linter:eslint", "executor": "@nx/linter:eslint",
"options": { "options": {
"lintFilePatterns": [ "lintFilePatterns": [
"apps/app-e2e/**/*.{js,ts}", "app-e2e/**/*.{js,ts}",
], ],
}, },
"outputs": [ "outputs": [
@ -202,8 +202,8 @@ const cypressJsonConfig = {
fileServerFolder: '.', fileServerFolder: '.',
fixturesFolder: './src/fixtures', fixturesFolder: './src/fixtures',
video: true, video: true,
videosFolder: '../../dist/cypress/apps/app-e2e/videos', videosFolder: '../dist/cypress/app-e2e/videos',
screenshotsFolder: '../../dist/cypress/apps/app-e2e/screenshots', screenshotsFolder: '../dist/cypress/app-e2e/screenshots',
chromeWebSecurity: false, chromeWebSecurity: false,
specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}', specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'src/support/e2e.ts', supportFile: 'src/support/e2e.ts',
@ -227,7 +227,7 @@ exports[`convertToCypressTen convertCypressProject should not break when an inva
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"cypressConfig": "apps/app-e2e/cypress.config.ts", "cypressConfig": "app-e2e/cypress.config.ts",
"devServerTarget": "app:serve", "devServerTarget": "app:serve",
"testingType": "e2e", "testingType": "e2e",
}, },
@ -240,7 +240,7 @@ exports[`convertToCypressTen convertCypressProject should not break when an inva
}, },
"executor": "@nx/cypress:cypress", "executor": "@nx/cypress:cypress",
"options": { "options": {
"cypressConfig": "apps/app-e2e/cypress.config.ts", "cypressConfig": "app-e2e/cypress.config.ts",
"devServerTarget": "app:serve", "devServerTarget": "app:serve",
"testingType": "e2e", "testingType": "e2e",
}, },
@ -249,7 +249,7 @@ exports[`convertToCypressTen convertCypressProject should not break when an inva
"executor": "@nx/linter:eslint", "executor": "@nx/linter:eslint",
"options": { "options": {
"lintFilePatterns": [ "lintFilePatterns": [
"apps/app-e2e/**/*.{js,ts}", "app-e2e/**/*.{js,ts}",
], ],
}, },
"outputs": [ "outputs": [
@ -268,8 +268,8 @@ const cypressJsonConfig = {
fileServerFolder: '.', fileServerFolder: '.',
fixturesFolder: './src/fixtures', fixturesFolder: './src/fixtures',
video: true, video: true,
videosFolder: '../../dist/cypress/apps/app-e2e/videos', videosFolder: '../dist/cypress/app-e2e/videos',
screenshotsFolder: '../../dist/cypress/apps/app-e2e/screenshots', screenshotsFolder: '../dist/cypress/app-e2e/screenshots',
chromeWebSecurity: false, chromeWebSecurity: false,
baseUrl: 'http://localhost:4200', baseUrl: 'http://localhost:4200',
specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}', specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}',
@ -293,8 +293,8 @@ const cypressJsonConfig = {
fileServerFolder: '.', fileServerFolder: '.',
fixturesFolder: './src/fixtures', fixturesFolder: './src/fixtures',
video: true, video: true,
videosFolder: '../../dist/cypress/apps/app-e2e/videos', videosFolder: '../dist/cypress/app-e2e/videos',
screenshotsFolder: '../../dist/cypress/apps/app-e2e/screenshots', screenshotsFolder: '../dist/cypress/app-e2e/screenshots',
chromeWebSecurity: false, chromeWebSecurity: false,
specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}', specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'src/support/e2e.ts', supportFile: 'src/support/e2e.ts',

View File

@ -38,8 +38,8 @@ describe('convertToCypressTen', () => {
describe('convertCypressProject', () => { describe('convertCypressProject', () => {
beforeEach(async () => { beforeEach(async () => {
addProjectConfiguration(tree, 'app', { addProjectConfiguration(tree, 'app', {
root: 'apps/app', root: 'app',
sourceRoot: 'apps/app/src', sourceRoot: 'app/src',
targets: { targets: {
serve: { serve: {
executor: '@nx/web:file-server', executor: '@nx/web:file-server',
@ -53,31 +53,30 @@ describe('convertToCypressTen', () => {
name: 'app-e2e', name: 'app-e2e',
skipFormat: true, skipFormat: true,
project: 'app', project: 'app',
projectNameAndRootFormat: 'as-provided',
}); });
}); });
it('should update project w/defaults', async () => { it('should update project w/defaults', async () => {
expect(tree.exists('apps/app-e2e/cypress.json')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.json')).toBeTruthy();
await migrateCypressProject(tree); await migrateCypressProject(tree);
expect(tree.exists('apps/app-e2e/cypress.config.ts')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.config.ts')).toBeTruthy();
expect( expect(tree.read('app-e2e/cypress.config.ts', 'utf-8')).toMatchSnapshot();
tree.read('apps/app-e2e/cypress.config.ts', 'utf-8') expect(readJson(tree, 'app-e2e/tsconfig.json').include).toEqual([
).toMatchSnapshot();
expect(readJson(tree, 'apps/app-e2e/tsconfig.json').include).toEqual([
'src/**/*.ts', 'src/**/*.ts',
'src/**/*.js', 'src/**/*.js',
'cypress.config.ts', 'cypress.config.ts',
]); ]);
expect(tree.exists('apps/app-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/e2e/app.cy.ts')).toBeTruthy();
expect(tree.exists('apps/app-e2e/src/support/e2e.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/support/e2e.ts')).toBeTruthy();
}); });
it('should update project w/customized config', async () => { it('should update project w/customized config', async () => {
expect(tree.exists('apps/app-e2e/cypress.json')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.json')).toBeTruthy();
updateJson(tree, 'apps/app-e2e/cypress.json', (json) => { updateJson(tree, 'app-e2e/cypress.json', (json) => {
json = { json = {
...json, ...json,
baseUrl: 'http://localhost:4200', baseUrl: 'http://localhost:4200',
@ -90,28 +89,26 @@ describe('convertToCypressTen', () => {
await migrateCypressProject(tree); await migrateCypressProject(tree);
expect(tree.exists('apps/app-e2e/cypress.config.ts')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.config.ts')).toBeTruthy();
expect( expect(tree.read('app-e2e/cypress.config.ts', 'utf-8')).toMatchSnapshot();
tree.read('apps/app-e2e/cypress.config.ts', 'utf-8') expect(readJson(tree, 'app-e2e/tsconfig.json').include).toEqual([
).toMatchSnapshot();
expect(readJson(tree, 'apps/app-e2e/tsconfig.json').include).toEqual([
'src/**/*.ts', 'src/**/*.ts',
'src/**/*.js', 'src/**/*.js',
'cypress.config.ts', 'cypress.config.ts',
]); ]);
expect(tree.exists('apps/app-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/e2e/app.cy.ts')).toBeTruthy();
expect(tree.exists('apps/app-e2e/src/support/e2e.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/support/e2e.ts')).toBeTruthy();
}); });
it('should not update a non e2e project', async () => { it('should not update a non e2e project', async () => {
await migrateCypressProject(tree); await migrateCypressProject(tree);
expect(tree.exists('apps/app/cypress.config.ts')).toBeFalsy(); expect(tree.exists('app/cypress.config.ts')).toBeFalsy();
expect(tree.exists('apps/app/src/e2e/app.cy.ts')).toBeFalsy(); expect(tree.exists('app/src/e2e/app.cy.ts')).toBeFalsy();
expect(tree.exists('apps/app/src/support/e2e.ts')).toBeFalsy(); expect(tree.exists('app/src/support/e2e.ts')).toBeFalsy();
}); });
it('should handle custom target names', async () => { it('should handle custom target names', async () => {
expect(tree.exists('apps/app-e2e/cypress.json')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.json')).toBeTruthy();
const pc = readProjectConfiguration(tree, 'app-e2e'); const pc = readProjectConfiguration(tree, 'app-e2e');
pc.targets = { pc.targets = {
'e2e-custom': { 'e2e-custom': {
@ -123,21 +120,19 @@ describe('convertToCypressTen', () => {
await migrateCypressProject(tree); await migrateCypressProject(tree);
expect(tree.exists('apps/app-e2e/cypress.config.ts')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.config.ts')).toBeTruthy();
expect( expect(tree.read('app-e2e/cypress.config.ts', 'utf-8')).toMatchSnapshot();
tree.read('apps/app-e2e/cypress.config.ts', 'utf-8') expect(readJson(tree, 'app-e2e/tsconfig.json').include).toEqual([
).toMatchSnapshot();
expect(readJson(tree, 'apps/app-e2e/tsconfig.json').include).toEqual([
'src/**/*.ts', 'src/**/*.ts',
'src/**/*.js', 'src/**/*.js',
'cypress.config.ts', 'cypress.config.ts',
]); ]);
expect(tree.exists('apps/app-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/e2e/app.cy.ts')).toBeTruthy();
expect(tree.exists('apps/app-e2e/src/support/e2e.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/support/e2e.ts')).toBeTruthy();
}); });
it('should infer targets with --all flag', async () => { it('should infer targets with --all flag', async () => {
expect(tree.exists('apps/app-e2e/cypress.json')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.json')).toBeTruthy();
const pc = readProjectConfiguration(tree, 'app-e2e'); const pc = readProjectConfiguration(tree, 'app-e2e');
pc.targets = { pc.targets = {
...pc.targets, ...pc.targets,
@ -150,24 +145,22 @@ describe('convertToCypressTen', () => {
await migrateCypressProject(tree); await migrateCypressProject(tree);
expect(tree.exists('apps/app-e2e/cypress.config.ts')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.config.ts')).toBeTruthy();
expect( expect(tree.read('app-e2e/cypress.config.ts', 'utf-8')).toMatchSnapshot();
tree.read('apps/app-e2e/cypress.config.ts', 'utf-8') expect(readJson(tree, 'app-e2e/tsconfig.json').include).toEqual([
).toMatchSnapshot();
expect(readJson(tree, 'apps/app-e2e/tsconfig.json').include).toEqual([
'src/**/*.ts', 'src/**/*.ts',
'src/**/*.js', 'src/**/*.js',
'cypress.config.ts', 'cypress.config.ts',
]); ]);
expect(tree.exists('apps/app-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/e2e/app.cy.ts')).toBeTruthy();
expect(tree.exists('apps/app-e2e/src/support/e2e.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/support/e2e.ts')).toBeTruthy();
expect( expect(
readProjectConfiguration(tree, 'app-e2e').targets readProjectConfiguration(tree, 'app-e2e').targets
).toMatchSnapshot(); ).toMatchSnapshot();
}); });
it('should not break when an invalid target is passed in', async () => { it('should not break when an invalid target is passed in', async () => {
expect(tree.exists('apps/app-e2e/cypress.json')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.json')).toBeTruthy();
const pc = readProjectConfiguration(tree, 'app-e2e'); const pc = readProjectConfiguration(tree, 'app-e2e');
pc.targets = { pc.targets = {
...pc.targets, ...pc.targets,
@ -180,24 +173,22 @@ describe('convertToCypressTen', () => {
await migrateCypressProject(tree); await migrateCypressProject(tree);
expect(tree.exists('apps/app-e2e/cypress.config.ts')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.config.ts')).toBeTruthy();
expect( expect(tree.read('app-e2e/cypress.config.ts', 'utf-8')).toMatchSnapshot();
tree.read('apps/app-e2e/cypress.config.ts', 'utf-8') expect(readJson(tree, 'app-e2e/tsconfig.json').include).toEqual([
).toMatchSnapshot();
expect(readJson(tree, 'apps/app-e2e/tsconfig.json').include).toEqual([
'src/**/*.ts', 'src/**/*.ts',
'src/**/*.js', 'src/**/*.js',
'cypress.config.ts', 'cypress.config.ts',
]); ]);
expect(tree.exists('apps/app-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/e2e/app.cy.ts')).toBeTruthy();
expect(tree.exists('apps/app-e2e/src/support/e2e.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/support/e2e.ts')).toBeTruthy();
expect( expect(
readProjectConfiguration(tree, 'app-e2e').targets readProjectConfiguration(tree, 'app-e2e').targets
).toMatchSnapshot(); ).toMatchSnapshot();
}); });
it('should handle multiple configurations', async () => { it('should handle multiple configurations', async () => {
expect(tree.exists('apps/app-e2e/cypress.json')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.json')).toBeTruthy();
const pc = readProjectConfiguration(tree, 'app-e2e'); const pc = readProjectConfiguration(tree, 'app-e2e');
pc.targets = { pc.targets = {
...pc.targets, ...pc.targets,
@ -218,26 +209,24 @@ describe('convertToCypressTen', () => {
await migrateCypressProject(tree); await migrateCypressProject(tree);
expect(tree.exists('apps/app-e2e/cypress.config.ts')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.config.ts')).toBeTruthy();
expect( expect(tree.read('app-e2e/cypress.config.ts', 'utf-8')).toMatchSnapshot();
tree.read('apps/app-e2e/cypress.config.ts', 'utf-8') expect(readJson(tree, 'app-e2e/tsconfig.json').include).toEqual([
).toMatchSnapshot();
expect(readJson(tree, 'apps/app-e2e/tsconfig.json').include).toEqual([
'src/**/*.ts', 'src/**/*.ts',
'src/**/*.js', 'src/**/*.js',
'cypress.config.ts', 'cypress.config.ts',
]); ]);
expect(tree.exists('apps/app-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/e2e/app.cy.ts')).toBeTruthy();
expect(tree.exists('apps/app-e2e/src/support/e2e.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/support/e2e.ts')).toBeTruthy();
expect( expect(
readProjectConfiguration(tree, 'app-e2e').targets['e2e'] readProjectConfiguration(tree, 'app-e2e').targets['e2e']
).toMatchSnapshot(); ).toMatchSnapshot();
}); });
it('should handle multiple configurations with no default cypressConfig option', async () => { it('should handle multiple configurations with no default cypressConfig option', async () => {
expect(tree.exists('apps/app-e2e/cypress.json')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.json')).toBeTruthy();
tree.write( tree.write(
'apps/app-e2e/cypress.production.json', 'app-e2e/cypress.production.json',
JSON.stringify({ JSON.stringify({
fileServerFolder: '.', fileServerFolder: '.',
fixturesFolder: './src/fixtures', fixturesFolder: './src/fixtures',
@ -246,8 +235,8 @@ describe('convertToCypressTen', () => {
pluginsFile: './src/plugins/index', pluginsFile: './src/plugins/index',
supportFile: './src/support/index.ts', supportFile: './src/support/index.ts',
video: true, video: true,
videosFolder: '../../dist/cypress/apps/client-e2e/videos', videosFolder: '../dist/cypress/client-e2e/videos',
screenshotsFolder: '../../dist/cypress/apps/client-e2e/screenshots', screenshotsFolder: '../dist/cypress/client-e2e/screenshots',
chromeWebSecurity: false, chromeWebSecurity: false,
}) })
); );
@ -261,12 +250,12 @@ describe('convertToCypressTen', () => {
}, },
configurations: { configurations: {
production: { production: {
cypressConfig: 'apps/app-e2e/cypress.production.json', cypressConfig: 'app-e2e/cypress.production.json',
devServerTarget: 'target:serve:production', devServerTarget: 'target:serve:production',
}, },
static: { static: {
baseUrl: 'http://localhost:3000', baseUrl: 'http://localhost:3000',
cypressConfig: 'apps/app-e2e/cypress.json', cypressConfig: 'app-e2e/cypress.json',
}, },
}, },
}, },
@ -276,18 +265,16 @@ describe('convertToCypressTen', () => {
await migrateCypressProject(tree); await migrateCypressProject(tree);
expect(tree.exists('apps/app-e2e/cypress.config.ts')).toBeTruthy(); expect(tree.exists('app-e2e/cypress.config.ts')).toBeTruthy();
expect( expect(tree.read('app-e2e/cypress.config.ts', 'utf-8')).toMatchSnapshot();
tree.read('apps/app-e2e/cypress.config.ts', 'utf-8') expect(readJson(tree, 'app-e2e/tsconfig.json').include).toEqual([
).toMatchSnapshot();
expect(readJson(tree, 'apps/app-e2e/tsconfig.json').include).toEqual([
'src/**/*.ts', 'src/**/*.ts',
'src/**/*.js', 'src/**/*.js',
'cypress.production.config.ts', 'cypress.production.config.ts',
'cypress.config.ts', 'cypress.config.ts',
]); ]);
expect(tree.exists('apps/app-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/e2e/app.cy.ts')).toBeTruthy();
expect(tree.exists('apps/app-e2e/src/support/e2e.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/support/e2e.ts')).toBeTruthy();
expect( expect(
readProjectConfiguration(tree, 'app-e2e').targets['e2e'] readProjectConfiguration(tree, 'app-e2e').targets['e2e']
).toMatchSnapshot(); ).toMatchSnapshot();
@ -296,8 +283,8 @@ describe('convertToCypressTen', () => {
it('should handle sharing the same config across projects', async () => { it('should handle sharing the same config across projects', async () => {
mockedInstalledCypressVersion.mockReturnValue(9); mockedInstalledCypressVersion.mockReturnValue(9);
addProjectConfiguration(tree, 'app-two', { addProjectConfiguration(tree, 'app-two', {
root: 'apps/app-two', root: 'app-two',
sourceRoot: 'apps/app-two/src', sourceRoot: 'app-two/src',
targets: { targets: {
serve: { serve: {
executor: '@nx/web:file-server', executor: '@nx/web:file-server',
@ -310,6 +297,7 @@ describe('convertToCypressTen', () => {
name: 'app-two-e2e', name: 'app-two-e2e',
skipFormat: true, skipFormat: true,
project: 'app-two', project: 'app-two',
projectNameAndRootFormat: 'as-provided',
}); });
const appOneProjectConfig = readProjectConfiguration(tree, 'app-e2e'); const appOneProjectConfig = readProjectConfiguration(tree, 'app-e2e');
appOneProjectConfig.targets['e2e'].options.cypressConfig = 'cypress.json'; appOneProjectConfig.targets['e2e'].options.cypressConfig = 'cypress.json';
@ -333,13 +321,13 @@ describe('convertToCypressTen', () => {
await migrateCypressProject(tree); await migrateCypressProject(tree);
expect(tree.read('cypress.config.ts', 'utf-8')).toMatchSnapshot(); expect(tree.read('cypress.config.ts', 'utf-8')).toMatchSnapshot();
expect(readJson(tree, 'apps/app-e2e/tsconfig.json').include).toEqual([ expect(readJson(tree, 'app-e2e/tsconfig.json').include).toEqual([
'src/**/*.ts', 'src/**/*.ts',
'src/**/*.js', 'src/**/*.js',
'../../cypress.config.ts', '../cypress.config.ts',
]); ]);
expect(tree.exists('apps/app-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/e2e/app.cy.ts')).toBeTruthy();
expect(tree.exists('apps/app-e2e/src/support/e2e.ts')).toBeTruthy(); expect(tree.exists('app-e2e/src/support/e2e.ts')).toBeTruthy();
expect(readProjectConfiguration(tree, 'app-e2e').targets['e2e']).toEqual({ expect(readProjectConfiguration(tree, 'app-e2e').targets['e2e']).toEqual({
executor: '@nx/cypress:cypress', executor: '@nx/cypress:cypress',
options: { options: {
@ -353,13 +341,13 @@ describe('convertToCypressTen', () => {
}, },
}, },
}); });
expect(readJson(tree, 'apps/app-two-e2e/tsconfig.json').include).toEqual([ expect(readJson(tree, 'app-two-e2e/tsconfig.json').include).toEqual([
'src/**/*.ts', 'src/**/*.ts',
'src/**/*.js', 'src/**/*.js',
'../../cypress.config.ts', '../cypress.config.ts',
]); ]);
expect(tree.exists('apps/app-two-e2e/src/e2e/app.cy.ts')).toBeTruthy(); expect(tree.exists('app-two-e2e/src/e2e/app.cy.ts')).toBeTruthy();
expect(tree.exists('apps/app-two-e2e/src/support/e2e.ts')).toBeTruthy(); expect(tree.exists('app-two-e2e/src/support/e2e.ts')).toBeTruthy();
expect( expect(
readProjectConfiguration(tree, 'app-two-e2e').targets['e2e'] readProjectConfiguration(tree, 'app-two-e2e').targets['e2e']
).toEqual({ ).toEqual({
@ -393,8 +381,8 @@ describe('convertToCypressTen', () => {
}; };
const projectConfig = { const projectConfig = {
root: 'apps/app-e2e', root: 'app-e2e',
sourceRoot: 'apps/app-e2e/src', sourceRoot: 'app-e2e/src',
}; };
const filePaths = [ const filePaths = [
'src/integration/nested/something.spec.ts', 'src/integration/nested/something.spec.ts',
@ -486,9 +474,7 @@ const eh = require("../../support")
expect(newIntegrationFolderContents.length).toEqual( expect(newIntegrationFolderContents.length).toEqual(
oldIntegrationFolderContents.length oldIntegrationFolderContents.length
); );
expect(tree.exists('apps/app-e2e/src/fixtures/example.json')).toEqual( expect(tree.exists('app-e2e/src/fixtures/example.json')).toEqual(true);
true
);
}); });
it('should rename files', () => { it('should rename files', () => {
@ -513,7 +499,7 @@ const eh = require("../../support")
}); });
describe('updateImports', () => { describe('updateImports', () => {
const filePath = 'apps/app-e2e/src/e2e/sometest.cy.ts'; const filePath = 'app-e2e/src/e2e/sometest.cy.ts';
const fileContents = String.raw` const fileContents = String.raw`
import { getGreeting } from '../support/app.po'; import { getGreeting } from '../support/app.po';
@ -554,15 +540,15 @@ describe('a', () => {
}); });
describe('Support File Imports', () => { describe('Support File Imports', () => {
const newImport = 'apps/app-e2e/src/support/e2e.ts'; const newImport = 'app-e2e/src/support/e2e.ts';
it('should update imports w/defaults', () => { it('should update imports w/defaults', () => {
const oldImport = 'apps/app-e2e/src/support/index.ts'; const oldImport = 'app-e2e/src/support/index.ts';
const actual = createSupportFileImport( const actual = createSupportFileImport(
oldImport, oldImport,
newImport, newImport,
'apps/app-e2e/src' 'app-e2e/src'
); );
expect(actual).toEqual({ expect(actual).toEqual({
oldImportPathLeaf: 'support', oldImportPathLeaf: 'support',
@ -571,12 +557,12 @@ describe('a', () => {
}); });
it('should handle custom support file location', () => { it('should handle custom support file location', () => {
const oldImport = 'apps/app-e2e/src/support/blah.ts'; const oldImport = 'app-e2e/src/support/blah.ts';
const actual = createSupportFileImport( const actual = createSupportFileImport(
oldImport, oldImport,
newImport, newImport,
'apps/app-e2e/src' 'app-e2e/src'
); );
expect(actual).toEqual({ expect(actual).toEqual({
oldImportPathLeaf: 'support/blah', oldImportPathLeaf: 'support/blah',
@ -585,12 +571,12 @@ describe('a', () => {
}); });
it('should handle nested custom support location', () => { it('should handle nested custom support location', () => {
const oldImport = 'apps/app-e2e/src/support/blah/abc.ts'; const oldImport = 'app-e2e/src/support/blah/abc.ts';
const actual = createSupportFileImport( const actual = createSupportFileImport(
oldImport, oldImport,
newImport, newImport,
'apps/app-e2e/src' 'app-e2e/src'
); );
expect(actual).toEqual({ expect(actual).toEqual({
oldImportPathLeaf: 'support/blah/abc', oldImportPathLeaf: 'support/blah/abc',
@ -599,12 +585,12 @@ describe('a', () => {
}); });
it('should handle nested custom support location w/index.ts', () => { it('should handle nested custom support location w/index.ts', () => {
const oldImport = 'apps/app-e2e/src/support/something/neat/index.ts'; const oldImport = 'app-e2e/src/support/something/neat/index.ts';
const actual = createSupportFileImport( const actual = createSupportFileImport(
oldImport, oldImport,
newImport, newImport,
'apps/app-e2e/src' 'app-e2e/src'
); );
expect(actual).toEqual({ expect(actual).toEqual({
oldImportPathLeaf: 'support/something/neat', oldImportPathLeaf: 'support/something/neat',
@ -616,7 +602,7 @@ describe('a', () => {
describe(updatePluginFile.name, () => { describe(updatePluginFile.name, () => {
it('should update module.exports for ts files', () => { it('should update module.exports for ts files', () => {
tree.write( tree.write(
'apps/app-e2e/src/plugins/index.ts', 'app-e2e/src/plugins/index.ts',
` `
function myCoolFunction() { function myCoolFunction() {
console.log('cool') console.log('cool')
@ -631,7 +617,7 @@ module.exports.blah = myCoolFunction;
); );
const actual = updatePluginFile( const actual = updatePluginFile(
tree, tree,
{ root: 'apps/app-e2e' }, { root: 'app-e2e' },
{ {
cypressConfigJson: {}, cypressConfigJson: {},
cypressConfigTs: { e2e: { pluginsFile: './src/plugins/index.ts' } }, cypressConfigTs: { e2e: { pluginsFile: './src/plugins/index.ts' } },
@ -641,7 +627,7 @@ module.exports.blah = myCoolFunction;
expect(actual.cypressConfigTs.e2e.pluginsFile).toEqual( expect(actual.cypressConfigTs.e2e.pluginsFile).toEqual(
'./src/plugins/index' './src/plugins/index'
); );
expect(tree.read('apps/app-e2e/src/plugins/index.ts', 'utf-8')).toEqual(` expect(tree.read('app-e2e/src/plugins/index.ts', 'utf-8')).toEqual(`
function myCoolFunction() { function myCoolFunction() {
console.log('cool') console.log('cool')
} }
@ -665,10 +651,10 @@ module.exports = function(on, config) {
module.exports.blah = myCoolFunction; module.exports.blah = myCoolFunction;
`; `;
tree.write('apps/app-e2e/src/plugins/index.js', pluginFileContent); tree.write('app-e2e/src/plugins/index.js', pluginFileContent);
const actual = updatePluginFile( const actual = updatePluginFile(
tree, tree,
{ root: 'apps/app-e2e' }, { root: 'app-e2e' },
{ {
cypressConfigJson: {}, cypressConfigJson: {},
cypressConfigTs: { e2e: { pluginsFile: './src/plugins/index.js' } }, cypressConfigTs: { e2e: { pluginsFile: './src/plugins/index.js' } },
@ -678,7 +664,7 @@ module.exports.blah = myCoolFunction;
expect(actual.cypressConfigTs.e2e.pluginsFile).toEqual( expect(actual.cypressConfigTs.e2e.pluginsFile).toEqual(
'./src/plugins/index' './src/plugins/index'
); );
expect(tree.read('apps/app-e2e/src/plugins/index.js', 'utf-8')).toEqual( expect(tree.read('app-e2e/src/plugins/index.js', 'utf-8')).toEqual(
pluginFileContent pluginFileContent
); );
}); });
@ -686,7 +672,7 @@ module.exports.blah = myCoolFunction;
it('should not update if no file is preset', () => { it('should not update if no file is preset', () => {
const actual = updatePluginFile( const actual = updatePluginFile(
tree, tree,
{ root: 'apps/app-e2e' }, { root: 'app-e2e' },
{ {
cypressConfigJson: {}, cypressConfigJson: {},
cypressConfigTs: { e2e: { pluginsFile: false } }, cypressConfigTs: { e2e: { pluginsFile: false } },
@ -694,7 +680,7 @@ module.exports.blah = myCoolFunction;
); );
expect(actual.cypressConfigTs.e2e.pluginsFile).toBeFalsy(); expect(actual.cypressConfigTs.e2e.pluginsFile).toBeFalsy();
expect(tree.exists('apps/app-e2e/src/plugins/index.ts')).toBeFalsy(); expect(tree.exists('app-e2e/src/plugins/index.ts')).toBeFalsy();
}); });
}); });
}); });