Update test framework: fix run_tests.py to support all test files, add auto-import-check for test files

This commit is contained in:
qiaoxinjiu
2026-05-09 15:11:30 +08:00
parent eb053a347f
commit eaba8328da
21739 changed files with 2236758 additions and 719 deletions

View File

@@ -0,0 +1,7 @@
export const a = 'a'
export function aFunc () {
return a
}
export * from './foo.mjs'

View File

@@ -0,0 +1,5 @@
export const b = 'b'
export function bFunc () {
return b
}

View File

@@ -0,0 +1,4 @@
import bar from './something.mjs'
export default bar
export * from './a.mjs'
export * from './b.mjs'

View File

@@ -0,0 +1,18 @@
// The following is generated by tslib. __exportStar is a format which cjs-module-lexer exposes as a reexport
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./circular-b"), exports);
exports.foo = 42;

View File

@@ -0,0 +1,5 @@
import { bar } from './circular-b.mjs'
export const foo = 1
export { bar }

View File

@@ -0,0 +1,15 @@
// The following is generated by tslib. __exportStar is a format which cjs-module-lexer exposes as a reexport
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./circular-a"), exports);

View File

@@ -0,0 +1,3 @@
import { foo } from './circular-a.mjs'
export const bar = foo + 1

View File

@@ -0,0 +1,7 @@
import { testB } from './cyclical-b.mjs'
export function testA () {
console.log('testA')
}
testB()

View File

@@ -0,0 +1,6 @@
import { testA } from './cyclical-a.mjs'
export function testB () {
console.log('testB')
testA()
}

View File

@@ -0,0 +1,8 @@
// File generated from our OpenAPI spec by Stainless.
import * as BatchesAPI from './cyclical-self.mjs'
export class Batches {}
export class BatchesPage {}
(function (Batches) {
Batches.BatchesPage = BatchesAPI.BatchesPage
// eslint-disable-next-line no-class-assign
})(Batches || (Batches = {}))

View File

@@ -0,0 +1,4 @@
export const foo = 'a'
export default function () {
return 'c'
}

View File

@@ -0,0 +1 @@
export const foo = 'b'

View File

@@ -0,0 +1 @@
export const foo = 'c'

View File

@@ -0,0 +1,5 @@
export * from './duplicate-a.mjs'
export * from './duplicate-b.mjs'
export { foo } from './duplicate-c.mjs'
export * from './duplicate-a.mjs'
export * from './duplicate-b.mjs'

View File

@@ -0,0 +1,5 @@
export * from './duplicate-a.mjs'
export * from './duplicate-b.mjs'
const foo = 'foo'
export default foo

View File

@@ -0,0 +1,8 @@
let env = { FOO: 'baz' }
function setEnv (newEnv) {
console.log('setting env, env.FOO is', newEnv.FOO)
env = newEnv
}
export { setEnv, env }

View File

@@ -0,0 +1,32 @@
// Exporting declarations
export let name1, name2/*, … */; // also var //| name1,name2
export const name1 = 1, name2 = 2/*, … */; // also var, let //| name1,name2
export function functionName() { /* … */ } //| functionName
export class ClassName { /* … */ } //| ClassName
export function* generatorFunctionName() { /* … */ } //| generatorFunctionName
export const { name1, name2: bar } = o; //| name1,bar
export const [ name1, name2 ] = array; //| name1,name2
// Export list
let name1, nameN; export { name1, /* …, */ nameN }; //| name1,nameN
let variable1, variable2, nameN; export { variable1 as name1, variable2 as name2, /* …, */ nameN }; //| name1,name2,nameN
let variable1; export { variable1 as "string name" }; //| string name
let name1; export { name1 as default /*, … */ }; //| default
// Default exports
export default expression; //| default
export default function functionName() { /* … */ } //| default
export default class ClassName { /* … */ } //| default
export default function* generatorFunctionName() { /* … */ } //| default
export default function () { /* … */ } //| default
export default class { /* … */ } //| default
export default function* () { /* … */ } //| default
// Aggregating modules
export * from "module-name"; //| * from module-name
export * as name1 from "module-name"; //| name1
export { name1, /* …, */ nameN } from "module-name"; //| name1,nameN
export { import1 as name1, import2 as name2, /* …, */ nameN } from "module-name"; //| name1,name2,nameN
export { default, /* …, */ } from "module-name"; //| default
export { default as name1 } from "module-name"; //| name1

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env node
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
// This script doesn't actually have to do anything.

View File

