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,11 @@
import { foo } from '../fixtures/circular-b.js'
import Hook from '../../index.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/circular-[ab].js/)) {
exports.foo += 15
}
})
strictEqual(foo, 57)

View File

@@ -0,0 +1,4 @@
import { Batches, BatchesPage } from '../fixtures/cyclical-self.mjs'
import { strictEqual } from 'assert'
strictEqual(Batches.BatchesPage, BatchesPage)

View File

@@ -0,0 +1,86 @@
// 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 Hook from '../../index.js'
import a from '../fixtures/export-types/default-expression-array.mjs'
import n from '../fixtures/export-types/default-expression-num.mjs'
import s from '../fixtures/export-types/default-expression-string.mjs'
import fn from '../fixtures/export-types/default-function.mjs'
import cn from '../fixtures/export-types/default-class.mjs'
import gfn from '../fixtures/export-types/default-generator.mjs'
import afn from '../fixtures/export-types/default-function-anon.mjs'
import acn from '../fixtures/export-types/default-class-anon.mjs'
import agfn from '../fixtures/export-types/default-generator-anon.mjs'
import callEx from '../fixtures/export-types/default-call-expression.mjs'
import { somethingElse } from '../fixtures/export-types/default-call-expression-renamed.mjs'
import defaultImportExport from '../fixtures/export-types/import-default-export.mjs'
import varDefaultExport from '../fixtures/export-types/variable-default-export.mjs'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/default-expression-array\.m?js/)) {
exports.default[0] += 1
} else if (name.match(/default-expression-num\.m?js/)) {
exports.default += 1
} else if (name.match(/default-expression-string\.m?js/)) {
exports.default += 'dawg'
} else if (name.match(/default-function\.m?js/)) {
const orig = exports.default
exports.default = function () {
return orig() + 1
}
} else if (name.match(/default-class\.m?js/)) {
exports.default.prototype.getFoo = function () {
return 2
}
} else if (name.match(/default-generator\.m?js/)) {
const orig2 = exports.default
exports.default = function * () {
return orig2().next().value + 1
}
} else if (name.match(/default-function-anon\.m?js/)) {
const orig = exports.default
exports.default = function () {
return orig() + 1
}
} else if (name.match(/default-class-anon\.m?js/)) {
exports.default.prototype.getFoo = function () {
return 2
}
} else if (name.match(/default-generator-anon\.m?js/)) {
const orig2 = exports.default
exports.default = function * () {
return orig2().next().value + 1
}
} else if (name.match(/import-default-export\.m?js/)) {
const orig3 = exports.default
exports.default = function () {
return orig3() + 1
}
} else if (name.match(/variable-default-export\.m?js/)) {
const orig4 = exports.default
exports.default = function () {
return orig4() + 1
}
} else if (name.match(/default-call-expression\.m?js/)) {
exports.default += 1
} else if (name.match(/default-call-expression-renamed\.m?js/)) {
exports.somethingElse += 1
}
})
/* eslint-disable new-cap */
strictEqual(defaultImportExport(), 2)
strictEqual(varDefaultExport(), 2)
strictEqual(a[0], 2)
strictEqual(fn(), 2)
strictEqual(new cn().getFoo(), 2)
strictEqual(gfn().next().value, 2)
strictEqual(afn(), 2)
strictEqual(new acn().getFoo(), 2)
strictEqual(agfn().next().value, 2)
strictEqual(n, 2)
strictEqual(s, 'dogdawg')
strictEqual(callEx, 2)
strictEqual(somethingElse, 2)

View File

@@ -0,0 +1,20 @@
// 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.
const Hook = require('../../index.js')
const { rejects } = require('assert')
Hook((exports, name) => {
if (name === 'os') {
Object.defineProperty(exports, 'freemem', {
get: () => () => 47
})
}
})
;(async () => {
rejects(async () => {
await import('os')
})
})()

View File

@@ -0,0 +1,13 @@
import * as lib from '../fixtures/duplicate-explicit.mjs'
import { strictEqual } from 'assert'
import Hook from '../../index.js'
Hook((exports, name) => {
if (name.endsWith('duplicate-explicit.mjs')) {
strictEqual(exports.foo, 'c')
exports.foo += '-wrapped'
}
})
// foo should not be exported because there are duplicate exports
strictEqual(lib.foo, 'c-wrapped')

View File

