-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
workspace-lib.test.ts
120 lines (93 loc) · 2.98 KB
/
workspace-lib.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import {
checkFilesExist,
newProject,
readJson,
cleanupProject,
runCLI,
runCLIAsync,
uniq,
updateFile,
expectJestTestsToPass,
} from '@nrwl/e2e/utils';
let proj: string;
beforeAll(() => {
proj = newProject();
});
afterAll(() => cleanupProject());
describe('@nrwl/workspace:library', () => {
it('should be able to be created', () => {
const libName = uniq('mylib');
const dirName = uniq('dir');
runCLI(`generate @nrwl/workspace:lib ${libName} --directory ${dirName}`);
checkFilesExist(
`libs/${dirName}/${libName}/src/index.ts`,
`libs/${dirName}/${libName}/README.md`
);
});
describe('linting', () => {
it('should support eslint', () => {
const libName = uniq('mylib');
runCLI(`generate @nrwl/workspace:lib ${libName}`);
const result = runCLI(`lint ${libName}`);
expect(result).toContain(`Linting "${libName}"...`);
expect(result).toContain('All files pass linting.');
});
});
describe('unit testing', () => {
it('should run default jest tests', async () => {
await expectJestTestsToPass('@nrwl/workspace:lib');
});
});
it('should be able to use and be used by other libs', () => {
const consumerLib = uniq('consumer');
const producerLib = uniq('producer');
runCLI(`generate @nrwl/workspace:lib ${consumerLib}`);
runCLI(`generate @nrwl/workspace:lib ${producerLib}`);
updateFile(
`libs/${producerLib}/src/lib/${producerLib}.ts`,
'export const a = 0;'
);
updateFile(
`libs/${consumerLib}/src/lib/${consumerLib}.ts`,
`
import { a } from '@${proj}/${producerLib}';
export function ${consumerLib}() {
return a + 1;
}`
);
updateFile(
`libs/${consumerLib}/src/lib/${consumerLib}.spec.ts`,
`
import { ${consumerLib} } from './${consumerLib}';
describe('', () => {
it('should return 1', () => {
expect(${consumerLib}()).toEqual(1);
});
});`
);
runCLI(`test ${consumerLib}`);
});
it('should be able to be built when it is buildable', () => {
const buildableLib = uniq('buildable');
runCLI(`generate @nrwl/workspace:lib ${buildableLib} --buildable`);
const result = runCLI(`build ${buildableLib}`);
expect(result).toContain(
`Compiling TypeScript files for project "${buildableLib}"...`
);
expect(result).toContain(
`Done compiling TypeScript files for project "${buildableLib}".`
);
checkFilesExist(`dist/libs/${buildableLib}/README.md`);
const json = readJson(`dist/libs/${buildableLib}/package.json`);
expect(json.main).toEqual('./src/index.js');
expect(json.typings).toEqual('./src/index.d.ts');
});
});
describe('@nrwl/workspace:npm-package', () => {
it('should create a minimal npm package', () => {
const npmPackage = uniq('npm-package');
runCLI(`generate @nrwl/workspace:npm-package ${npmPackage}`);
const result = runCLI(`test ${npmPackage}`);
expect(result).toContain('Hello World');
});
});