/
replace-app-import-with-storybook-toggle.spec.ts
65 lines (52 loc) · 1.94 KB
/
replace-app-import-with-storybook-toggle.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
import { addProjectConfiguration, Tree } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { formatFile } from '../../../utils/format-file';
import { replaceAppImportWithStorybookToggle } from './replace-app-import-with-storybook-toggle';
describe('replaceAppImportWithStorybookToggle', () => {
let tree: Tree;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
addProjectConfiguration(tree, 'products', {
root: 'apps/products',
sourceRoot: 'apps/products/src',
});
});
it('should update the main file with import from storybook', async () => {
tree.write(
'/apps/products/src/main.tsx',
formatFile`import { AppRegistry } from 'react-native';
import App from './app/App';
AppRegistry.registerComponent('main', () => App);
`
);
replaceAppImportWithStorybookToggle(tree, {
name: 'products',
js: false,
});
const mainFile = tree.read('apps/products/src/main.tsx', 'utf-8');
expect(formatFile`${mainFile}`).toEqual(
formatFile`import { AppRegistry } from 'react-native';
import App from './storybook/toggle-storybook';
AppRegistry.registerComponent('main', () => App);`
);
});
it('should not update the main file if import is already updated', async () => {
tree.write(
'/apps/products/src/main.tsx',
formatFile`import { AppRegistry } from 'react-native';
import App from './app/App';
AppRegistry.registerComponent('main', () => App);
`
);
replaceAppImportWithStorybookToggle(tree, {
name: 'products',
js: false,
});
const mainFile = tree.read('apps/products/src/main.tsx', 'utf-8');
expect(formatFile`${mainFile}`).toEqual(
formatFile`import { AppRegistry } from 'react-native';
import App from './storybook/toggle-storybook';
AppRegistry.registerComponent('main', () => App);`
);
});
});