@@ -0,0 +1,19 @@
import * as lib from '../fixtures/duplicate.mjs'
import { notEqual, strictEqual } from 'assert'
import Hook from '../../index.js'
Hook((exports, name) => {
if (name.match(/duplicate\.mjs/)) {
// foo should not be exported because there are duplicate * exports
strictEqual('foo' in exports, false)
// default should be exported
strictEqual(exports.default, 'foo')
}
})
notEqual(lib, undefined)
// foo should not be exported because there are duplicate exports
strictEqual('foo' in lib, false)
// default should be exported
strictEqual(lib.default, 'foo')

View File

@@ -0,0 +1,29 @@
// 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.
const Hook = require('../../index.js')
const { strictEqual } = require('assert')
Hook((exports, name) => {
if (name.match(/something.js/)) {
const orig = exports.default
exports.default = function bar () {
return orig() + 15
}
}
if (name.match(/something.mjs/)) {
const orig = exports.default
return function bar () {
return orig() + 15
}
}
})
;(async () => {
const { default: barMjs } = await import('../fixtures/something.mjs')
const { default: barJs } = await import('../fixtures/something.js')
strictEqual(barMjs(), 57)
strictEqual(barJs(), 57)
})()

View File

@@ -0,0 +1,23 @@
// 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 Hook from '../../index.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/something\.m?js/)) {
const orig = exports.default
exports.default = function bar () {
return orig() + 15
}
}
})
;(async () => {
const { default: barMjs } = await import('../fixtures/something.mjs')
const { default: barJs } = await import('../fixtures/something.js')
strictEqual(barMjs(), 57)
strictEqual(barJs(), 57)
})()

View File

@@ -0,0 +1,27 @@
// 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.
const { Hook } = require('../../index.js')
const { strictEqual } = require('assert')
Hook((exports, name) => {
if (name.match(/something\.m?js/)) {
exports.foo += 15
}
if (name === 'os') {
Object.defineProperty(exports, 'freemem', {
value: () => 47
})
}
})
;(async () => {
const { foo: fooMjs } = await import('../fixtures/something.mjs')
const { foo: fooJs } = await import('../fixtures/something.js')
const { freemem } = await import('os')
strictEqual(fooMjs, 57)
strictEqual(fooJs, 57)
strictEqual(freemem(), 47)
})()

View File

@@ -0,0 +1,27 @@
// 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 Hook from '../../index.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/something\.m?js/)) {
exports.foo += 15
}
if (name === 'os') {
Object.defineProperty(exports, 'freemem', {
value: () => 47
})
}
})
;(async () => {
const { foo: fooMjs } = await import('../fixtures/something.mjs')
const { foo: fooJs } = await import('../fixtures/something.js')
const { freemem } = await import('os')
strictEqual(fooMjs, 57)
strictEqual(fooJs, 57)
strictEqual(freemem(), 47)
})()

View File

@@ -0,0 +1,11 @@
import { foo } from '../fixtures/reexport.js'
import Hook from '../../index.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/reexport.js/)) {
exports.foo += 15
}
})
strictEqual(foo, 57)

View File

@@ -0,0 +1,5 @@
// 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.
// Empty file just to validate the loader is not crashing.

View File

@@ -0,0 +1,25 @@
// 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 Hook from '../../index.js'
import { foo as fooMjs } from '../fixtures/something.mjs'
import { foo as fooJs } from '../fixtures/something.js'
import { strictEqual, deepStrictEqual } from 'assert'
let hookedExports
Hook((exports, name) => {
hookedExports = exports
})
strictEqual(fooMjs, 42)
strictEqual(fooJs, 42)
strictEqual(hookedExports[Symbol.toStringTag], 'Module')
deepStrictEqual(Object.getOwnPropertyDescriptor(hookedExports, Symbol.toStringTag), {
value: 'Module',
enumerable: false,
writable: false,
configurable: false
})

View File

@@ -0,0 +1,26 @@
import Hook from '../../index.js'
import foo from '../fixtures/re-export-cjs-built-in.js'
import foo2 from '../fixtures/re-export-cjs.js'
import foo3 from '../fixtures/re-export-cjs-json.js'
import { deepStrictEqual, strictEqual } from 'assert'
Hook((exports, name) => {
if (name.endsWith('fixtures/re-export-cjs-built-in.js')) {
strictEqual(typeof exports.default, 'function')
exports.default = '1'
}
if (name.endsWith('fixtures/re-export-cjs.js')) {
strictEqual(exports.default, 'bar')
exports.default = '2'
}
if (name.endsWith('fixtures/re-export-cjs-json.js')) {
deepStrictEqual(exports.default, { data: 'dog' })
exports.default = '3'
}
})
strictEqual(foo, '1')
strictEqual(foo2, '2')
strictEqual(foo3, '3')

View File

