chore(testing): reduce create-workspace --preset=npm e2e time (#15239)

This commit is contained in:
Emily Xiong 2023-03-02 10:38:18 -05:00 committed by GitHub
parent aaed63ba18
commit 3ef5406fb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 207 additions and 25 deletions

View File

@ -12,6 +12,12 @@
"type": "boolean",
"default": false,
"x-priority": "internal"
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
}
},
"required": [],

View File

@ -19,6 +19,12 @@
"description": "Skip formatting files.",
"type": "boolean",
"default": false
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"additionalProperties": false,

View File

@ -122,6 +122,12 @@
"type": "boolean",
"description": "Whether or not to configure the ESLint \"parserOptions.project\" option. We do not do this by default for lint performance reasons.",
"default": false
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"additionalProperties": false,

View File

@ -118,6 +118,12 @@
"description": "Use a custom Express server for the Next.js application.",
"type": "boolean",
"default": false
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
}
},
"required": [],

View File

@ -30,6 +30,12 @@
"type": "boolean",
"default": false,
"description": "Use JavaScript instead of TypeScript"
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
}
},
"required": [],

View File

@ -146,6 +146,12 @@
"type": "boolean",
"default": true,
"x-deprecated": "Nx only supports standaloneConfig"
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
}
},
"required": ["name"],

View File

