fix(storybook): install cypress packages if not installed for e2e apps
ISSUES CLOSED: #7158
This commit is contained in:
parent
e960285769
commit
c68b37e29f
@ -58,4 +58,23 @@ describe('@nrwl/storybook:cypress-project', () => {
|
|||||||
tree.exists('apps/one/two/test-ui-lib-e2e/cypress.json')
|
tree.exists('apps/one/two/test-ui-lib-e2e/cypress.json')
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should make sure the cypress packages are installed', async () => {
|
||||||
|
expect(
|
||||||
|
readJson(tree, 'package.json').devDependencies['cypress']
|
||||||
|
).toBeFalsy();
|
||||||
|
await cypressProjectGenerator(tree, {
|
||||||
|
name: 'test-ui-lib',
|
||||||
|
directory: 'one/two',
|
||||||
|
linter: Linter.EsLint,
|
||||||
|
standaloneConfig: false,
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
readJson(tree, 'package.json').devDependencies['cypress']
|
||||||
|
).toBeTruthy();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
readJson(tree, 'package.json').devDependencies['@nrwl/cypress']
|
||||||
|
).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,19 +1,25 @@
|
|||||||
import {
|
import {
|
||||||
convertNxGenerator,
|
convertNxGenerator,
|
||||||
formatFiles,
|
formatFiles,
|
||||||
|
GeneratorCallback,
|
||||||
|
readJson,
|
||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
Tree,
|
Tree,
|
||||||
updateJson,
|
updateJson,
|
||||||
updateProjectConfiguration,
|
updateProjectConfiguration,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
|
|
||||||
import { Linter } from '@nrwl/linter';
|
import { Linter } from '@nrwl/linter';
|
||||||
import { cypressProjectGenerator as _cypressProjectGenerator } from '@nrwl/cypress';
|
import {
|
||||||
|
cypressProjectGenerator as _cypressProjectGenerator,
|
||||||
|
cypressInitGenerator as _cypressInitGenerator,
|
||||||
|
} from '@nrwl/cypress';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getE2eProjectName,
|
getE2eProjectName,
|
||||||
getUnscopedLibName,
|
getUnscopedLibName,
|
||||||
} from '@nrwl/cypress/src/utils/project-name';
|
} from '@nrwl/cypress/src/utils/project-name';
|
||||||
import { safeFileDelete } from '../../utils/utilities';
|
import { safeFileDelete } from '../../utils/utilities';
|
||||||
|
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
|
||||||
|
|
||||||
export interface CypressConfigureSchema {
|
export interface CypressConfigureSchema {
|
||||||
name: string;
|
name: string;
|
||||||
@ -32,6 +38,13 @@ export async function cypressProjectGenerator(
|
|||||||
const cypressProjectName = `${
|
const cypressProjectName = `${
|
||||||
schema.directory ? getUnscopedLibName(libRoot) : schema.name
|
schema.directory ? getUnscopedLibName(libRoot) : schema.name
|
||||||
}-e2e`;
|
}-e2e`;
|
||||||
|
|
||||||
|
const tasks: GeneratorCallback[] = [];
|
||||||
|
|
||||||
|
if (!projectAlreadyHasCypress(tree)) {
|
||||||
|
tasks.push(_cypressInitGenerator(tree));
|
||||||
|
}
|
||||||
|
|
||||||
const installTask = await _cypressProjectGenerator(tree, {
|
const installTask = await _cypressProjectGenerator(tree, {
|
||||||
name: cypressProjectName,
|
name: cypressProjectName,
|
||||||
project: schema.name,
|
project: schema.name,
|
||||||
@ -40,6 +53,8 @@ export async function cypressProjectGenerator(
|
|||||||
directory: schema.directory,
|
directory: schema.directory,
|
||||||
standaloneConfig: schema.standaloneConfig,
|
standaloneConfig: schema.standaloneConfig,
|
||||||
});
|
});
|
||||||
|
tasks.push(installTask);
|
||||||
|
|
||||||
const generatedCypressProjectName = getE2eProjectName(
|
const generatedCypressProjectName = getE2eProjectName(
|
||||||
schema.name,
|
schema.name,
|
||||||
libRoot,
|
libRoot,
|
||||||
@ -51,7 +66,7 @@ export async function cypressProjectGenerator(
|
|||||||
|
|
||||||
await formatFiles(tree);
|
await formatFiles(tree);
|
||||||
|
|
||||||
return installTask;
|
return runTasksInSerial(...tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeUnneededFiles(tree: Tree, projectName: string, js: boolean) {
|
function removeUnneededFiles(tree: Tree, projectName: string, js: boolean) {
|
||||||
@ -93,6 +108,16 @@ function updateAngularJsonBuilder(
|
|||||||
updateProjectConfiguration(tree, e2eProjectName, project);
|
updateProjectConfiguration(tree, e2eProjectName, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function projectAlreadyHasCypress(tree: Tree): boolean {
|
||||||
|
const packageJsonContents = readJson(tree, 'package.json');
|
||||||
|
return (
|
||||||
|
(packageJsonContents?.['devDependencies']?.['@nrwl/cypress'] ||
|
||||||
|
packageJsonContents?.['dependencies']?.['@nrwl/cypress']) &&
|
||||||
|
(packageJsonContents?.['devDependencies']?.['cypress'] ||
|
||||||
|
packageJsonContents?.['dependencies']?.['cypress'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default cypressProjectGenerator;
|
export default cypressProjectGenerator;
|
||||||
export const cypressProjectSchematic = convertNxGenerator(
|
export const cypressProjectSchematic = convertNxGenerator(
|
||||||
cypressProjectGenerator
|
cypressProjectGenerator
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user