-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
stories-app.spec.ts
128 lines (109 loc) · 3.2 KB
/
stories-app.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
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
121
122
123
124
125
126
127
128
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';
describe('react:stories for applications', () => {
let appTree: Tree;
beforeEach(async () => {
appTree = await createTestUIApp('test-ui-app');
// create another component
appTree.write(
'apps/test-ui-app/src/app/anothercmp/another-cmp.tsx',
`import React from 'react';
import './test.scss';
export interface TestProps {
name: string;
displayAge: boolean;
}
export const Test = (props: TestProps) => {
return (
<div>
<h1>Welcome to test component, {props.name}</h1>
</div>
);
};
export default Test;
`
);
});
it('should create the stories', async () => {
await storiesGenerator(appTree, {
project: 'test-ui-app',
generateCypressSpecs: false,
});
expect(
appTree.exists('apps/test-ui-app/src/app/nx-welcome.stories.tsx')
).toBeTruthy();
expect(
appTree.exists(
'apps/test-ui-app/src/app/anothercmp/another-cmp.stories.tsx'
)
).toBeTruthy();
});
it('should generate Cypress specs', async () => {
await storiesGenerator(appTree, {
project: 'test-ui-app',
generateCypressSpecs: true,
});
expect(
appTree.exists('apps/test-ui-app-e2e/src/integration/app.spec.ts')
).toBeTruthy();
expect(
appTree.exists(
'apps/test-ui-app-e2e/src/integration/another-cmp/another-cmp.spec.ts'
)
).toBeTruthy();
});
it('should ignore files that do not contain components', async () => {
// create another component
appTree.write(
'apps/test-ui-app/src/app/some-utils.js',
`export const add = (a: number, b: number) => a + b;`
);
await storiesGenerator(appTree, {
project: 'test-ui-app',
generateCypressSpecs: false,
});
// should just create the story and not error, even though there's a js file
// not containing any react component
expect(
appTree.exists('apps/test-ui-app/src/app/nx-welcome.stories.tsx')
).toBeTruthy();
});
it('should not update existing stories', async () => {
// ARRANGE
appTree.write(
'apps/test-ui-app/src/app/nx-welcome.stories.tsx',
`import { ComponentStory, ComponentMeta } from '@storybook/react'`
);
// ACT
await storiesGenerator(appTree, {
project: 'test-ui-app',
generateCypressSpecs: false,
});
// ASSERT
expect(
appTree.read('apps/test-ui-app/src/app/nx-welcome.stories.tsx', 'utf-8')
).toEqual(
`import { ComponentStory, ComponentMeta } from '@storybook/react'`
);
});
});
export async function createTestUIApp(
libName: string,
plainJS = false
): Promise<Tree> {
let appTree = createTreeWithEmptyWorkspace();
await applicationGenerator(appTree, {
e2eTestRunner: 'cypress',
linter: Linter.EsLint,
skipFormat: false,
style: 'css',
unitTestRunner: 'none',
name: libName,
js: plainJS,
standaloneConfig: false,
});
return appTree;
}