-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
expo.test.ts
196 lines (173 loc) · 6.24 KB
/
expo.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import {
checkFilesExist,
cleanupProject,
expectTestsPass,
getPackageManagerCommand,
killPorts,
newProject,
promisifiedTreeKill,
readJson,
readResolvedConfiguration,
runCLI,
runCLIAsync,
runCommand,
runCommandUntil,
uniq,
updateFile,
updateJson,
} from '@nx/e2e/utils';
import { join } from 'path';
describe('expo', () => {
let proj: string;
let appName = uniq('my-app');
let libName = uniq('lib');
beforeAll(() => {
proj = newProject();
// we create empty preset above which skips creation of `production` named input
updateJson('nx.json', (nxJson) => {
nxJson.namedInputs = {
default: ['{projectRoot}/**/*', 'sharedGlobals'],
production: ['default'],
sharedGlobals: [],
};
nxJson.targetDefaults.build.inputs = ['production', '^production'];
return nxJson;
});
runCLI(`generate @nx/expo:application ${appName} --no-interactive`);
runCLI(
`generate @nx/expo:library ${libName} --buildable --publishable --importPath=${proj}/${libName}`
);
});
afterAll(() => cleanupProject());
it('should test and lint', async () => {
const componentName = uniq('component');
runCLI(
`generate @nx/expo:component ${componentName} --project=${libName} --export --no-interactive`
);
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.');
});
it('should export', async () => {
const exportResults = await runCLIAsync(
`export ${appName} --no-interactive`
);
expect(exportResults.combinedOutput).toContain(
'Export was successful. Your exported files can be found'
);
checkFilesExist(`dist/apps/${appName}/metadata.json`);
});
it('should export-web', async () => {
expect(() => {
runCLI(`export-web ${appName}`);
checkFilesExist(`apps/${appName}/dist/index.html`);
checkFilesExist(`apps/${appName}/dist/metadata.json`);
}).not.toThrow();
});
it('should prebuild', async () => {
// run prebuild command with git check disable
// set a mock package name for ios and android in expo's app.json
const projects = await readResolvedConfiguration();
const root = projects[appName].root;
const appJsonPath = join(root, `app.json`);
const appJson = await readJson(appJsonPath);
if (appJson.expo.ios) {
appJson.expo.ios.bundleIdentifier = 'nx.test';
}
if (appJson.expo.android) {
appJson.expo.android.package = 'nx.test';
}
updateFile(appJsonPath, JSON.stringify(appJson));
// run prebuild command with git check disable
process.env['EXPO_NO_GIT_STATUS'] = 'true';
const prebuildResult = await runCLIAsync(
`prebuild ${appName} --no-interactive --install=false`
);
expect(prebuildResult.combinedOutput).toContain('Config synced');
});
it('should install', async () => {
// run install command
const installResults = await runCLIAsync(
`install ${appName} --no-interactive`
);
expect(installResults.combinedOutput).toContain(
'Successfully ran target install'
);
});
it('should start', async () => {
// run start command
const startProcess = await runCommandUntil(
`start ${appName} -- --port=8081`,
(output) =>
output.includes(`Packager is ready at http://localhost:8081`) ||
output.includes(`Web is waiting on http://localhost:8081`)
);
// port and process cleanup
try {
await promisifiedTreeKill(startProcess.pid, 'SIGKILL');
await killPorts(8081);
} catch (err) {
expect(err).toBeFalsy();
}
});
it('should build publishable library', async () => {
expect(() => {
runCLI(`build ${libName}`);
checkFilesExist(`dist/libs/${libName}/index.esm.js`);
checkFilesExist(`dist/libs/${libName}/src/index.d.ts`);
}).not.toThrow();
});
it('should tsc app', async () => {
expect(() => {
const pmc = getPackageManagerCommand();
runCommand(
`${pmc.runUninstalledPackage} tsc -p apps/${appName}/tsconfig.app.json`
);
checkFilesExist(
`dist/out-tsc/apps/${appName}/src/app/App.js`,
`dist/out-tsc/apps/${appName}/src/app/App.d.ts`,
`dist/out-tsc/libs/${libName}/src/index.js`,
`dist/out-tsc/libs/${libName}/src/index.d.ts`
);
}).not.toThrow();
});
it('should support generating projects with the new name and root format', () => {
const appName = uniq('app1');
const libName = uniq('@my-org/lib1');
runCLI(
`generate @nx/expo:application ${appName} --project-name-and-root-format=as-provided --no-interactive`
);
// check files are generated without the layout directory ("apps/") and
// using the project name as the directory when no directory is provided
checkFilesExist(`${appName}/src/app/App.tsx`);
// check tests pass
const appTestResult = runCLI(`test ${appName}`);
expect(appTestResult).toContain(
`Successfully ran target test for project ${appName}`
);
// assert scoped project names are not supported when --project-name-and-root-format=derived
expect(() =>
runCLI(
`generate @nx/expo:library ${libName} --buildable --project-name-and-root-format=derived`
)
).toThrow();
runCLI(
`generate @nx/expo:library ${libName} --buildable --project-name-and-root-format=as-provided`
);
// check files are generated without the layout directory ("libs/") and
// using the project name as the directory when no directory is provided
checkFilesExist(`${libName}/src/index.ts`);
// check tests pass
const libTestResult = runCLI(`test ${libName}`);
expect(libTestResult).toContain(
`Successfully ran target test for project ${libName}`
);
});
});