Skip to content

Commit 19c846e

Browse files
Merge branch 'main' into add-failing-test
2 parents af90140 + b444f95 commit 19c846e

File tree

28 files changed

+229
-62
lines changed

28 files changed

+229
-62
lines changed

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- uses: actions/setup-node@v4
1616
with:
17-
node-version: 20
17+
node-version: 24
1818
- run: npm install
1919
- run: npm run build --if-present
2020
- run: |

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414
with:
15-
node-version: 20
15+
node-version: 24
1616
- run: npm install
1717
- run: npm run lint

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- uses: actions/checkout@v4
2121
- uses: actions/setup-node@v4
2222
with:
23-
node-version: 20
23+
node-version: 24
2424
registry-url: https://npm.pkg.github.com/
2525
- name: Insert repository owner as scope into package name
2626
run: |

.github/workflows/test-pnpm.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: test-pnpm
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test-pnpm:
11+
runs-on: ${{ matrix.os }}
12+
timeout-minutes: 12
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
node-version: [22.x]
17+
os: [ubuntu-latest]
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- uses: pnpm/action-setup@v4
24+
with:
25+
version: 9
26+
- run: npm install
27+
- run: npm run build --if-present
28+
- run: npm run test-ci-pnpm

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
node-version: [18.x, 20.x, 22.x]
16+
node-version: [22.x, 24.x]
1717
os: [ubuntu-latest, windows-latest]
1818
steps:
1919
- uses: actions/checkout@v4

CHANGELOG.md

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

