Skip to content

Commit 23c365f

Browse files
committed
feat(repo): merge main from https://github.com/nrwl/nx-labs
2 parents b0ffe29 + c9f3070 commit 23c365f

File tree

5 files changed

+202
-0
lines changed

5 files changed

+202
-0
lines changed

e2e/rspack/jest.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'rspack-e2e',
4+
preset: '../../jest.preset.js',
5+
globals: {},
6+
transform: {
7+
'^.+\\.[tj]s$': [
8+
'ts-jest',
9+
{
10+
tsconfig: '<rootDir>/tsconfig.spec.json',
11+
},
12+
],
13+
},
14+
moduleFileExtensions: ['ts', 'js', 'html'],
15+
coverageDirectory: '../../coverage/e2e/rspack-e2e',
16+
};

e2e/rspack/project.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "rspack-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"projectType": "application",
5+
"sourceRoot": "e2e/rspack-e2e/src",
6+
"targets": {
7+
"e2e": {
8+
"executor": "@nx/jest:jest",
9+
"options": {
10+
"jestConfig": "e2e/rspack-e2e/jest.config.ts",
11+
"runInBand": true,
12+
"passWithNoTests": false
13+
},
14+
"dependsOn": ["rspack:build"]
15+
}
16+
},
17+
"tags": [],
18+
"implicitDependencies": ["rspack"]
19+
}

e2e/rspack/tests/rspack.spec.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import { getPackageManagerCommand } from '@nx/devkit';
2+
import {
3+
checkFilesExist,
4+
ensureNxProject,
5+
listFiles,
6+
runNxCommandAsync,
7+
tmpProjPath,
8+
uniq,
9+
updateFile,
10+
} from '@nx/plugin/testing';
11+
import { execSync } from 'child_process';
12+
import { writeFileSync } from 'fs';
13+
import { join } from 'path';
14+
15+
describe('rspack e2e', () => {
16+
// Setting up individual workspaces per
17+
// test can cause e2e runs to take a long time.
18+
// For this reason, we recommend each suite only
19+
// consumes 1 workspace. The tests should each operate
20+
// on a unique project in the workspace, such that they
21+
// are not dependant on one another.
22+
beforeAll(() => {
23+
ensureNxProject('@nx/rspack', 'dist/packages/rspack');
24+
});
25+
26+
afterAll(() => {
27+
// `nx reset` kills the daemon, and performs
28+
// some work which can help clean up e2e leftovers
29+
runNxCommandAsync('reset');
30+
});
31+
32+
it('should create rspack root project and additional apps', async () => {
33+
const project = uniq('myapp');
34+
await runNxCommandAsync(
35+
`generate @nx/rspack:preset ${project} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress`
36+
);
37+
38+
// Added this so that the nx-ecosystem-ci tests don't throw jest error
39+
writeFileSync(
40+
join(tmpProjPath(), '.babelrc'),
41+
`
42+
{
43+
"presets": [
44+
"@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript",
45+
[
46+
"@nx/react/babel",
47+
{
48+
"runtime": "automatic"
49+
}
50+
]
51+
],
52+
"plugins": ["@babel/plugin-transform-runtime"]
53+
}
54+
`
55+
);
56+
57+
const pm = getPackageManagerCommand();
58+
execSync(
59+
pm.addDev +
60+
' @babel/preset-react @babel/preset-env @babel/preset-typescript',
61+
{ cwd: tmpProjPath() }
62+
);
63+
64+
let result = await runNxCommandAsync(`build ${project}`, {
65+
env: { NODE_ENV: 'production' },
66+
});
67+
expect(result.stdout).toContain('Successfully ran target build');
68+
// Make sure expected files are present.
69+
expect(listFiles(`dist/${project}`)).toHaveLength(5);
70+
71+
result = await runNxCommandAsync(`test ${project}`);
72+
expect(result.stdout).toContain('Successfully ran target test');
73+
74+
// TODO(Colum): re-enable when cypress issue is resolved
75+
// result = await runNxCommandAsync(`e2e e2e`);
76+
// expect(result.stdout).toContain('Successfully ran target e2e');
77+
78+
// Update app and make sure previous dist files are not present.
79+
updateFile(`src/app/app.tsx`, (content) => {
80+
return `${content}\nconsole.log('hello');
81+
`;
82+
});
83+
result = await runNxCommandAsync(`build ${project}`, {
84+
env: { NODE_ENV: 'production' },
85+
});
86+
expect(result.stdout).toContain('Successfully ran target build');
87+
expect(listFiles(`dist/${project}`)).toHaveLength(5); // same length as before
88+
89+
// Generate a new app and check that the files are correct
90+
const app2 = uniq('app2');
91+
await runNxCommandAsync(
92+
`generate @nx/rspack:app ${app2} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress --style=css`
93+
);
94+
checkFilesExist(`${app2}/project.json`, `${app2}-e2e/project.json`);
95+
96+
// Added this so that the nx-ecosystem-ci tests don't throw jest error
97+
writeFileSync(
98+
join(tmpProjPath(), app2, '.babelrc'),
99+
`
100+
{
101+
"presets": [
102+
"@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript",
103+
[
104+
"@nx/react/babel",
105+
{
106+
"runtime": "automatic"
107+
}
108+
]
109+
],
110+
"plugins": ["@babel/plugin-transform-runtime"]
111+
}
112+
`
113+
);
114+
115+
result = await runNxCommandAsync(`build ${app2}`, {
116+
env: { NODE_ENV: 'production' },
117+
});
118+
expect(result.stdout).toContain('Successfully ran target build');
119+
// Make sure expected files are present.
120+
expect(listFiles(`dist/${app2}`)).toHaveLength(5);
121+
122+
result = await runNxCommandAsync(`test ${app2}`);
123+
expect(result.stdout).toContain('Successfully ran target test');
124+
125+
// TODO(Colum): re-enable when cypress issue is resolved
126+
// result = await runNxCommandAsync(`e2e ${app2}-e2e`);
127+
// expect(result.stdout).toContain('Successfully ran target e2e');
128+
129+
// Generate a Nest app and verify build output
130+
const app3 = uniq('app3');
131+
await runNxCommandAsync(
132+
`generate @nx/rspack:app ${app3} --framework=nest --unitTestRunner=jest --no-interactive`
133+
);
134+
checkFilesExist(`${app3}/project.json`);
135+
136+
result = await runNxCommandAsync(`build ${app3}`);
137+
expect(result.stdout).toContain('Successfully ran target build');
138+
// Make sure expected files are present.
139+
expect(listFiles(`dist/${app3}`)).toHaveLength(2);
140+
141+
result = await runNxCommandAsync(
142+
`build ${app3} --generatePackageJson=true`
143+
);
144+
expect(result.stdout).toContain('Successfully ran target build');
145+
// Make sure expected files are present.
146+
expect(listFiles(`dist/${app3}`)).toHaveLength(4);
147+
}, 200_000);
148+
});

e2e/rspack/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"files": [],
4+
"include": [],
5+
"references": [
6+
{
7+
"path": "./tsconfig.spec.json"
8+
}
9+
]
10+
}

e2e/rspack/tsconfig.spec.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"types": ["jest", "node"]
7+
},
8+
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
9+
}

0 commit comments

Comments
 (0)