@@ -0,0 +1,17 @@
import Hook from '../../index.js'
import { foo } from '../fixtures/re-export-star-external.mjs'
import { bar } from '../fixtures/sub-directory/re-export-star-external.mjs'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.endsWith('fixtures/re-export-star-external.mjs')) {
exports.foo = '1'
}
if (name.endsWith('fixtures/sub-directory/re-export-star-external.mjs')) {
exports.bar = '2'
}
})
strictEqual(foo, '1')
strictEqual(bar, '2')

23
node_modules/import-in-the-middle/test/hook/remove.mjs generated vendored Normal file
View File

@@ -0,0 +1,23 @@
// 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 Hook from '../../index.js'
import { strictEqual } from 'assert'
const hook = new Hook((exports, name) => {
if (name.match(/something\.m?js/)) {
exports.foo += 15
}
})
;(async () => {
const { foo: fooMjs } = await import('../fixtures/something.mjs')
hook.unhook()
const { foo: fooJs } = await import('../fixtures/something.js')
strictEqual(fooMjs, 57)
strictEqual(fooJs, 42)
})()

View File

@@ -0,0 +1,12 @@
import Hook from '../../index.js'
import { foo } from '../fixtures/require-root.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.endsWith('require-root.js')) {
strictEqual(exports.foo, 'something')
exports.foo += '-wrap'
}
})
strictEqual(foo, 'something-wrap')

View File

@@ -0,0 +1,11 @@
import { foo } from '../fixtures/specifier-external.js'
import Hook from '../../index.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.endsWith('fixtures/specifier-external.js')) {
exports.foo = 'bar2'
}
})
strictEqual(foo, 'bar2')

View File

@@ -0,0 +1,10 @@
import { foo } from '../fixtures/specifier.mjs'
import Hook from '../../index.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.endsWith('fixtures/specifier.mjs')) {
exports.foo = 1
}
})
strictEqual(foo, 1)

View File

@@ -0,0 +1,11 @@
import { foo } from '../fixtures/nested-folder/specifier.js'
import Hook from '../../index.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.endsWith('fixtures/nested-folder/specifier.js')) {
exports.foo = 1
}
})
strictEqual(foo, 1)

View File

@@ -0,0 +1,11 @@
import { foo } from '../fixtures/specifier-string.js'
import Hook from '../../index.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.endsWith('fixtures/specifier-string.js')) {
exports.foo = 1
}
})
strictEqual(foo, 1)

View File

@@ -0,0 +1,26 @@
// 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 { Hook } from '../../index.js'
import barMjs from '../fixtures/something.mjs'
import barJs from '../fixtures/something.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/something.mjs/)) {
const orig = exports.default
exports.default = function bar () {
return orig() + 15
}
}
if (name.match(/something.js/)) {
const orig = exports.default
return function bar () {
return orig() + 15
}
}
})
strictEqual(barMjs(), 57)
strictEqual(barJs(), 57)

View File

@@ -0,0 +1,15 @@
// 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 Hook from '../../index.js'
import { foo as fooMjs } from '../fixtures/something.mjs'
import { foo as fooJs } from '../fixtures/something.js'
import { strictEqual, fail } from 'assert'
Hook(() => {
fail('should not have been called at all')
})
strictEqual(fooMjs, 42)
strictEqual(fooJs, 42)

View File

@@ -0,0 +1,15 @@
import Hook from '../../index.js'
import { Report } from 'c8/index.js'
import path from 'path'
import { fileURLToPath } from 'url'
import { strictEqual } from 'assert'
const c8Dir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'node_modules', 'c8')
Hook(['c8'], { internals: true }, (exports, name, baseDir) => {
strictEqual(name, path.join('c8', 'index.js'))
strictEqual(baseDir, c8Dir)
exports.Report = () => 42
})
strictEqual(Report({}), 42)

View File

@@ -0,0 +1,15 @@
import Hook from '../../index.js'
import { Report } from 'c8/index.js'
import path from 'path'
import { fileURLToPath } from 'url'
import { strictEqual, notStrictEqual } from 'assert'
const c8Dir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'node_modules', 'c8')
Hook(['c8'], (exports, name, baseDir) => {
strictEqual(name, 'c8')
strictEqual(baseDir, c8Dir)
exports.Report = () => 42
})
notStrictEqual(Report({}), 42)

View File

@@ -0,0 +1,15 @@
import Hook from '../../index.js'
import { Report } from 'c8'
import path from 'path'
import { fileURLToPath } from 'url'
import { strictEqual } from 'assert'
const c8Dir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'node_modules', 'c8')
Hook(['c8'], (exports, name, baseDir) => {
strictEqual(name, 'c8')
strictEqual(baseDir, c8Dir)
exports.Report = () => 42
})
strictEqual(Report({}), 42)