3+
* 2.7.3 _Sep.12.2025_
4+
* drop node version [18 and 20 from tests.](https://github.com/iambumblehead/esmock/pull/326)
5+
* increment some dependencies [and reduce audit warnings.](https://github.com/iambumblehead/esmock/pull/327)
6+
* restore [ava and all other disabled test-runner tests](https://github.com/iambumblehead/esmock/pull/328)
7+
* 2.7.2 _Sep.01.2025_
8+
* [increment resolvewithplus,](https://github.com/iambumblehead/esmock/pull/325) match [exact export paths,](https://github.com/iambumblehead/resolvewithplus/pull/71) thanks @matz3
9+
* 2.7.1 _Jul.01.2025_
10+
* [added node v24 to test matrix](https://github.com/iambumblehead/esmock/pull/324)
11+
* 2.7.0 _Jan.24.2025_
12+
* [update resolver](https://github.com/iambumblehead/esmock/pull/322) to correctly resolve openai package
13+
* [update typescript-eslint](https://github.com/iambumblehead/esmock/pull/323)
14+
* 2.6.9 _Oct.18.2024_
15+
* [added --glob option for rimraf](https://github.com/iambumblehead/esmock/pull/317) usage removing un-used sources
16+
* [added node v23 to test matrix](https://github.com/iambumblehead/esmock/pull/316)
17+
* [resolve v23-related error](https://github.com/iambumblehead/esmock/pull/316) when `module.exports` is exported
18+
* 2.6.8 _Oct.17.2024_
19+
* [added pnpm unit-test,](https://github.com/iambumblehead/esmock/pull/315) thanks @darcyrush
20+
* [resolve issue for pnpm](https://github.com/iambumblehead/esmock/pull/315) by escaping '+' char in regexp
21+
* [add log utility function](https://github.com/iambumblehead/esmock/pull/314) for debugging loader
22+
* [dropped ava and jest](https://github.com/iambumblehead/esmock/pull/314) from test sequence, node v22 --loader issues
323
* 2.6.7 _Jul.16.2024_
424
* [add swc tests and remove swc caution from README](https://github.com/iambumblehead/esmock/pull/309) thanks @Brooooooklyn
525
* [unpin node 22.1 at test CI](https://github.com/iambumblehead/esmock/pull/309) and use latest 22.x

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default [
1717
rules: {
1818
"@typescript-eslint/no-unused-expressions": 0,
1919
"@typescript-eslint/no-explicit-any": 0,
20+
"@typescript-eslint/no-unused-vars": 0,
2021
"comma-dangle": "off"
2122
}
2223
},
@@ -47,6 +48,7 @@ export default [
4748
"no-unused-vars": ["error", {
4849
"vars": "all",
4950
"args": "after-used",
51+
"varsIgnorePattern": "log",
5052
"ignoreRestSiblings": false
5153
}],
5254
"global-require": 0,

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "esmock",
33
"type": "module",
4-
"version": "2.6.7",
4+
"version": "2.7.3",
55
"license": "ISC",
66
"readmeFilename": "README.md",
77
"description": "provides native ESM import and globals mocking for unit tests",
@@ -60,27 +60,28 @@
6060
"node": ">=14.16.0"
6161
},
6262
"dependencies": {
63-
"resolvewithplus": "^2.1.5"
63+
"resolvewithplus": "^2.1.7"
6464
},
6565
"devDependencies": {
66-
"c8": "^10.1.2",
67-
"eslint": "^9.5.0",
68-
"eslint-plugin-markdown": "^5.0.0",
69-
"typescript-eslint": "^8.0.0-alpha.30",
70-
"@typescript-eslint/parser": "^8.0.0-alpha.30",
71-
"@typescript-eslint/eslint-plugin": "^8.0.0-alpha.30"
66+
"c8": "^10.1.3",
67+
"eslint": "^9.34.0",
68+
"eslint-plugin-markdown": "^5.1.0",
69+
"typescript-eslint": "^8.41.0",
70+
"@typescript-eslint/parser": "^8.41.0",
71+
"@typescript-eslint/eslint-plugin": "^8.41.0"
7272
},
7373
"scripts": {
7474
"test:install": "cd tests && npm run install:all",
7575
"test:all": "cd tests && npm run test:all",
7676
"test:all-ci": "cd tests && npm run test:all-ci",
7777
"test": "npm run test:all",
78+
"test-ci-pnpm": "cd tests && cd tests-pnpm && pnpm i && npm run test",
7879
"test-ci": "npm run test:install && npm run test:all-ci",
7980
"test-cover": "npm run test:install && c8 npm run test:all",
8081
"lint": "eslint .",
8182
"lint-fix": "eslint --fix .",
8283
"mini:pkg": "npm pkg delete scripts devDependencies dependencies",
83-
"mini:src": "cd src && npx rimraf \"!(esmock|esmockLoader).js\"",
84+
"mini:src": "cd src && npx rimraf --glob \"!(esmock|esmockLoader).js\"",
8485
"mini": "npm run mini:src && npm run mini:pkg",
8586
"prepublishOnly": "npm run lint && npm run test-ci && npm run mini"
8687
}

src/esmockLoader.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from 'node:fs/promises'
1+
import fs from 'node:fs'
22
import module from 'node:module'
33
import process from 'process'
44
import esmockErr from './esmockErr.js'
@@ -25,14 +25,23 @@ const isnotfoundRe = /isfound=false/
2525
const iscommonjsmoduleRe = /^(commonjs|module)$/
2626
const isstrict3 = /strict=3/
2727
const hashbangRe = /^(#![^\n]*\n)/
28+
29+
// escape '+' char, pnpm generates long pathnames serialized with these
30+
const moduleIdEsc = str =>
31+
str.indexOf('+') >= 0 ? str.replace(/(?!\\)\+/g, '\\+') : str
32+
2833
// returned regexp will match embedded moduleid w/ treeid
2934
const moduleIdReCreate = (moduleid, treeid) => new RegExp(
30-
`.*(${moduleid}(\\?${treeid}(?:(?!#-#).)*)).*`)
35+
`.*(${moduleIdEsc(moduleid)}(\\?${treeid}(?:(?!#-#).)*)).*`)
3136

3237
// node v12.0-v18.x, global
3338
const mockKeys = global.mockKeys = (global.mockKeys || {})
3439
const mockKeysSource = global.mockKeysSource = (global.mockKeysSource || {})
3540

41+
// use fs when logging from hooks, console.log async unpredictable
42+
const log = (...args) => (
43+
fs.writeSync(1, JSON.stringify(args, null, ' ').slice(2, -1)))
44+
3645
// node v20.0-v20.6
3746
const globalPreload = !module.register && (({ port }) => (
3847
port.addEventListener('message', ev => (
@@ -170,7 +179,7 @@ const load = async (url, context, nextLoad) => {
170179
const sourceIsNullLike = (
171180
nextLoadRes.source === null || nextLoadRes.source === undefined)
172181
const source = sourceIsNullLike
173-
? String(await fs.readFile(new URL(url)))
182+
? String(fs.readFileSync(new URL(url)))
174183
: String(nextLoadRes.source)
175184
const hbang = (source.match(hashbangRe) || [])[0] || ''
176185
const sourcesafe = hbang ? source.replace(hashbangRe, '') : source

src/esmockModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const isJSONExtnRe = /\.json$/i
2424

2525
// https://github.com/iambumblehead/esmock/issues/284
2626
// older applications may export names that are reserved in newer runtimes
27-
const reservedKeywordsFoundInWild = /(^|,)static($|,)/g
27+
const reservedKeywordsFoundInWild = /(^|,)(static|module\.exports)($|,)/g
2828

2929
// assigning the object to its own prototypal inheritor can error, eg
3030
// 'Cannot assign to read only property \'F_OK\' of object \'#<Object>\''

0 commit comments

Comments
 (0)