forked from nrwl/nx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.test.ts
89 lines (80 loc) · 2.98 KB
/
jest.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {
runCLIAsync,
ensureProject,
uniq,
runCLI,
forEachCli,
updateFile
} from './utils';
import { stripIndents } from '@angular-devkit/core/src/utils/literals';
forEachCli(() => {
describe('Jest', () => {
it('should be able test projects using jest', async done => {
ensureProject();
const mylib = uniq('mylib');
const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --unit-test-runner jest`);
runCLI(`generate @nrwl/angular:lib ${mylib} --unit-test-runner jest`);
await Promise.all([
runCLIAsync(`generate @nrwl/angular:service test --project ${myapp}`),
runCLIAsync(`generate @nrwl/angular:component test --project ${myapp}`),
runCLIAsync(`generate @nrwl/angular:service test --project ${mylib}`),
runCLIAsync(`generate @nrwl/angular:component test --project ${mylib}`)
]);
const appResult = await runCLIAsync(`test ${myapp} --no-watch`);
expect(appResult.stderr).toContain('Test Suites: 3 passed, 3 total');
const libResult = await runCLIAsync(`test ${mylib}`);
expect(libResult.stderr).toContain('Test Suites: 3 passed, 3 total');
done();
}, 45000);
it('should merge with jest config globals', async done => {
ensureProject();
const testGlobal = `'My Test Global'`;
const mylib = uniq('mylib');
runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`);
updateFile(`libs/${mylib}/src/lib/${mylib}.ts`, `export class Test { }`);
updateFile(
`libs/${mylib}/src/lib/${mylib}.spec.ts`,
`
test('can access jest global', () => {
expect((global as any).testGlobal).toBe(${testGlobal});
});
`
);
updateFile(
`libs/${mylib}/jest.config.js`,
stripIndents`
module.exports = {
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
transform: {
'^.+\\.(ts|js|html)$': 'ts-jest'
},
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html'],
coverageReporters: ['html'],
passWithNoTests: true,
globals: { testGlobal: ${testGlobal} }
};`
);
const appResult = await runCLIAsync(`test ${mylib} --no-watch`);
expect(appResult.stderr).toContain('Test Suites: 1 passed, 1 total');
done();
}, 45000);
it('should set the NODE_ENV to `test`', async done => {
ensureProject();
const mylib = uniq('mylib');
runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`);
updateFile(
`libs/${mylib}/src/lib/${mylib}.spec.ts`,
`
test('can access jest global', () => {
expect(process.env.NODE_ENV).toBe('test');
});
`
);
const appResult = await runCLIAsync(`test ${mylib} --no-watch`);
expect(appResult.stderr).toContain('Test Suites: 1 passed, 1 total');
done();
}, 45000);
});
});