View File

@@ -0,0 +1,34 @@
import { strictEqual } from 'assert'
import Hook from '../../index.js'
/* eslint-disable import/first */
import {
/* eslint-disable import/no-named-default */
default as bar,
foo,
aFunc,
baz
} from '../fixtures/bundle.mjs'
Hook((exports, name) => {
if (/bundle\.mjs/.test(name) === false) return
const bar = exports.default
exports.default = function wrappedBar () {
return bar() + '-wrapped'
}
const foo = exports.foo
exports.foo = function wrappedFoo () {
return foo() + '-wrapped'
}
const aFunc = exports.aFunc
exports.aFunc = function wrappedAFunc () {
return aFunc() + '-wrapped'
}
})
strictEqual(bar(), '42-wrapped')
strictEqual(foo(), 'foo-wrapped')
strictEqual(aFunc(), 'a-wrapped')
strictEqual(baz(), 'baz')

View File

@@ -0,0 +1,24 @@
// 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 Hook from '../../index.js'
import { foo as fooMjs } from '../fixtures/something.mjs'
import { foo as fooJs } from '../fixtures/something.js'
import { freemem } from 'os'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/something\.m?js/)) {
exports.foo += 15
}
if (name === 'os') {
Object.defineProperty(exports, 'freemem', {
value: () => 47
})
}
})
strictEqual(fooMjs, 57)
strictEqual(fooJs, 57)
strictEqual(freemem(), 47)

View File

@@ -0,0 +1,10 @@
import { format, parse } from 'date-fns'
import Hook from '../../index.js'
Hook((exports, name) => {
if (name === 'date-fns') {
//
}
})
console.assert(format, parse)

View File

@@ -0,0 +1,84 @@
// 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 Hook from '../../index.js'
import {
name1 as n1,
name2 as n2,
name3 as n3,
name4 as n4,
ClassName as cn,
generatorFunctionName as gfn,
name5 as n5,
bar as n6,
name7 as n7,
name8 as n8,
asyncFunctionName as afn,
asyncGeneratorFunctionName as agfn,
arrowFunction as arfn,
asyncArrowFunction as aarfn
, functionName
} from '../fixtures/export-types/declarations.mjs'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/declarations\.m?js/)) {
exports.name1 += 1
exports.name2 += 1
exports.name3 += 1
exports.name4 += 1
const orig = exports.functionName
exports.functionName = function () {
return orig() + 1
}
exports.ClassName.prototype.getFoo = function () {
return 2
}
const orig2 = exports.generatorFunctionName
exports.generatorFunctionName = function * () {
return orig2().next().value + 1
}
exports.name5 += 1
exports.bar += 1
exports.name7 += 1
exports.name8 += 1
const asyncOrig = exports.asyncFunctionName
exports.asyncFunctionName = async function () {
return await asyncOrig() + 1
}
const asyncOrig2 = exports.asyncGeneratorFunctionName
exports.asyncGeneratorFunctionName = async function * () {
for await (const value of asyncOrig2()) {
yield value + 1
}
}
const arrowOrig = exports.arrowFunction
exports.arrowFunction = () => {
return arrowOrig() + 1
}
const asyncArrowOrig = exports.asyncArrowFunction
exports.asyncArrowFunction = async () => {
return await asyncArrowOrig() + 1
}
}
})
strictEqual(n1, 2)
strictEqual(n2, 2)
strictEqual(n3, 2)
strictEqual(n4, 2)
strictEqual(functionName(), 2)
/* eslint-disable new-cap */
strictEqual(new cn().getFoo(), 2)
strictEqual(gfn().next().value, 2)
strictEqual(n5, 2)
strictEqual(n6, 2)
strictEqual(n7, 2)
strictEqual(n8, 2)
strictEqual(await afn(), 2)
for await (const value of agfn()) {
strictEqual(value, 2)
}
strictEqual(arfn(), 2)
strictEqual(await aarfn(), 2)

View File

@@ -0,0 +1,33 @@
import { fileURLToPath } from 'url'
import { join } from 'path'
import { strictEqual } from 'assert'
import Hook from '../../index.js'
const toWrap = join(fileURLToPath(import.meta.url), '..', '..', 'fixtures', 'foo.mjs')
Hook([toWrap], (exports) => {
const original = exports.foo
exports.foo = function foo () {
return original() + '-first'
}
})
Hook([toWrap], (exports) => {
const original = exports.foo
exports.foo = function foo () {
return original() + '-second'
}
})
Hook([toWrap], (exports) => {
const shouldNotExist = exports.default
exports = function () {
return shouldNotExist()
}
})
const imp = await import('../fixtures/foo.mjs')
strictEqual(imp.foo(), 'foo-first-second')
// This should not throw!
strictEqual(imp.default, undefined)

