-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run: use --import, do not intercept exitCode
If plugins export an `importLoader`, and Module.register exists, then use that instead of their `loader` export. process.exitCode became {configurable:false} in nodejs/node#44711 Can bring back exitCode interception when/if it becomes configurable again, re nodejs/node#49579 For now, just set it, and then verify it's the expected value, and put it back to 0 if so.
- Loading branch information
Showing
8 changed files
with
135 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// the arguments when running test files, abstracted from run.ts for testing | ||
import type { LoadedConfig } from '@tapjs/config' | ||
import { importLoaders, loaderFallbacks, loaders } from '@tapjs/test' | ||
import module from 'node:module' | ||
|
||
// if we have Module.register(), then use --import wherever possible | ||
const useImport = !!(module as { register?: (...a: any) => any }) | ||
.register | ||
|
||
const importScripts = useImport ? importLoaders : [] | ||
const loaderScripts = useImport ? loaders : loaderFallbacks | ||
|
||
const pi = useImport | ||
? '--import=@tapjs/processinfo/import' | ||
: '--loader=@tapjs/processinfo/loader' | ||
|
||
const always = [ | ||
...importScripts.map(l => `--import=${l}`), | ||
...loaderScripts.map(l => `--loader=${l}`), | ||
...(useImport && !loaderScripts.length | ||
? [] | ||
: ['--no-warnings=ExperimentalLoader']), | ||
'--enable-source-maps', | ||
// ensure this always comes last in the list | ||
pi, | ||
] | ||
|
||
export const testArgv = (config: LoadedConfig) => [ | ||
...always, | ||
...(config.get('node-arg') || []), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import {LoadedConfig} from '@tapjs/config' | ||
import t from 'tap' | ||
|
||
const mocks = { | ||
'@tapjs/test': { | ||
importLoaders: ['blah/import'], | ||
loaders: ['no-import/loader'], | ||
loaderFallbacks: ['blah/loader', 'no-import/loader'], | ||
}, | ||
module: { | ||
register: () => {} | ||
} | ||
} | ||
|
||
const mocksNoImport = { | ||
'@tapjs/test': { | ||
importLoaders: ['blah/import'], | ||
loaders: ['no-import/loader'], | ||
loaderFallbacks: ['blah/loader', 'no-import/loader'], | ||
}, | ||
module: { | ||
register: null | ||
} | ||
} | ||
|
||
const mocksAllImport = { | ||
'@tapjs/test': { | ||
importLoaders: ['blah/import', 'has-import/import'], | ||
loaders: [], | ||
loaderFallbacks: ['blah/loader', 'has-import/loader'], | ||
}, | ||
module: { | ||
register: () => {} | ||
} | ||
} | ||
|
||
t.test('mix of loaders and imports', async t => { | ||
const { testArgv } = await t.mockImport('../dist/test-argv.js', mocks) as typeof import('../dist/test-argv.js') | ||
t.strictSame(testArgv({ get: () => {}} as unknown as LoadedConfig), [ | ||
'--import=blah/import', | ||
'--loader=no-import/loader', | ||
'--no-warnings=ExperimentalLoader', | ||
'--enable-source-maps', | ||
'--import=@tapjs/processinfo/import', | ||
]) | ||
}) | ||
|
||
t.test('with --node-arg', async t => { | ||
const { testArgv } = await t.mockImport('../dist/test-argv.js', mocks) as typeof import('../dist/test-argv.js') | ||
t.strictSame(testArgv({ get: () => ['a', 'b']} as unknown as LoadedConfig), [ | ||
'--import=blah/import', | ||
'--loader=no-import/loader', | ||
'--no-warnings=ExperimentalLoader', | ||
'--enable-source-maps', | ||
'--import=@tapjs/processinfo/import', | ||
'a', | ||
'b', | ||
]) | ||
}) | ||
|
||
t.test('all imports, no loader', async t => { | ||
const { testArgv } = await t.mockImport('../dist/test-argv.js', mocksAllImport) as typeof import('../dist/test-argv.js') | ||
t.strictSame(testArgv({ get: () => []} as unknown as LoadedConfig), [ | ||
'--import=blah/import', | ||
'--import=has-import/import', | ||
'--enable-source-maps', | ||
'--import=@tapjs/processinfo/import', | ||
]) | ||
}) | ||
|
||
t.test('no import support, only loader', async t => { | ||
const { testArgv } = await t.mockImport('../dist/test-argv.js', mocksNoImport) as typeof import('../dist/test-argv.js') | ||
t.strictSame(testArgv({ get: () => []} as unknown as LoadedConfig), [ | ||
'--loader=blah/loader', | ||
'--loader=no-import/loader', | ||
'--no-warnings=ExperimentalLoader', | ||
'--enable-source-maps', | ||
'--loader=@tapjs/processinfo/loader', | ||
]) | ||
}) |