-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chore(node-integration-tests): Improve node test runner naming #21685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ import { existsSync } from 'fs'; | |
| import { cp, mkdir, readFile, rm, writeFile } from 'fs/promises'; | ||
| import { basename, join } from 'path'; | ||
| import { inspect, promisify } from 'util'; | ||
| import { afterAll, beforeAll, describe, test } from 'vitest'; | ||
| import { afterAll, beforeAll, test, type TestAPI } from 'vitest'; | ||
| import type { DeepPartial } from './assertions'; | ||
| import { | ||
| assertEnvelopeHeader, | ||
|
|
@@ -296,47 +296,82 @@ export function createEsmAndCjsTests( | |
| } | ||
| } | ||
|
|
||
| describe('esm/cjs', () => { | ||
| const esmTestFn = options?.failsOnEsm ? test.fails : test; | ||
| describe('esm', () => { | ||
| callback( | ||
| () => createRunner(esmScenarioPathForRun).withFlags('--import', esmInstrumentPathForRun), | ||
| esmTestFn, | ||
| 'esm', | ||
| tmpDirPath, | ||
| ); | ||
| // Wrap the test API so it prepends the test name with the mode | ||
| // Also wraps the nested fields `only`, `skip`, `each`, and `for` | ||
| function wrapTestApi(api: TestAPI | typeof test.fails | typeof test.only | typeof test.skip, suffix: string) { | ||
| return new Proxy(api, { | ||
| apply: (target, thisArg, args: Parameters<typeof api>) => { | ||
| if (typeof args[0] === 'string') { | ||
| args[0] = `${args[0]} [${suffix}]`; | ||
| } | ||
|
|
||
| return Reflect.apply(target, thisArg, args); | ||
| }, | ||
|
|
||
| get: (target, prop: 'only' | 'skip' | 'each' | 'for') => { | ||
| if (prop === 'only' || prop === 'skip') { | ||
| return wrapTestApi(target[prop], suffix); | ||
| } | ||
|
|
||
| if (prop === 'each' || prop === 'for') { | ||
| return wrapTestEachApi(target[prop], suffix); | ||
| } | ||
|
|
||
| return Reflect.get(target, prop); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| const cjsTestFn = options?.failsOnCjs ? test.fails : test; | ||
| describe('cjs', () => { | ||
| callback( | ||
| () => createRunner(cjsScenarioPath).withFlags('--require', cjsInstrumentPath), | ||
| cjsTestFn, | ||
| 'cjs', | ||
| tmpDirPath, | ||
| ); | ||
| // For test.each, we can't just wrap the function itself, but need to wrap the returned function | ||
| // As usage is e.g. test.each(...)('test name', () => {}) | ||
| function wrapTestEachApi<Api extends typeof test.each | typeof test.for>(api: Api, suffix: string) { | ||
| return new Proxy(api, { | ||
| apply: (target, thisArg, args: Parameters<typeof api>) => { | ||
| const res = Reflect.apply(target, thisArg, args); | ||
|
|
||
| return new Proxy(res, { | ||
| apply: (target, thisArg, args: Parameters<ReturnType<typeof test.each>>) => { | ||
| if (typeof args[0] === 'string') { | ||
| args[0] = `${args[0]} [${suffix}]`; | ||
| } | ||
| return Reflect.apply(target, thisArg, args); | ||
| }, | ||
| }); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| // Create tmp directory | ||
| beforeAll(async () => { | ||
| await createTmpDir(); | ||
| }, 60_000); | ||
| const esmTestFn = options?.failsOnEsm ? wrapTestApi(test.fails, 'esm - fails') : wrapTestApi(test, 'esm'); | ||
| const cjsTestFn = options?.failsOnCjs ? wrapTestApi(test.fails, 'cjs - fails') : wrapTestApi(test, 'cjs'); | ||
|
|
||
| // Clean up the tmp directory after both esm and cjs suites have run | ||
| afterAll(async () => { | ||
| // First do cleanup! | ||
| cleanupChildProcesses(); | ||
| callback( | ||
| () => createRunner(esmScenarioPathForRun).withFlags('--import', esmInstrumentPathForRun), | ||
| esmTestFn, | ||
| 'esm', | ||
| tmpDirPath, | ||
| ); | ||
|
|
||
| try { | ||
| await rm(tmpDirPath, { recursive: true, force: true }); | ||
| } catch { | ||
| if (process.env.DEBUG) { | ||
| // eslint-disable-next-line no-console | ||
| console.error(`Failed to remove tmp dir: ${tmpDirPath}`); | ||
| } | ||
| callback(() => createRunner(cjsScenarioPath).withFlags('--require', cjsInstrumentPath), cjsTestFn, 'cjs', tmpDirPath); | ||
|
|
||
| // Create tmp directory | ||
| beforeAll(async () => { | ||
| await createTmpDir(); | ||
| }, 60_000); | ||
|
|
||
| // Clean up the tmp directory after both esm and cjs suites have run | ||
| afterAll(async () => { | ||
| // First do cleanup! | ||
| cleanupChildProcesses(); | ||
|
|
||
| try { | ||
| await rm(tmpDirPath, { recursive: true, force: true }); | ||
| } catch { | ||
| if (process.env.DEBUG) { | ||
| // eslint-disable-next-line no-console | ||
| console.error(`Failed to remove tmp dir: ${tmpDirPath}`); | ||
| } | ||
| }, 30_000); | ||
| }); | ||
| } | ||
| }, 30_000); | ||
|
Comment on lines
+364
to
+374
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Multiple Suggested FixRefactor the cleanup mechanism to be robust against concurrent execution. Instead of a single global set that gets cleared, each Prompt for AI Agent |
||
| } | ||
|
|
||
| async function convertEsmFileToCjs(inputPath: string, outputPath: string): Promise<void> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.