View File

@@ -0,0 +1,10 @@
import { strictEqual } from 'assert'
// We dynamically import a specific file that imports the
// native module for this platform and architecture.
//
// This way we know the file exists and the native module can
// be loaded.
const lib = await import(`../fixtures/native-modules/${process.platform}-${process.arch}.js`)
strictEqual(typeof lib.default.crc32, 'function')

View File

@@ -0,0 +1,16 @@
import * as lib from '@react-email/components'
import { Heading } from '@react-email/components'
import Hook from '../../index.js'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/@react-email\/components/)) {
exports.Heading = function wrappedHeading () {
return 'heading-wrapped'
}
}
})
strictEqual(typeof lib.Button, 'function')
strictEqual(lib.Heading(), 'heading-wrapped')
strictEqual(Heading(), 'heading-wrapped')

View File

@@ -0,0 +1,4 @@
import ui from '../fixtures/module-exports-cjs-shim.mjs'
import { notStrictEqual } from 'assert'
notStrictEqual(ui, undefined)

View File

@@ -0,0 +1,16 @@
import got, { Options } from 'got'
import { strictEqual } from 'assert'
import Hook from '../../index.js'
Hook((exports, name) => {
if (name === 'got' && 'Options' in exports) {
exports.Options = 'nothing'
}
})
strictEqual(typeof got, 'function')
strictEqual(typeof got.post, 'function')
strictEqual(typeof got.stream, 'function')
strictEqual(typeof got.extend, 'function')
strictEqual(Options, 'nothing')

View File

@@ -0,0 +1,5 @@
import * as lib from '../fixtures/invalid-identifier.js'
import { strictEqual } from 'assert'
strictEqual(typeof lib['one.two'], 'function')
strictEqual(typeof lib['unsigned short'], 'string')

View File

@@ -0,0 +1,15 @@
// 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 Hook from '../../index.js'
import jsonMjs from '../fixtures/json.mjs'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/json\.mjs/)) {
exports.default.data += '-dawg'
}
})
strictEqual(jsonMjs.data, 'dog-dawg')

View File

@@ -0,0 +1,16 @@
import OpenAI from 'openai'
import Hook from '../../index.js'
Hook((exports, name) => {
if (name === 'openai') {
console.assert(name, exports)
}
})
console.assert(OpenAI)
const openAI = new OpenAI({
apiKey: 'doesnt-matter'
})
console.assert(openAI)

View File

@@ -0,0 +1,26 @@
import { strictEqual } from 'assert'
import Hook from '../../index.js'
Hook((exports, name) => {
if (/got-alike\.mjs/.test(name) === false) return
const foo = exports.foo
exports.foo = foo + '-wrapped'
const renamedDefaultExport = exports.renamedDefaultExport
exports.renamedDefaultExport = function bazWrapped () {
return renamedDefaultExport() + '-wrapped'
}
})
/* eslint-disable import/no-named-default */
import {
default as Got,
foo,
renamedDefaultExport
} from '../fixtures/got-alike.mjs'
strictEqual(foo, '42-wrapped')
const got = new Got()
strictEqual(got.foo, 'foo')
strictEqual(renamedDefaultExport(), 'baz-wrapped')

View File

@@ -0,0 +1,15 @@
// 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 Hook from '../../index.js'
import jsonMjs from '../fixtures/json-attributes.mjs'
import { strictEqual } from 'assert'
Hook((exports, name) => {
if (name.match(/json-attributes\.mjs/)) {
exports.default.data += '-dawg'
}
})
strictEqual(jsonMjs.data, 'dog-dawg')

View File

@@ -0,0 +1,8 @@
import { strictEqual } from 'assert'
const mod = await import('../fixtures/something.mts')
strictEqual(mod.foo, 42)
strictEqual(typeof mod.bar, 'function')
strictEqual(mod.bar(), 42)
strictEqual(Object.keys(mod).length, 2)

View File

@@ -0,0 +1,8 @@
import { strictEqual } from 'assert'
// https://github.com/nodejs/import-in-the-middle/issues/139
import * as libServer from 'vue/server-renderer'
// https://github.com/nodejs/import-in-the-middle/issues/144
import * as lib from 'vue'
strictEqual(typeof libServer.renderToString, 'function')
strictEqual(typeof lib.ref, 'function')