-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
react-native.test.ts
163 lines (144 loc) · 5.46 KB
/
react-native.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import {
checkFilesExist,
cleanupProject,
expectTestsPass,
newProject,
readJson,
runCLI,
runCLIAsync,
uniq,
updateFile,
} from '@nrwl/e2e/utils';
import { join } from 'path';
describe('react native', () => {
let proj: string;
beforeAll(() => (proj = newProject()));
afterAll(() => cleanupProject());
it('should test, create ios and android JS bundles', async () => {
const appName = uniq('my-app');
const libName = uniq('lib');
const componentName = uniq('component');
runCLI(
`generate @nrwl/react-native:application ${appName} --install=false`
);
runCLI(`generate @nrwl/react-native:library ${libName}`);
runCLI(
`generate @nrwl/react-native:component ${componentName} --project=${libName} --export`
);
updateFile(`apps/${appName}/src/app/App.tsx`, (content) => {
let updated = `// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport {${componentName}} from '${proj}/${libName}';\n${content}`;
return updated;
});
expectTestsPass(await runCLIAsync(`test ${appName}`));
expectTestsPass(await runCLIAsync(`test ${libName}`));
const appLintResults = await runCLIAsync(`lint ${appName}`);
expect(appLintResults.combinedOutput).toContain('All files pass linting.');
const libLintResults = await runCLIAsync(`lint ${libName}`);
expect(libLintResults.combinedOutput).toContain('All files pass linting.');
const iosBundleResult = await runCLIAsync(
`bundle-ios ${appName} --sourcemapOutput=../../dist/apps/${appName}/ios/main.map`
);
expect(iosBundleResult.combinedOutput).toContain(
'Done writing bundle output'
);
expect(() => {
checkFilesExist(`dist/apps/${appName}/ios/main.jsbundle`);
checkFilesExist(`dist/apps/${appName}/ios/main.map`);
}).not.toThrow();
const androidBundleResult = await runCLIAsync(
`bundle-android ${appName} --sourcemapOutput=../../dist/apps/${appName}/android/main.map`
);
expect(androidBundleResult.combinedOutput).toContain(
'Done writing bundle output'
);
expect(() => {
checkFilesExist(`dist/apps/${appName}/android/main.jsbundle`);
checkFilesExist(`dist/apps/${appName}/android/main.map`);
}).not.toThrow();
}, 1000000);
it('should create storybook with application', async () => {
const appName = uniq('my-app');
runCLI(
`generate @nrwl/react-native:application ${appName} --install=false`
);
runCLI(
`generate @nrwl/react-native:storybook-configuration ${appName} --generateStories --no-interactive`
);
expect(() =>
checkFilesExist(
`.storybook/story-loader.js`,
`apps/${appName}/src/storybook/storybook.ts`,
`apps/${appName}/src/storybook/toggle-storybook.tsx`,
`apps/${appName}/src/app/App.stories.tsx`
)
).not.toThrow();
await runCLIAsync(`storybook ${appName}`);
const result = readJson(join('apps', appName, 'package.json'));
expect(result).toMatchObject({
dependencies: {
'@storybook/addon-ondevice-actions': '*',
'@storybook/addon-ondevice-backgrounds': '*',
'@storybook/addon-ondevice-controls': '*',
'@storybook/addon-ondevice-notes': '*',
},
});
});
it('should upgrade native for application', async () => {
const appName = uniq('my-app');
runCLI(
`generate @nrwl/react-native:application ${appName} --install=false`
);
expect(() =>
runCLI(
`generate @nrwl/react-native:upgrade-native ${appName} --install=false`
)
).not.toThrow();
});
it('should build publishable library', async () => {
const libName = uniq('lib');
const componentName = uniq('component');
runCLI(
`generate @nrwl/react-native:library ${libName} --buildable --publishable --importPath=${proj}/${libName}`
);
runCLI(
`generate @nrwl/react-native:component ${componentName} --project=${libName} --export`
);
expect(() => {
runCLI(`build ${libName}`);
checkFilesExist(`dist/libs/${libName}/index.js`);
checkFilesExist(`dist/libs/${libName}/src/index.d.ts`);
}).not.toThrow();
});
it('sync npm dependencies for autolink', async () => {
const appName = uniq('my-app');
runCLI(
`generate @nrwl/react-native:application ${appName} --install=false`
);
// Add npm package with native modules
updateFile(join('package.json'), (content) => {
const json = JSON.parse(content);
json.dependencies['react-native-image-picker'] = '1.0.0';
json.dependencies['react-native-gesture-handler'] = '1.0.0';
json.dependencies['react-native-safe-area-contex'] = '1.0.0';
return JSON.stringify(json, null, 2);
});
// Add import for Nx to pick up
updateFile(join('apps', appName, 'src/app/App.tsx'), (content) => {
return `import AsyncStorage from '@react-native-async-storage/async-storage';import Config from 'react-native-config';\n${content}`;
});
await runCLIAsync(
`sync-deps ${appName} --include=react-native-gesture-handler,react-native-safe-area-context,react-native-image-picker`
);
const result = readJson(join('apps', appName, 'package.json'));
expect(result).toMatchObject({
dependencies: {
'react-native-image-picker': '*',
'react-native-gesture-handler': '*',
'react-native-safe-area-context': '*',
'react-native': '*',
'react-native-config': '*',
'@react-native-async-storage/async-storage': '*',
},
});
});
});