fix(testing): run init generator in cypress-project when cypress is n… (#12552)
This commit is contained in:
parent
1f1559378f
commit
ed05ca3d6e
@ -11,9 +11,10 @@ import { cypressProjectGenerator } from './cypress-project';
|
|||||||
import { Schema } from './schema';
|
import { Schema } from './schema';
|
||||||
import { Linter } from '@nrwl/linter';
|
import { Linter } from '@nrwl/linter';
|
||||||
import { installedCypressVersion } from '../../utils/cypress-version';
|
import { installedCypressVersion } from '../../utils/cypress-version';
|
||||||
|
import { cypressInitGenerator } from '../init/init';
|
||||||
|
|
||||||
jest.mock('../../utils/cypress-version');
|
jest.mock('../../utils/cypress-version');
|
||||||
|
jest.mock('../init/init');
|
||||||
describe('Cypress Project', () => {
|
describe('Cypress Project', () => {
|
||||||
let tree: Tree;
|
let tree: Tree;
|
||||||
const defaultOptions: Omit<Schema, 'name' | 'project'> = {
|
const defaultOptions: Omit<Schema, 'name' | 'project'> = {
|
||||||
@ -23,6 +24,8 @@ describe('Cypress Project', () => {
|
|||||||
let mockedInstalledCypressVersion: jest.Mock<
|
let mockedInstalledCypressVersion: jest.Mock<
|
||||||
ReturnType<typeof installedCypressVersion>
|
ReturnType<typeof installedCypressVersion>
|
||||||
> = installedCypressVersion as never;
|
> = installedCypressVersion as never;
|
||||||
|
let mockInitCypress: jest.Mock<ReturnType<typeof cypressInitGenerator>> =
|
||||||
|
cypressInitGenerator as never;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
tree = createTreeWithEmptyV1Workspace();
|
tree = createTreeWithEmptyV1Workspace();
|
||||||
@ -55,6 +58,26 @@ describe('Cypress Project', () => {
|
|||||||
});
|
});
|
||||||
afterEach(() => jest.clearAllMocks());
|
afterEach(() => jest.clearAllMocks());
|
||||||
|
|
||||||
|
it('should call init if cypress is not installed', async () => {
|
||||||
|
mockedInstalledCypressVersion.mockReturnValue(null);
|
||||||
|
await cypressProjectGenerator(tree, {
|
||||||
|
...defaultOptions,
|
||||||
|
name: 'my-app-e2e',
|
||||||
|
project: 'my-app',
|
||||||
|
});
|
||||||
|
expect(mockInitCypress).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call not init if cypress is installed', async () => {
|
||||||
|
mockedInstalledCypressVersion.mockReturnValue(10);
|
||||||
|
await cypressProjectGenerator(tree, {
|
||||||
|
...defaultOptions,
|
||||||
|
name: 'my-app-e2e',
|
||||||
|
project: 'my-app',
|
||||||
|
});
|
||||||
|
expect(mockInitCypress).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
describe('> v10', () => {
|
describe('> v10', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockedInstalledCypressVersion.mockReturnValue(10);
|
mockedInstalledCypressVersion.mockReturnValue(10);
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import {
|
|||||||
cypressVersion,
|
cypressVersion,
|
||||||
eslintPluginCypressVersion,
|
eslintPluginCypressVersion,
|
||||||
} from '../../utils/versions';
|
} from '../../utils/versions';
|
||||||
|
import { cypressInitGenerator } from '../init/init';
|
||||||
// app
|
// app
|
||||||
import { Schema } from './schema';
|
import { Schema } from './schema';
|
||||||
|
|
||||||
@ -248,13 +249,21 @@ export async function addLinter(host: Tree, options: CypressProjectSchema) {
|
|||||||
|
|
||||||
export async function cypressProjectGenerator(host: Tree, schema: Schema) {
|
export async function cypressProjectGenerator(host: Tree, schema: Schema) {
|
||||||
const options = normalizeOptions(host, schema);
|
const options = normalizeOptions(host, schema);
|
||||||
|
const tasks = [];
|
||||||
|
const cypressVersion = installedCypressVersion();
|
||||||
|
// if there is an installed cypress version, then we don't call
|
||||||
|
// init since we want to keep the existing version that is installed
|
||||||
|
if (!cypressVersion) {
|
||||||
|
tasks.push(cypressInitGenerator(host, options));
|
||||||
|
}
|
||||||
createFiles(host, options);
|
createFiles(host, options);
|
||||||
addProject(host, options);
|
addProject(host, options);
|
||||||
const installTask = await addLinter(host, options);
|
const installTask = await addLinter(host, options);
|
||||||
|
tasks.push(installTask);
|
||||||
if (!options.skipFormat) {
|
if (!options.skipFormat) {
|
||||||
await formatFiles(host);
|
await formatFiles(host);
|
||||||
}
|
}
|
||||||
return installTask;
|
return runTasksInSerial(...tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeOptions(host: Tree, options: Schema): CypressProjectSchema {
|
function normalizeOptions(host: Tree, options: Schema): CypressProjectSchema {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user