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 4, 2023
1 parent 18c016b commit 132aa44
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 298 deletions.
File renamed without changes.
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 132aa44

Please sign in to comment.