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