|
1 | 1 | 'use strict'; |
2 | 2 | require('../common'); |
| 3 | +const { spawnSyncAndAssert } = require('../common/child_process'); |
3 | 4 | const fixtures = require('../common/fixtures'); |
4 | 5 |
|
5 | 6 | // This is a minimum integration test for CJS transpiled from ESM that tries to load real ESM. |
6 | 7 |
|
7 | | -const { spawnSync } = require('child_process'); |
8 | | -const result = spawnSync(process.execPath, [ |
| 8 | +spawnSyncAndAssert(process.execPath, [ |
9 | 9 | '--experimental-require-module', |
10 | 10 | fixtures.path('es-modules', 'transpiled-cjs-require-module', 'dist', 'import-both.cjs'), |
11 | 11 | ], { |
12 | | - encoding: 'utf8', |
| 12 | + trim: true, |
| 13 | + stdout: 'import both', |
13 | 14 | }); |
14 | | -if (!result.stdout.includes('import both')) { |
15 | | - throw new Error(`stdout did not include 'import both':\n${result.stdout}`); |
16 | | -} |
17 | 15 |
|
18 | | -const resultNamed = spawnSync(process.execPath, [ |
| 16 | +spawnSyncAndAssert(process.execPath, [ |
19 | 17 | '--experimental-require-module', |
20 | 18 | fixtures.path('es-modules', 'transpiled-cjs-require-module', 'dist', 'import-named.cjs'), |
21 | 19 | ], { |
22 | | - encoding: 'utf8', |
| 20 | + trim: true, |
| 21 | + stdout: 'import named', |
23 | 22 | }); |
24 | | -if (!resultNamed.stdout.includes('import named')) { |
25 | | - throw new Error(`stdout did not include 'import named':\n${resultNamed.stdout}`); |
26 | | -} |
27 | 23 |
|
28 | | -const resultDefault = spawnSync(process.execPath, [ |
| 24 | +spawnSyncAndAssert(process.execPath, [ |
29 | 25 | '--experimental-require-module', |
30 | 26 | fixtures.path('es-modules', 'transpiled-cjs-require-module', 'dist', 'import-default.cjs'), |
31 | 27 | ], { |
32 | | - encoding: 'utf8', |
| 28 | + trim: true, |
| 29 | + stdout: 'import default', |
33 | 30 | }); |
34 | | -if (!resultDefault.stdout.includes('import default')) { |
35 | | - throw new Error(`stdout did not include 'import default':\n${resultDefault.stdout}`); |
36 | | -} |
0 commit comments