chore(linter): optimize e2e tests (#20718)

This commit is contained in:
Miroslav Jonaš 2023-12-13 16:44:30 +01:00 committed by GitHub
parent 43141334a8
commit 5d9f78a848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -26,7 +26,9 @@ describe('Linter', () => {
let projScope; let projScope;
beforeAll(() => { beforeAll(() => {
projScope = newProject(); projScope = newProject({
packages: ['@nx/react', '@nx/js', '@nx/eslint'],
});
runCLI(`generate @nx/react:app ${myapp} --tags=validtag`); runCLI(`generate @nx/react:app ${myapp} --tags=validtag`);
runCLI(`generate @nx/js:lib ${mylib}`); runCLI(`generate @nx/js:lib ${mylib}`);
}); });
@ -619,7 +621,11 @@ describe('Linter', () => {
}); });
describe('Root projects migration', () => { describe('Root projects migration', () => {
beforeEach(() => newProject()); beforeEach(() =>
newProject({
packages: ['@nx/react', '@nx/js', '@nx/angular', '@nx/node'],
})
);
afterEach(() => cleanupProject()); afterEach(() => cleanupProject());
function verifySuccessfulStandaloneSetup(myapp: string) { function verifySuccessfulStandaloneSetup(myapp: string) {
@ -773,6 +779,7 @@ describe('Linter', () => {
newProject({ newProject({
name: uniq('eslint'), name: uniq('eslint'),
unsetProjectNameAndRootFormat: false, unsetProjectNameAndRootFormat: false,
packages: ['@nx/react'],
}); });
}); });

View File

@ -29,7 +29,7 @@ import {
RunCmdOpts, RunCmdOpts,
runCommand, runCommand,
} from './command-utils'; } from './command-utils';
import { output } from '@nx/devkit'; import { output, readJsonFile } from '@nx/devkit';
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { resetWorkspaceContext } from 'nx/src/utils/workspace-context'; import { resetWorkspaceContext } from 'nx/src/utils/workspace-context';
@ -143,8 +143,16 @@ export function newProject({
const projectDirectory = tmpProjPath(); const projectDirectory = tmpProjPath();
copySync(`${tmpBackupProjPath()}`, `${projectDirectory}`); copySync(`${tmpBackupProjPath()}`, `${projectDirectory}`);
// TODO: What is this for? const dependencies = readJsonFile(
if (packageManager === 'pnpm') { `${projectDirectory}/package.json`
).devDependencies;
const missingPackages = (packages || []).filter((p) => !dependencies[p]);
if (missingPackages.length > 0) {
packageInstall(missingPackages.join(` `), projName);
} else if (packageManager === 'pnpm') {
// pnpm creates sym links to the pnpm store,
// we need to run the install again after copying the temp folder
execSync(getPackageManagerCommand().install, { execSync(getPackageManagerCommand().install, {
cwd: projectDirectory, cwd: projectDirectory,
stdio: 'pipe', stdio: 'pipe',