@@ -0,0 +1,19 @@
const o = { name5: 1, name6: 1 }
const array = [1, 1]
// Exporting declarations
export const name1 = 1; export const name2 = 1/*, … */ // also var
export const name3 = 1; export const name4 = 1/*, … */ // also var, let
export function functionName () { return 1 }
export class ClassName { getFoo () { return 1 } }
export function * generatorFunctionName () { return 1 }
export const { name5, name6: bar } = o
export const [name7, name8] = array
export async function asyncFunctionName () { return 1 }
export async function * asyncGeneratorFunctionName () { yield 1 }
export const arrowFunction = () => {
return 1
}
export const asyncArrowFunction = async () => {
return 1
}

View File

@@ -0,0 +1,2 @@
export * from './default-call-expression.mjs'
export { default as somethingElse } from './default-call-expression.mjs'

View File

@@ -0,0 +1 @@
export default parseInt('1')

View File

@@ -0,0 +1 @@
export default class { getFoo () { return 1 } }

View File

@@ -0,0 +1 @@
export default class ClassName { getFoo () { return 1 } }

View File

@@ -0,0 +1 @@
export default [1]

View File

@@ -0,0 +1 @@
export default 1

View File

@@ -0,0 +1 @@
export default 'dog'

View File

@@ -0,0 +1 @@
export default function () { return 1 }

View File

@@ -0,0 +1 @@
export default function functionName () { return 1 }

View File

@@ -0,0 +1 @@
export default function * () { return 1 }

View File

@@ -0,0 +1 @@
export default function * generatorFunctionName () { return 1 }

View File

@@ -0,0 +1,3 @@
export default function () {
return 1
}

View File

@@ -0,0 +1,2 @@
import fnDefaultExport from './fn-default-export.mjs'
export default fnDefaultExport

View File

@@ -0,0 +1,12 @@
// Export list
const name1 = 1
const name2 = 1
const name5 = 1
const variable1 = 1
const variable2 = 1
const variable3 = 1
const name6 = 1
export { name1, name2 }
export { variable1 as name3, variable2 as name4, /* …, */ name5 }
export { variable3 as 'name' }
export { name6 as default /*, … */ }

View File

@@ -0,0 +1,5 @@
const temp = function () {
return 1
}
export default temp

View File

@@ -0,0 +1,5 @@
export function foo () {
return 'foo'
}
export * from './lib/baz.mjs'

View File

@@ -0,0 +1,11 @@
// This replicates the way the in-the-wild `got` module does things:
// https://github.com/sindresorhus/got/blob/3822412/source/index.ts
class got {
foo = 'foo'
}
export default got
export { got }
export * from './something.mjs'
export { default as renamedDefaultExport } from './lib/baz.mjs'

View File

@@ -0,0 +1,10 @@
import { strictEqual } from 'assert'
import * as foo from './foo.mjs'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
const fooPath = join(dirname(fileURLToPath(import.meta.url)), 'foo.mjs')
strictEqual(typeof foo.foo, 'function')
strictEqual(global.hooked.length, 1)
strictEqual(global.hooked[0], fooPath)

View File

@@ -0,0 +1,18 @@
import { register } from 'module'
import { Hook, createAddHookMessageChannel } from '../../index.js'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
const fooPath = join(dirname(fileURLToPath(import.meta.url)), 'foo.mjs')
const { registerOptions, waitForAllMessagesAcknowledged } = createAddHookMessageChannel()
register('../../hook.mjs', import.meta.url, registerOptions)
global.hooked = []
Hook([fooPath], (_, name) => {
global.hooked.push(name)
})
await waitForAllMessagesAcknowledged()

View File

@@ -0,0 +1,16 @@
import { strictEqual } from 'assert'
import { sep } from 'path'
import * as os from 'node:os'
import { Hook } from '../../index.js'
const hooked = []
Hook((_, name) => {
hooked.push(name)
})
strictEqual(hooked.length, 2)
strictEqual(hooked[0], 'path')
strictEqual(hooked[1], 'os')
strictEqual(sep, '@')
strictEqual(os.arch(), 'new_crazy_arch')

View File

@@ -0,0 +1,23 @@
import { register } from 'module'
import { Hook, createAddHookMessageChannel } from '../../index.js'
// We've imported path here to ensure that the hook is still applied later even
// if the library is used here.
import * as path from 'path'
const { registerOptions, waitForAllMessagesAcknowledged } = createAddHookMessageChannel()
register('../../hook.mjs', import.meta.url, registerOptions)
Hook(['path'], (exports) => {
exports.sep = '@'
})
Hook(['os'], (exports) => {
exports.arch = function () {
return 'new_crazy_arch'
}
})
console.assert(path.sep !== '@')
await waitForAllMessagesAcknowledged()

