Skip to content

Commit 9be2a33

Browse files
Merge pull request #322 from iambumblehead/resolve-failing-openai-mock-test
resolve failing openai mock test
2 parents 5db199a + 37cbd16 commit 9be2a33

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# changelog
22

3+
* 2.7.0 _Jan.24.2025_
4+
* [update resolver](https://github.com/iambumblehead/esmock/pull/322) to correctly resolve openai package
35
* 2.6.9 _Oct.18.2024_
46
* [added --glob option for rimraf](https://github.com/iambumblehead/esmock/pull/317) usage removing un-used sources
57
* [added node v23 to test matrix](https://github.com/iambumblehead/esmock/pull/316)

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "esmock",
33
"type": "module",
4-
"version": "2.6.9",
4+
"version": "2.7.0",
55
"license": "ISC",
66
"readmeFilename": "README.md",
77
"description": "provides native ESM import and globals mocking for unit tests",
@@ -60,12 +60,12 @@
6060
"node": ">=14.16.0"
6161
},
6262
"dependencies": {
63-
"resolvewithplus": "^2.1.5"
63+
"resolvewithplus": "^2.1.6"
6464
},
6565
"devDependencies": {
66-
"c8": "^10.1.2",
67-
"eslint": "^9.13.0",
68-
"eslint-plugin-markdown": "^5.0.0",
66+
"c8": "^10.1.3",
67+
"eslint": "^9.19.0",
68+
"eslint-plugin-markdown": "^5.1.0",
6969
"typescript-eslint": "^8.0.0-alpha.30",
7070
"@typescript-eslint/parser": "^8.0.0-alpha.30",
7171
"@typescript-eslint/eslint-plugin": "^8.0.0-alpha.30"

tests/local/importsopenai.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import OpenAI from 'openai'
2+
3+
export const analyze = () => {
4+
const openai = new OpenAI({ apiKey: '111' })
5+
6+
return openai
7+
}

tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"dependencies": {
1818
"express": "^4.18.2",
19+
"openai": "^4.80.0",
1920
"@aws-sdk/client-s3": "^3.408.0",
2021
"babelGeneratedDoubleDefault": "file:./local/babelGeneratedDoubleDefault",
2122
"eslint": "^8.54.0",
@@ -52,7 +53,7 @@
5253
"test:test-mocha": "cd tests-mocha && npm test",
5354
"test-dropped:test-ava": "cd tests-ava && npm test",
5455
"test:test-tsx": "cd tests-tsx && npm test",
55-
"test:test-swc": "cd tests-swc && npm test",
56+
"test-dropped:test-swc": "cd tests-swc && npm test",
5657
"test:node19-tsm": " cd tests-tsm && npm test",
5758
"test:node18-test-tsm": "npm run isnodenight || npm run test:node19-tsm",
5859
"test:node18-test-tsx": "cd tests-tsx && npm run test",

tests/tests-node/esmock.node.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,15 @@ test('mocks express, exports disallowed keyword "static"', async () => {
622622
}
623623
}))
624624
})
625+
626+
test('mocks openai, busy package.json exports', async () => {
627+
const openai = await esmock('../local/importsopenai.js', import.meta.url, {
628+
openai: class {
629+
constructor () {
630+
this.istest = true
631+
}
632+
}
633+
})
634+
635+
assert.ok(openai.analyze().istest)
636+
})

tests/tests-swc/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"dependencies": {
99
"esmock": "file:..",
1010
"typescript": "^5.5.3",
11-
"@swc-node/register": "^1.10.8",
12-
"@swc/core": "^1.6.13"
11+
"@swc-node/register": "^1.10.9",
12+
"@swc/core": "^1.10.9"
1313
},
1414
"scripts": {
1515
"isloaderavailable": "node -e \"(([mj, mn]) => (+mj < 18 || (+mj === 20 && +mn < 6) || (+mj === 18 && +mn < 19)))(process.versions.node.split('.')) || process.exit(1)\"",

0 commit comments

Comments
 (0)