/
runTest.ts
39 lines (34 loc) · 1.33 KB
/
runTest.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
/* eslint-disable no-console */
import * as childProcess from 'child_process';
import { sync as rimrafSync } from 'rimraf';
const TEST_APP_DIR = 'test/buildProcess/testApp';
/**
* Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current
* process if this script is run with the `--debug` flag. Returns contents of `stdout`.
*/
function run(cmd: string, options?: childProcess.ExecSyncOptions): string {
return String(
childProcess.execSync(cmd, {
stdio: process.argv.includes('--debug') ? 'inherit' : 'ignore',
...options,
}),
);
}
// Note: We use a file dependency for the SDK, rather than linking it, because if it's linked, nextjs rolls the entire
// SDK and all of its dependencies into a bundle, making it impossible to tell (from the NFT file, at least) what's
// being included.
console.log('Installing dependencies...');
process.chdir(TEST_APP_DIR);
rimrafSync('node_modules');
run('yarn');
console.log('Building app...');
rimrafSync('.next');
run('yarn build');
console.log('App built. Running tests...');
process.chdir('..');
try {
// Even if this script hasn't been run with the `--debug` flag, we want the output of tests to be shown.
run('yarn jest tests', { stdio: 'inherit' });
} catch (err) {
console.log('\nNot all build process tests passed.');
}