@ -2,13 +2,11 @@ import {
createNonNxProjectDirectory,
runCLI,
runCommand,
tmpProjPath,
updateFile,
getPackageManagerCommand,
getSelectedPackageManager,
getPublishedVersion,
} from '@nrwl/e2e/utils';
import { Workspaces } from 'nx/src/config/workspaces';
describe('add-nx-to-monorepo', () => {
const pmc = getPackageManagerCommand({

View File

@ -0,0 +1,11 @@
/* eslint-disable */
export default {
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
maxWorkers: 1,
globals: { 'ts-jest': { tsconfig: '<rootDir>/tsconfig.spec.json' } },
displayName: 'e2e-workspace-create-npm',
preset: '../../jest.preset.js',
};

View File

@ -0,0 +1,11 @@
{
"name": "e2e-workspace-create-npm",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/workspace-create-npm",
"projectType": "application",
"targets": {
"e2e": {},
"run-e2e-tests": {}
},
"implicitDependencies": ["create-nx-workspace"]
}

View File

@ -1,11 +1,14 @@
import { forEach } from '@angular-devkit/schematics';
import {
checkFilesExist,
cleanupProject,
packageInstall,
readJson,
removeFile,
runCLI,
runCreateWorkspace,
uniq,
updateJson,
} from '@nrwl/e2e/utils';
describe('create-nx-workspace --preset=npm', () => {
@ -25,7 +28,9 @@ describe('create-nx-workspace --preset=npm', () => {
const appName = uniq('my-app');
expect(() => {
runCLI(`generate @nrwl/angular:app ${appName} --no-interactive`);
runCLI(
`generate @nrwl/angular:app ${appName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
}, 1_000_000);
@ -35,7 +40,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');
expect(() => {
runCLI(`generate @nrwl/angular:lib ${libName} --no-interactive`);
runCLI(
`generate @nrwl/angular:lib ${libName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
@ -50,7 +57,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');
expect(() =>
runCLI(`generate @nrwl/workspace:library ${libName} --no-interactive`)
runCLI(
`generate @nrwl/workspace:library ${libName} --skipPackageJson --no-interactive`
)
).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
@ -65,7 +74,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');
expect(() =>
runCLI(`generate @nrwl/js:library ${libName} --no-interactive`)
runCLI(
`generate @nrwl/js:library ${libName} --skipPackageJson --no-interactive`
)
).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
@ -80,7 +91,9 @@ describe('create-nx-workspace --preset=npm', () => {
const appName = uniq('my-app');
expect(() =>
runCLI(`generate @nrwl/web:app ${appName} --no-interactive`)
runCLI(
`generate @nrwl/web:app ${appName} --skipPackageJson --no-interactive`
)
).not.toThrowError();
checkFilesExist('tsconfig.base.json');
});
@ -91,7 +104,9 @@ describe('create-nx-workspace --preset=npm', () => {
const appName = uniq('my-app');
expect(() => {
runCLI(`generate @nrwl/react:app ${appName} --no-interactive`);
runCLI(
`generate @nrwl/react:app ${appName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
});
@ -102,7 +117,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');
expect(() => {
runCLI(`generate @nrwl/react:lib ${libName} --no-interactive`);
runCLI(
`generate @nrwl/react:lib ${libName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
@ -117,7 +134,9 @@ describe('create-nx-workspace --preset=npm', () => {
const appName = uniq('my-app');
expect(() => {
runCLI(`generate @nrwl/next:app ${appName} --no-interactive`);
runCLI(
`generate @nrwl/next:app ${appName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
});
@ -128,7 +147,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');
expect(() => {
runCLI(`generate @nrwl/next:lib ${libName} --no-interactive`);
runCLI(
`generate @nrwl/next:lib ${libName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
@ -143,7 +164,9 @@ describe('create-nx-workspace --preset=npm', () => {
const appName = uniq('my-app');
expect(() => {
runCLI(`generate @nrwl/react-native:app ${appName} --no-interactive`);
runCLI(
`generate @nrwl/react-native:app ${appName} --install=false --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
});
@ -154,7 +177,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');
expect(() => {
runCLI(`generate @nrwl/react-native:lib ${libName} --no-interactive`);
runCLI(
`generate @nrwl/react-native:lib ${libName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
@ -169,7 +194,9 @@ describe('create-nx-workspace --preset=npm', () => {
const appName = uniq('my-app');
expect(() => {
runCLI(`generate @nrwl/node:app ${appName} --no-interactive`);
runCLI(
`generate @nrwl/node:app ${appName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
});
@ -180,7 +207,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');
expect(() => {
runCLI(`generate @nrwl/node:lib ${libName} --no-interactive`);
runCLI(
`generate @nrwl/node:lib ${libName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
@ -195,7 +224,9 @@ describe('create-nx-workspace --preset=npm', () => {
const appName = uniq('my-app');
expect(() => {
runCLI(`generate @nrwl/nest:app ${appName} --no-interactive`);
runCLI(
`generate @nrwl/nest:app ${appName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
});
@ -206,7 +237,9 @@ describe('create-nx-workspace --preset=npm', () => {
const libName = uniq('lib');
expect(() => {
runCLI(`generate @nrwl/nest:lib ${libName} --no-interactive`);
runCLI(
`generate @nrwl/nest:lib ${libName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
const tsconfig = readJson(`tsconfig.base.json`);
@ -221,7 +254,9 @@ describe('create-nx-workspace --preset=npm', () => {
const appName = uniq('my-app');
expect(() => {
runCLI(`generate @nrwl/express:app ${appName} --no-interactive`);
runCLI(
`generate @nrwl/express:app ${appName} --skipPackageJson --no-interactive`
);
}).not.toThrowError();
checkFilesExist('tsconfig.base.json');
});

View File

@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}

View File

@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx",
"**/*.d.ts",
"jest.config.ts"
]
}

View File

@ -13,6 +13,7 @@ export async function detoxApplicationGenerator(host: Tree, schema: Schema) {
const options = normalizeOptions(host, schema);
const initTask = await detoxInitGenerator(host, {
...options,
skipFormat: true,
});
createFiles(host, options);

View File

@ -9,6 +9,12 @@
"type": "boolean",
"default": false,
"x-priority": "internal"
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
}
},
"required": []

View File

@ -59,12 +59,15 @@ export async function expoInitGenerator(host: Tree, schema: Schema) {
}
if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
const jestTask = await jestInitGenerator(host, {});
const jestTask = await jestInitGenerator(host, schema);
tasks.push(jestTask);
}
if (!schema.e2eTestRunner || schema.e2eTestRunner === 'detox') {
const detoxTask = await detoxInitGenerator(host, { skipFormat: true });
const detoxTask = await detoxInitGenerator(host, {
...schema,
skipFormat: true,
});
tasks.push(detoxTask);
}

View File

@ -17,6 +17,7 @@ export async function applicationGenerator(
): Promise<GeneratorCallback> {
const options = normalizeOptions(tree, rawOptions);
const initTask = await initGenerator(tree, {
skipPackageJson: options.skipPackageJson,
unitTestRunner: options.unitTestRunner,
skipFormat: true,
});

View File

@ -10,14 +10,21 @@ export async function initGenerator(
rawOptions: InitGeneratorOptions
): Promise<GeneratorCallback> {
const options = normalizeOptions(rawOptions);
const tasks: GeneratorCallback[] = [];
const nodeInitTask = await nodeInitGenerator(tree, options);
const installPackagesTask = addDependencies(tree);
tasks.push(nodeInitTask);
if (!options.skipPackageJson) {
const installPackagesTask = addDependencies(tree);
tasks.push(installPackagesTask);
}
if (!options.skipFormat) {
await formatFiles(tree);
}
return runTasksInSerial(nodeInitTask, installPackagesTask);
return runTasksInSerial(...tasks);
}
export default initGenerator;

View File

@ -3,4 +3,5 @@ import { UnitTestRunner } from '../utils';
export interface InitGeneratorOptions {
skipFormat?: boolean;
unitTestRunner?: UnitTestRunner;
skipPackageJson?: boolean;
}

View File

@ -16,6 +16,12 @@
"description": "Skip formatting files.",
"type": "boolean",
"default": false
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"additionalProperties": false,

View File

@ -29,6 +29,7 @@ export interface LibraryGeneratorOptions {
unitTestRunner?: UnitTestRunner;
standaloneConfig?: boolean;
setParserOptionsProject?: boolean;
skipPackageJson?: boolean;
}
export interface NormalizedOptions extends LibraryGeneratorOptions {

View File

@ -122,6 +122,12 @@
"type": "boolean",
"description": "Whether or not to configure the ESLint \"parserOptions.project\" option. We do not do this by default for lint performance reasons.",
"default": false
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false,
"x-priority": "internal"
}
},
"additionalProperties": false,

View File

@ -16,4 +16,5 @@ export interface Schema {
standaloneConfig?: boolean;
swc?: boolean;
customServer?: boolean;
skipPackageJson?: boolean;
}

View File

@ -118,6 +118,12 @@
"description": "Use a custom Express server for the Next.js application.",
"type": "boolean",
"default": false
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
}
},
"required": [],

View File

@ -58,8 +58,10 @@ export async function nextInitGenerator(host: Tree, schema: InitSchema) {
const reactTask = await reactInitGenerator(host, schema);
tasks.push(reactTask);
const installTask = updateDependencies(host);
tasks.push(installTask);
if (!schema.skipPackageJson) {
const installTask = updateDependencies(host);
tasks.push(installTask);
}
addGitIgnoreEntry(host);

View File

@ -3,4 +3,5 @@ export interface InitSchema {
e2eTestRunner?: 'cypress' | 'none';
skipFormat?: boolean;
js?: boolean;
skipPackageJson?: boolean;
}

View File

@ -27,6 +27,12 @@
"type": "boolean",
"default": false,
"description": "Use JavaScript instead of TypeScript"
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
}
},
"required": []

View File

@ -22,4 +22,5 @@ export interface Schema {
strict?: boolean;
setParserOptionsProject?: boolean;
standaloneConfig?: boolean;
skipPackageJson?: boolean;
}

View File

@ -149,6 +149,12 @@
"type": "boolean",
"default": true,
"x-deprecated": "Nx only supports standaloneConfig"
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
}
},
"required": ["name"],

View File

@ -65,7 +65,10 @@ export async function reactNativeInitGenerator(host: Tree, schema: Schema) {
}
if (!schema.e2eTestRunner || schema.e2eTestRunner === 'detox') {
const detoxTask = await detoxInitGenerator(host, {});
const detoxTask = await detoxInitGenerator(host, {
...schema,
skipFormat: true,
});
tasks.push(detoxTask);
}