chore(repo): fix e2e setup

This commit is contained in:
Colum Ferry 2024-09-10 17:29:49 +01:00
parent 23c365f426
commit 099608f896
5 changed files with 41 additions and 46 deletions

View File

@ -1,8 +1,11 @@
/* eslint-disable */ /* eslint-disable */
export default { export default {
displayName: 'rspack-e2e', displayName: 'e2e-rspack',
preset: '../../jest.preset.js', preset: '../jest.preset.e2e.js',
maxWorkers: 1,
globals: {}, globals: {},
globalSetup: '../utils/global-setup.ts',
globalTeardown: '../utils/global-teardown.ts',
transform: { transform: {
'^.+\\.[tj]s$': [ '^.+\\.[tj]s$': [
'ts-jest', 'ts-jest',
@ -12,5 +15,5 @@ export default {
], ],
}, },
moduleFileExtensions: ['ts', 'js', 'html'], moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/e2e/rspack-e2e', coverageDirectory: '../../coverage/e2e/e2e-rspack',
}; };

View File

@ -1,19 +1,10 @@
{ {
"name": "rspack-e2e", "name": "e2e-rspack",
"$schema": "../../node_modules/nx/schemas/project-schema.json", "$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application", "projectType": "application",
"sourceRoot": "e2e/rspack-e2e/src", "sourceRoot": "e2e/rspack",
"targets": { "// targets": "to see all targets run: nx show project e2e-rspack --web",
"e2e": { "targets": {},
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "e2e/rspack-e2e/jest.config.ts",
"runInBand": true,
"passWithNoTests": false
},
"dependsOn": ["rspack:build"]
}
},
"tags": [], "tags": [],
"implicitDependencies": ["rspack"] "implicitDependencies": ["rspack"]
} }

View File

