-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
stories-lib.spec.ts
87 lines (77 loc) · 2.36 KB
/
stories-lib.spec.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
import { Tree } from '@nrwl/devkit';
import storiesGenerator from './stories';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import applicationGenerator from '../application/application';
import { Linter } from '@nrwl/linter';
import libraryGenerator from '../library/library';
import reactNativeComponentGenerator from '../component/component';
describe('react-native:stories for libraries', () => {
let appTree: Tree;
beforeEach(async () => {
appTree = await createTestUILib('test-ui-lib');
});
it('should create the stories', async () => {
await reactNativeComponentGenerator(appTree, {
name: 'test-ui-lib',
project: 'test-ui-lib',
});
await reactNativeComponentGenerator(appTree, {
name: 'another-cmp',
project: 'test-ui-lib',
});
await storiesGenerator(appTree, {
project: 'test-ui-lib',
});
expect(
appTree.exists(
'libs/test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx'
)
).toBeTruthy();
expect(
appTree.exists(
'libs/test-ui-lib/src/lib/another-cmp/another-cmp.stories.tsx'
)
).toBeTruthy();
});
it('should ignore files that do not contain components', async () => {
await reactNativeComponentGenerator(appTree, {
name: 'test-ui-lib',
project: 'test-ui-lib',
});
// create another component
appTree.write(
'libs/test-ui-lib/src/lib/some-command-line-utils.ts',
`export const add = (a: number, b: number) => a + b;`
);
await storiesGenerator(appTree, {
project: 'test-ui-lib',
});
// should just create the story and not error, even though there's a js file
// not containing any react component
expect(
appTree.exists(
'libs/test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx'
)
).toBeTruthy();
});
});
export async function createTestUILib(libName: string): Promise<Tree> {
let appTree = createTreeWithEmptyWorkspace();
appTree.write('.gitignore', '');
await libraryGenerator(appTree, {
linter: Linter.EsLint,
skipFormat: true,
skipTsConfig: false,
unitTestRunner: 'none',
name: libName,
});
await applicationGenerator(appTree, {
e2eTestRunner: 'none',
linter: Linter.EsLint,
skipFormat: false,
unitTestRunner: 'none',
name: `${libName}-e2e`,
install: false,
});
return appTree;
}