Skip to content

Commit

Permalink
fix(testing): make sure default jest tests pass for various projects
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens committed May 4, 2022
1 parent ebabc8c commit 41d4928
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 33 deletions.
30 changes: 6 additions & 24 deletions e2e/jest/src/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import {
runCLIAsync,
uniq,
updateFile,
fileExists,
expectJestTestsToPass,
} from '@nrwl/e2e/utils';

describe('Jest', () => {
beforeAll(() => {
newProject({ name: uniq('proj-jest') });
});

it('should be able test projects using jest', async () => {
await expectJestTestsToPass('@nrwl/workspace:lib');
await expectJestTestsToPass('@nrwl/js:lib');
}, 500000);

it('should merge with jest config globals', async () => {
const testGlobal = `'My Test Global'`;
const mylib = uniq('mylib');
Expand Down Expand Up @@ -140,27 +145,4 @@ describe('Jest', () => {
'Test Suites: 1 passed, 1 total'
);
}, 90000);

[
{ generator: '@nrwl/js:lib', name: uniq('js-lib') },
{ generator: '@nrwl/node:lib', name: uniq('node-lib') },
{ generator: '@nrwl/react:lib', name: uniq('react-lib') },
{ generator: '@nrwl/react:app', name: uniq('react-app') },
{ generator: '@nrwl/next:app', name: uniq('next-app') },
{ generator: '@nrwl/angular:app', name: uniq('angular-app') },
{ generator: '@nrwl/workspace:lib', name: uniq('workspace-lib') },
{ generator: '@nrwl/web:app', name: uniq('web-app') },
].forEach(({ generator, name }) => {
it(`should run default jest tests for ${generator}`, async () => {
const generatedResults = runCLI(
`generate ${generator} ${name} --no-interactive`
);
expect(generatedResults).toContain(`jest.config.ts`);

const results = await runCLIAsync(`test ${name}`);
expect(results.combinedOutput).toContain(
'Test Suites: 1 passed, 1 total'
);
}, 500000);
});
});
5 changes: 5 additions & 0 deletions e2e/js/src/js.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
checkFilesExist,
expectJestTestsToPass,
checkFilesDoNotExist,
newProject,
readFile,
Expand Down Expand Up @@ -242,4 +243,8 @@ describe('js e2e', () => {

checkFilesDoNotExist(`libs/${lib}/.babelrc`);
});

it('should run default jest tests', async () => {
await expectJestTestsToPass('@nrwl/js:lib');
});
});
4 changes: 4 additions & 0 deletions e2e/next/src/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
checkFilesExist,
cleanupProject,
createFile,
expectJestTestsToPass,
isNotWindows,
killPorts,
newProject,
Expand Down Expand Up @@ -409,6 +410,9 @@ describe('Next.js Applications', () => {
checkExport: false,
});
}, 300000);
it('should run default jest tests', async () => {
await expectJestTestsToPass('@nrwl/next:app');
});
});

function getData(port: number, path = ''): Promise<any> {
Expand Down
5 changes: 5 additions & 0 deletions e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { stripIndents } from '@angular-devkit/core/src/utils/literals';
import {
checkFilesDoNotExist,
checkFilesExist,
expectJestTestsToPass,
killPorts,
newProject,
packageInstall,
Expand Down Expand Up @@ -482,4 +483,8 @@ exports.FooModel = FooModel;
checkFilesDoNotExist('workspace.json', 'angular.json')
).not.toThrow();
}, 1000000);

it('should run default jest tests', async () => {
await expectJestTestsToPass('@nrwl/node:lib');
});
});
6 changes: 6 additions & 0 deletions e2e/react/src/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
checkFilesDoNotExist,
checkFilesExist,
createFile,
expectJestTestsToPass,
killPorts,
newProject,
readFile,
Expand Down Expand Up @@ -289,4 +290,9 @@ describe('React Applications and Libs with PostCSS', () => {
expect(buildResults.combinedOutput).toMatch(/HELLO FROM APP/);
expect(buildResults.combinedOutput).not.toMatch(/HELLO FROM LIB/);
}, 250_000);

it('should run default jest tests', async () => {
await expectJestTestsToPass('@nrwl/react:lib');
await expectJestTestsToPass('@nrwl/react:app');
});
});
27 changes: 27 additions & 0 deletions e2e/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,30 @@ export function waitUntil(
}, opts.timeout);
});
}

type GeneratorsWithDefaultTests =
| '@nrwl/js:lib'
| '@nrwl/node:lib'
| '@nrwl/react:lib'
| '@nrwl/react:app'
| '@nrwl/next:app'
| '@nrwl/angular:app'
| '@nrwl/workspace:lib'
| '@nrwl/web:app';

/**
* Runs the pass in generator and then runs test on
* the generated project to make sure the default tests pass.
*/
export async function expectJestTestsToPass(
generator: GeneratorsWithDefaultTests | string
) {
const name = uniq('proj');
const generatedResults = runCLI(
`generate ${generator} ${name} --no-interactive`
);
expect(generatedResults).toContain(`jest.config.ts`);

const results = await runCLIAsync(`test ${name}`);
expect(results.combinedOutput).toContain('Test Suites: 1 passed, 1 total');
}
5 changes: 5 additions & 0 deletions e2e/web/src/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
uniq,
updateFile,
updateProjectConfig,
expectJestTestsToPass,
} from '@nrwl/e2e/utils';

describe('Web Components Applications', () => {
Expand Down Expand Up @@ -181,6 +182,10 @@ describe('Web Components Applications', () => {
checkFilesDoNotExist('workspace.json', 'angular.json')
).not.toThrow();
}, 1000000);

it('should run default jest tests', async () => {
await expectJestTestsToPass('@nrwl/web:app');
});
});

describe('CLI - Environment Variables', () => {
Expand Down
12 changes: 3 additions & 9 deletions e2e/workspace-core/src/workspace-lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
runCLIAsync,
uniq,
updateFile,
expectJestTestsToPass,
} from '@nrwl/e2e/utils';

let proj: string;
Expand Down Expand Up @@ -44,15 +45,8 @@ describe('@nrwl/workspace:library', () => {
});

describe('unit testing', () => {
it('should support jest', async () => {
const libName = uniq('mylib');

runCLI(`generate @nrwl/workspace:lib ${libName}`);

const { stderr: result } = await runCLIAsync(`test ${libName}`);

expect(result).toContain(`Test Suites: 1 passed, 1 total`);
expect(result).toContain('Tests: 1 passed, 1 total');
it('should run default jest tests', async () => {
await expectJestTestsToPass('@nrwl/workspace:lib');
});
});

Expand Down

0 comments on commit 41d4928

Please sign in to comment.