@ -1,18 +1,21 @@
import { getPackageManagerCommand } from '@nx/devkit'; import { getPackageManagerCommand } from '@nx/devkit';
import { import {
checkFilesExist, checkFilesExist,
ensureNxProject, cleanupProject,
listFiles, listFiles,
runNxCommandAsync, newProject,
tmpProjPath, tmpProjPath,
uniq, uniq,
updateFile, updateFile,
} from '@nx/plugin/testing'; runCLI,
} from '@nx/e2e/utils';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { writeFileSync } from 'fs'; import { writeFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
describe('rspack e2e', () => { describe('rspack e2e', () => {
let proj: string;
// Setting up individual workspaces per // Setting up individual workspaces per
// test can cause e2e runs to take a long time. // test can cause e2e runs to take a long time.
// For this reason, we recommend each suite only // For this reason, we recommend each suite only
@ -20,18 +23,14 @@ describe('rspack e2e', () => {
// on a unique project in the workspace, such that they // on a unique project in the workspace, such that they
// are not dependant on one another. // are not dependant on one another.
beforeAll(() => { beforeAll(() => {
ensureNxProject('@nx/rspack', 'dist/packages/rspack'); proj = newProject({ packages: ['@nx/rspack'] });
}); });
afterAll(() => { afterAll(() => cleanupProject());
// `nx reset` kills the daemon, and performs
// some work which can help clean up e2e leftovers
runNxCommandAsync('reset');
});
it('should create rspack root project and additional apps', async () => { it('should create rspack root project and additional apps', async () => {
const project = uniq('myapp'); const project = uniq('myapp');
await runNxCommandAsync( runCLI(
`generate @nx/rspack:preset ${project} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress` `generate @nx/rspack:preset ${project} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress`
); );
@ -61,18 +60,18 @@ describe('rspack e2e', () => {
{ cwd: tmpProjPath() } { cwd: tmpProjPath() }
); );
let result = await runNxCommandAsync(`build ${project}`, { let result = runCLI(`build ${project}`, {
env: { NODE_ENV: 'production' }, env: { NODE_ENV: 'production' },
}); });
expect(result.stdout).toContain('Successfully ran target build'); expect(result).toContain('Successfully ran target build');
// Make sure expected files are present. // Make sure expected files are present.
expect(listFiles(`dist/${project}`)).toHaveLength(5); expect(listFiles(`dist/${project}`)).toHaveLength(5);
result = await runNxCommandAsync(`test ${project}`); result = runCLI(`test ${project}`);
expect(result.stdout).toContain('Successfully ran target test'); expect(result).toContain('Successfully ran target test');
// TODO(Colum): re-enable when cypress issue is resolved // TODO(Colum): re-enable when cypress issue is resolved
// result = await runNxCommandAsync(`e2e e2e`); // result = runCLI(`e2e e2e`);
// expect(result.stdout).toContain('Successfully ran target e2e'); // expect(result.stdout).toContain('Successfully ran target e2e');
// Update app and make sure previous dist files are not present. // Update app and make sure previous dist files are not present.
@ -80,15 +79,15 @@ describe('rspack e2e', () => {
return `${content}\nconsole.log('hello'); return `${content}\nconsole.log('hello');
`; `;
}); });
result = await runNxCommandAsync(`build ${project}`, { result = runCLI(`build ${project}`, {
env: { NODE_ENV: 'production' }, env: { NODE_ENV: 'production' },
}); });
expect(result.stdout).toContain('Successfully ran target build'); expect(result).toContain('Successfully ran target build');
expect(listFiles(`dist/${project}`)).toHaveLength(5); // same length as before expect(listFiles(`dist/${project}`)).toHaveLength(5); // same length as before
// Generate a new app and check that the files are correct // Generate a new app and check that the files are correct
const app2 = uniq('app2'); const app2 = uniq('app2');
await runNxCommandAsync( runCLI(
`generate @nx/rspack:app ${app2} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress --style=css` `generate @nx/rspack:app ${app2} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress --style=css`
); );
checkFilesExist(`${app2}/project.json`, `${app2}-e2e/project.json`); checkFilesExist(`${app2}/project.json`, `${app2}-e2e/project.json`);
@ -112,36 +111,34 @@ describe('rspack e2e', () => {
` `
); );
result = await runNxCommandAsync(`build ${app2}`, { result = runCLI(`build ${app2}`, {
env: { NODE_ENV: 'production' }, env: { NODE_ENV: 'production' },
}); });
expect(result.stdout).toContain('Successfully ran target build'); expect(result).toContain('Successfully ran target build');
// Make sure expected files are present. // Make sure expected files are present.
expect(listFiles(`dist/${app2}`)).toHaveLength(5); expect(listFiles(`dist/${app2}`)).toHaveLength(5);
result = await runNxCommandAsync(`test ${app2}`); result = runCLI(`test ${app2}`);
expect(result.stdout).toContain('Successfully ran target test'); expect(result).toContain('Successfully ran target test');
// TODO(Colum): re-enable when cypress issue is resolved // TODO(Colum): re-enable when cypress issue is resolved
// result = await runNxCommandAsync(`e2e ${app2}-e2e`); // result = runCLI(`e2e ${app2}-e2e`);
// expect(result.stdout).toContain('Successfully ran target e2e'); // expect(result.stdout).toContain('Successfully ran target e2e');
// Generate a Nest app and verify build output // Generate a Nest app and verify build output
const app3 = uniq('app3'); const app3 = uniq('app3');
await runNxCommandAsync( runCLI(
`generate @nx/rspack:app ${app3} --framework=nest --unitTestRunner=jest --no-interactive` `generate @nx/rspack:app ${app3} --framework=nest --unitTestRunner=jest --no-interactive`
); );
checkFilesExist(`${app3}/project.json`); checkFilesExist(`${app3}/project.json`);
result = await runNxCommandAsync(`build ${app3}`); result = runCLI(`build ${app3}`);
expect(result.stdout).toContain('Successfully ran target build'); expect(result).toContain('Successfully ran target build');
// Make sure expected files are present. // Make sure expected files are present.
expect(listFiles(`dist/${app3}`)).toHaveLength(2); expect(listFiles(`dist/${app3}`)).toHaveLength(2);
result = await runNxCommandAsync( result = runCLI(`build ${app3} --generatePackageJson=true`);
`build ${app3} --generatePackageJson=true` expect(result).toContain('Successfully ran target build');
);
expect(result.stdout).toContain('Successfully ran target build');
// Make sure expected files are present. // Make sure expected files are present.
expect(listFiles(`dist/${app3}`)).toHaveLength(4); expect(listFiles(`dist/${app3}`)).toHaveLength(4);
}, 200_000); }, 200_000);

View File

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

View File

@ -56,6 +56,7 @@ const nxPackages = [
`@nx/rollup`, `@nx/rollup`,
`@nx/react`, `@nx/react`,
`@nx/remix`, `@nx/remix`,
`@nx/rspack`,
`@nx/storybook`, `@nx/storybook`,
`@nx/vue`, `@nx/vue`,
`@nx/vite`, `@nx/vite`,