Skip to content

Commit

Permalink
chore(react): improve react e2e tests speed
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Apr 14, 2023
1 parent 3e45445 commit 03983dd
Show file tree
Hide file tree
Showing 18 changed files with 373 additions and 308 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/e2e-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ jobs:
- e2e-nx-misc
- e2e-nx-plugin
- e2e-nx-run
- e2e-react
- e2e-react-core
- e2e-react-extensions
- e2e-react-native
- e2e-web
- e2e-rollup
Expand Down Expand Up @@ -172,7 +173,9 @@ jobs:
codeowners: 'S04SYHYKGNP'
- project: e2e-nx-run
codeowners: 'S04SYHYKGNP'
- project: e2e-react
- project: e2e-react-core
codeowners: 'S04TNCNJG5N'
- project: e2e-react-extensions
codeowners: 'S04TNCNJG5N'
- project: e2e-react-native
codeowners: 'S04TNCNJG5N'
Expand Down Expand Up @@ -232,7 +235,9 @@ jobs:
- node_version: 16
project: e2e-lerna-smoke-tests
- node_version: 16
project: e2e-react
project: e2e-react-core
- node_version: 16
project: e2e-react-extensions
- node_version: 16
project: e2e-react-native
- node_version: 16
Expand Down Expand Up @@ -278,7 +283,9 @@ jobs:
- node_version: 19
project: e2e-lerna-smoke-tests
- node_version: 19
project: e2e-react
project: e2e-react-core
- node_version: 19
project: e2e-react-extensions
- node_version: 19
project: e2e-react-native
- node_version: 19
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/e2e-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ jobs:
- e2e-nx-misc
- e2e-nx-plugin
- e2e-nx-run
- e2e-react
- e2e-react-core
- e2e-react-extensions
- e2e-web
- e2e-rollup
- e2e-storybook
Expand Down Expand Up @@ -126,7 +127,9 @@ jobs:
codeowners: 'S04SYHYKGNP'
- project: e2e-nx-run
codeowners: 'S04SYHYKGNP'
- project: e2e-react
- project: e2e-react-core
codeowners: 'S04TNCNJG5N'
- project: e2e-react-extensions
codeowners: 'S04TNCNJG5N'
- project: e2e-web
codeowners: 'S04SJ6PL98X'
Expand Down Expand Up @@ -173,7 +176,9 @@ jobs:
- node_version: 16
project: e2e-lerna-smoke-tests
- node_version: 16
project: e2e-react
project: e2e-react-core
- node_version: 16
project: e2e-react-extensions
- node_version: 16
project: e2e-web
- node_version: 16
Expand Down Expand Up @@ -213,7 +218,9 @@ jobs:
- node_version: 19
project: e2e-lerna-smoke-tests
- node_version: 19
project: e2e-react
project: e2e-react-core
- node_version: 19
project: e2e-react-extensions
- node_version: 19
project: e2e-web
- node_version: 19
Expand Down
3 changes: 2 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ yarn.lock @FrozenPandaz @vsavkin @AgentEnder @jaysoo @JamesHenry
/docs/shared/packages/react/** @jaysoo @ndcunningham @mandarini @xiongemi
/docs/shared/packages/next/** @jaysoo @ndcunningham @xiongemi
/packages/react/** @jaysoo @ndcunningham @mandarini @xiongemi
/e2e/react/** @jaysoo @mandarini @xiongemi @ndcunningham
/e2e/react-core/** @jaysoo @mandarini @xiongemi @ndcunningham
/e2e/react-extensions/** @jaysoo @mandarini @xiongemi @ndcunningham
/packages/next/** @ndcunningham @jaysoo @xiongemi
/e2e/next/** @ndcunningham @jaysoo @xiongemi
/packages/react/plugins/component-testing/** @jaysoo @ndcunningham @barbados-clemens
Expand Down
2 changes: 1 addition & 1 deletion e2e/react/jest.config.ts → e2e/react-core/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default {
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
maxWorkers: 1,
globals: {},
displayName: 'e2e-react',
displayName: 'e2e-react-core',
preset: '../../jest.preset.js',
};
4 changes: 2 additions & 2 deletions e2e/react/project.json → e2e/react-core/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "e2e-react",
"name": "e2e-react-core",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/react",
"sourceRoot": "e2e/react-core",
"projectType": "application",
"targets": {
"e2e": {},
Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
describe('React Module Federation', () => {
let proj: string;

beforeEach(() => (proj = newProject()));
beforeAll(() => (proj = newProject()));

afterEach(() => cleanupProject());
afterAll(() => cleanupProject());

it('should generate host and remote apps', async () => {
const shell = uniq('shell');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,130 +264,3 @@ export async function h() { return 'c'; }
}, 250000);
});
});

describe('Build React applications and libraries with Vite', () => {
let proj: string;

beforeEach(() => {
proj = newProject();
});

it('should test and lint app with bundler=vite', async () => {
const viteApp = uniq('viteapp');

runCLI(
`generate @nrwl/react:app ${viteApp} --bundler=vite --unitTestRunner=vitest --no-interactive`
);

const appTestResults = await runCLIAsync(`test ${viteApp}`);
expect(appTestResults.combinedOutput).toContain(
'Successfully ran target test'
);

const appLintResults = await runCLIAsync(`lint ${viteApp}`);
expect(appLintResults.combinedOutput).toContain(
'Successfully ran target lint'
);

await runCLIAsync(`build ${viteApp}`);
checkFilesExist(`dist/apps/${viteApp}/index.html`);
}, 300_000);

it('should test and lint app with bundler=vite and inSourceTests', async () => {
const viteApp = uniq('viteapp');
const viteLib = uniq('vitelib');

runCLI(
`generate @nrwl/react:app ${viteApp} --bundler=vite --unitTestRunner=vitest --inSourceTests --no-interactive`
);
expect(() => {
checkFilesExist(`apps/${viteApp}/src/app/app.spec.tsx`);
}).toThrow();

const appTestResults = await runCLIAsync(`test ${viteApp}`);
expect(appTestResults.combinedOutput).toContain(
'Successfully ran target test'
);

const appLintResults = await runCLIAsync(`lint ${viteApp}`);
expect(appLintResults.combinedOutput).toContain(
'Successfully ran target lint'
);

await runCLIAsync(`build ${viteApp}`);
checkFilesExist(`dist/apps/${viteApp}/index.html`);

runCLI(
`generate @nrwl/react:lib ${viteLib} --bundler=vite --inSourceTests --unitTestRunner=vitest --no-interactive`
);
expect(() => {
checkFilesExist(`libs/${viteLib}/src/lib/${viteLib}.spec.tsx`);
}).toThrow();

runCLI(
`generate @nrwl/react:component comp1 --inSourceTests --export --project=${viteLib} --no-interactive`
);
expect(() => {
checkFilesExist(`libs/${viteLib}/src/lib/comp1/comp1.spec.tsx`);
}).toThrow();

runCLI(
`generate @nrwl/react:component comp2 --export --project=${viteLib} --no-interactive`
);
checkFilesExist(`libs/${viteLib}/src/lib/comp2/comp2.spec.tsx`);

const libTestResults = await runCLIAsync(`test ${viteLib}`);
expect(libTestResults.combinedOutput).toContain(
'Successfully ran target test'
);

const libLintResults = await runCLIAsync(`lint ${viteLib}`);
expect(libLintResults.combinedOutput).toContain(
'Successfully ran target lint'
);

await runCLIAsync(`build ${viteLib}`);
checkFilesExist(
`dist/libs/${viteLib}/index.d.ts`,
`dist/libs/${viteLib}/index.js`,
`dist/libs/${viteLib}/index.mjs`
);
}, 300_000);

it('should support bundling with Vite', async () => {
const viteLib = uniq('vitelib');

runCLI(
`generate @nrwl/react:lib ${viteLib} --bundler=vite --no-interactive --unit-test-runner=none`
);

const packageJson = readJson('package.json');
// Vite does not need these libraries to work.
expect(packageJson.dependencies['core-js']).toBeUndefined();
expect(packageJson.dependencies['tslib']).toBeUndefined();

await runCLIAsync(`build ${viteLib}`);

checkFilesExist(
`dist/libs/${viteLib}/package.json`,
`dist/libs/${viteLib}/index.d.ts`,
`dist/libs/${viteLib}/index.js`,
`dist/libs/${viteLib}/index.mjs`
);

// Convert non-buildable lib to buildable one
const nonBuildableLib = uniq('nonbuildablelib');
runCLI(
`generate @nrwl/react:lib ${nonBuildableLib} --no-interactive --unitTestRunner=jest`
);
runCLI(
`generate @nrwl/vite:configuration ${nonBuildableLib} --uiFramework=react --no-interactive`
);
await runCLIAsync(`build ${nonBuildableLib}`);
checkFilesExist(
`dist/libs/${nonBuildableLib}/index.d.ts`,
`dist/libs/${nonBuildableLib}/index.js`,
`dist/libs/${nonBuildableLib}/index.mjs`
);
}, 300_000);
});
Loading

0 comments on commit 03983dd

Please sign in to comment.