|
| 1 | +/* eslint-disable no-console */ |
| 2 | +import * as childProcess from 'child_process'; |
| 3 | +import { sync as rimrafSync } from 'rimraf'; |
| 4 | + |
| 5 | +const TEST_APP_DIR = 'test/buildProcess/testApp'; |
| 6 | + |
| 7 | +/** |
| 8 | + * Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current |
| 9 | + * process if this script is run with the `--debug` flag. Returns contents of `stdout`. |
| 10 | + */ |
| 11 | +function run(cmd: string, options?: childProcess.ExecSyncOptions): string { |
| 12 | + return String( |
| 13 | + childProcess.execSync(cmd, { |
| 14 | + stdio: process.argv.includes('--debug') ? 'inherit' : 'ignore', |
| 15 | + ...options, |
| 16 | + }), |
| 17 | + ); |
| 18 | +} |
| 19 | + |
| 20 | +// Note: We use a file dependency for the SDK, rather than linking it, because if it's linked, nextjs rolls the entire |
| 21 | +// SDK and all of its dependencies into a bundle, making it impossible to tell (from the NFT file, at least) what's |
| 22 | +// being included. |
| 23 | +console.log('Installing dependencies...'); |
| 24 | +process.chdir(TEST_APP_DIR); |
| 25 | +rimrafSync('node_modules'); |
| 26 | +run('yarn'); |
| 27 | + |
| 28 | +console.log('Building app...'); |
| 29 | +rimrafSync('.next'); |
| 30 | +run('yarn build'); |
| 31 | + |
| 32 | +console.log('App built. Running tests...'); |
| 33 | +process.chdir('..'); |
| 34 | +try { |
| 35 | + // Even if this script hasn't been run with the `--debug` flag, we want the output of tests to be shown. |
| 36 | + run('yarn jest tests', { stdio: 'inherit' }); |
| 37 | +} catch (err) { |
| 38 | + console.log('\nNot all build process tests passed.'); |
| 39 | +} |
0 commit comments