View File

@@ -0,0 +1 @@
module.exports.foo = 'something'

View File

@@ -0,0 +1,8 @@
// These export identifiers are only supported in Node 16+
exports['one.two'] = () => console.log('b')
// See: https://github.com/nodejs/import-in-the-middle/issues/94
exports['unsigned short'] = 'something'
exports._ = 'foo'
exports.$ = 'bar'

View File

@@ -0,0 +1,5 @@
import coolFile from './something.json' with { type: 'json' }
export default {
data: coolFile.data
}

View File

@@ -0,0 +1,9 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
import coolFile from './something.json' assert { type: 'json' }
export default {
data: coolFile.data
}

View File

@@ -0,0 +1,4 @@
export function baz () {
return 'baz'
}
export default baz

View File

@@ -0,0 +1,7 @@
// Regression test for https://github.com/nodejs/import-in-the-middle/issues/196
export default function foo () {
// do nothing
}
export { foo as 'module.exports' }

View File

@@ -0,0 +1,2 @@
console.log(`skipping ${process.env.IITM_TEST_FILE} as no native module is available for ${process.platform}-${process.arch}`)
process.exit(0)

View File

@@ -0,0 +1 @@
module.exports = require('@node-rs/crc32-darwin-arm64')

View File

@@ -0,0 +1 @@
module.exports = require('@node-rs/crc32-darwin-x64')

View File

@@ -0,0 +1 @@
module.exports = require('@node-rs/crc32-linux-arm64-gnu')

View File

@@ -0,0 +1,2 @@
console.log(`skipping ${process.env.IITM_TEST_FILE} as no native module is available for ${process.platform}-${process.arch}`)
process.exit(0)

View File

@@ -0,0 +1,2 @@
console.log(`skipping ${process.env.IITM_TEST_FILE} as no native module is available for ${process.platform}-${process.arch}`)
process.exit(0)

View File

@@ -0,0 +1 @@
module.exports = require('@node-rs/crc32-linux-x64-gnu')

View File

@@ -0,0 +1 @@
module.exports = require('@node-rs/crc32-win32-arm64-msvc')

View File

@@ -0,0 +1 @@
module.exports = require('@node-rs/crc32-win32-x64-msvc')

View File

@@ -0,0 +1 @@
module.exports = { ...require('#main-entry-point') }

View File

@@ -0,0 +1,17 @@
{
"name": "test-fixtures",
"imports": {
"#main-entry-point": {
"require": {
"node": "./something.js",
"default": "./something.js"
},
"import": {
"node":"./something.mjs",
"default": "./something.mjs"
}
},
"#main-entry-point-string" : "./something.js",
"#main-entry-point-external" : "some-external-cjs-module"
}
}

View File

@@ -0,0 +1 @@
module.exports = require('util').deprecate

View File

@@ -0,0 +1 @@
module.exports = require('./something.json')

View File

@@ -0,0 +1 @@
module.exports = require('some-external-cjs-module').foo

View File

@@ -0,0 +1 @@
export * from 'some-external-module'

View File

@@ -0,0 +1,15 @@
// The following is generated by tslib. __exportStar is a format which cjs-module-lexer exposes as a reexport
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./something"), exports);

View File

@@ -0,0 +1 @@
module.exports = { ...require('.') }

View File

@@ -0,0 +1,3 @@
export const sayHi = (name: string) => {
return `Hi ${name}`
};

View File

@@ -0,0 +1,10 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
'use strict'
module.exports = function bar () {
return 42
}
module.exports.foo = 42

View File

@@ -0,0 +1,3 @@
{
"data": "dog"
}

View File

@@ -0,0 +1,9 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
export const foo = 42
export default function bar () {
return foo
}

View File

@@ -0,0 +1,7 @@
export type { Debugger } from 'node:inspector'
export const foo: number = 42
export function bar(): number {
return foo
}

View File

@@ -0,0 +1 @@
module.exports = { ...require('#main-entry-point-external') }

View File

@@ -0,0 +1 @@
module.exports = { ...require('#main-entry-point-string') }

View File

@@ -0,0 +1 @@
export * from '#main-entry-point'

View File

@@ -0,0 +1 @@
export * from 'some-external-module/sub'