feat(repo): merge main from https://github.com/nrwl/nx-labs
This commit is contained in:
commit
23c365f426
16
e2e/rspack/jest.config.ts
Normal file
16
e2e/rspack/jest.config.ts
Normal file
@ -0,0 +1,16 @@
|
||||
/* eslint-disable */
|
||||
export default {
|
||||
displayName: 'rspack-e2e',
|
||||
preset: '../../jest.preset.js',
|
||||
globals: {},
|
||||
transform: {
|
||||
'^.+\\.[tj]s$': [
|
||||
'ts-jest',
|
||||
{
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json',
|
||||
},
|
||||
],
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||
coverageDirectory: '../../coverage/e2e/rspack-e2e',
|
||||
};
|
||||
19
e2e/rspack/project.json
Normal file
19
e2e/rspack/project.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "rspack-e2e",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"sourceRoot": "e2e/rspack-e2e/src",
|
||||
"targets": {
|
||||
"e2e": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"options": {
|
||||
"jestConfig": "e2e/rspack-e2e/jest.config.ts",
|
||||
"runInBand": true,
|
||||
"passWithNoTests": false
|
||||
},
|
||||
"dependsOn": ["rspack:build"]
|
||||
}
|
||||
},
|
||||
"tags": [],
|
||||
"implicitDependencies": ["rspack"]
|
||||
}
|
||||
148
e2e/rspack/tests/rspack.spec.ts
Normal file
148
e2e/rspack/tests/rspack.spec.ts
Normal file
@ -0,0 +1,148 @@
|
||||
import { getPackageManagerCommand } from '@nx/devkit';
|
||||
import {
|
||||
checkFilesExist,
|
||||
ensureNxProject,
|
||||
listFiles,
|
||||
runNxCommandAsync,
|
||||
tmpProjPath,
|
||||
uniq,
|
||||
updateFile,
|
||||
} from '@nx/plugin/testing';
|
||||
import { execSync } from 'child_process';
|
||||
import { writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('rspack e2e', () => {
|
||||
// Setting up individual workspaces per
|
||||
// test can cause e2e runs to take a long time.
|
||||
// For this reason, we recommend each suite only
|
||||
// consumes 1 workspace. The tests should each operate
|
||||
// on a unique project in the workspace, such that they
|
||||
// are not dependant on one another.
|
||||
beforeAll(() => {
|
||||
ensureNxProject('@nx/rspack', 'dist/packages/rspack');
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
// `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 () => {
|
||||
const project = uniq('myapp');
|
||||
await runNxCommandAsync(
|
||||
`generate @nx/rspack:preset ${project} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress`
|
||||
);
|
||||
|
||||
// Added this so that the nx-ecosystem-ci tests don't throw jest error
|
||||
writeFileSync(
|
||||
join(tmpProjPath(), '.babelrc'),
|
||||
`
|
||||
{
|
||||
"presets": [
|
||||
"@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript",
|
||||
[
|
||||
"@nx/react/babel",
|
||||
{
|
||||
"runtime": "automatic"
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": ["@babel/plugin-transform-runtime"]
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
const pm = getPackageManagerCommand();
|
||||
execSync(
|
||||
pm.addDev +
|
||||
' @babel/preset-react @babel/preset-env @babel/preset-typescript',
|
||||
{ cwd: tmpProjPath() }
|
||||
);
|
||||
|
||||
let result = await runNxCommandAsync(`build ${project}`, {
|
||||
env: { NODE_ENV: 'production' },
|
||||
});
|
||||
expect(result.stdout).toContain('Successfully ran target build');
|
||||
// Make sure expected files are present.
|
||||
expect(listFiles(`dist/${project}`)).toHaveLength(5);
|
||||
|
||||
result = await runNxCommandAsync(`test ${project}`);
|
||||
expect(result.stdout).toContain('Successfully ran target test');
|
||||
|
||||
// TODO(Colum): re-enable when cypress issue is resolved
|
||||
// result = await runNxCommandAsync(`e2e e2e`);
|
||||
// expect(result.stdout).toContain('Successfully ran target e2e');
|
||||
|
||||
// Update app and make sure previous dist files are not present.
|
||||
updateFile(`src/app/app.tsx`, (content) => {
|
||||
return `${content}\nconsole.log('hello');
|
||||
`;
|
||||
});
|
||||
result = await runNxCommandAsync(`build ${project}`, {
|
||||
env: { NODE_ENV: 'production' },
|
||||
});
|
||||
expect(result.stdout).toContain('Successfully ran target build');
|
||||
expect(listFiles(`dist/${project}`)).toHaveLength(5); // same length as before
|
||||
|
||||
// Generate a new app and check that the files are correct
|
||||
const app2 = uniq('app2');
|
||||
await runNxCommandAsync(
|
||||
`generate @nx/rspack:app ${app2} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress --style=css`
|
||||
);
|
||||
checkFilesExist(`${app2}/project.json`, `${app2}-e2e/project.json`);
|
||||
|
||||
// Added this so that the nx-ecosystem-ci tests don't throw jest error
|
||||
writeFileSync(
|
||||
join(tmpProjPath(), app2, '.babelrc'),
|
||||
`
|
||||
{
|
||||
"presets": [
|
||||
"@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript",
|
||||
[
|
||||
"@nx/react/babel",
|
||||
{
|
||||
"runtime": "automatic"
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": ["@babel/plugin-transform-runtime"]
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
result = await runNxCommandAsync(`build ${app2}`, {
|
||||
env: { NODE_ENV: 'production' },
|
||||
});
|
||||
expect(result.stdout).toContain('Successfully ran target build');
|
||||
// Make sure expected files are present.
|
||||
expect(listFiles(`dist/${app2}`)).toHaveLength(5);
|
||||
|
||||
result = await runNxCommandAsync(`test ${app2}`);
|
||||
expect(result.stdout).toContain('Successfully ran target test');
|
||||
|
||||
// TODO(Colum): re-enable when cypress issue is resolved
|
||||
// result = await runNxCommandAsync(`e2e ${app2}-e2e`);
|
||||
// expect(result.stdout).toContain('Successfully ran target e2e');
|
||||
|
||||
// Generate a Nest app and verify build output
|
||||
const app3 = uniq('app3');
|
||||
await runNxCommandAsync(
|
||||
`generate @nx/rspack:app ${app3} --framework=nest --unitTestRunner=jest --no-interactive`
|
||||
);
|
||||
checkFilesExist(`${app3}/project.json`);
|
||||
|
||||
result = await runNxCommandAsync(`build ${app3}`);
|
||||
expect(result.stdout).toContain('Successfully ran target build');
|
||||
// Make sure expected files are present.
|
||||
expect(listFiles(`dist/${app3}`)).toHaveLength(2);
|
||||
|
||||
result = await runNxCommandAsync(
|
||||
`build ${app3} --generatePackageJson=true`
|
||||
);
|
||||
expect(result.stdout).toContain('Successfully ran target build');
|
||||
// Make sure expected files are present.
|
||||
expect(listFiles(`dist/${app3}`)).toHaveLength(4);
|
||||
}, 200_000);
|
||||
});
|
||||
10
e2e/rspack/tsconfig.json
Normal file
10
e2e/rspack/tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
9
e2e/rspack/tsconfig.spec.json
Normal file
9
e2e/rspack/tsconfig.spec.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user