Skip to content

Commit

Permalink
Merge pull request #213 from iambumblehead/restore-ava-tests-for-node…
Browse files Browse the repository at this point in the history
…-current

restore ava to node20 unit-tests
  • Loading branch information
iambumblehead authored Jul 22, 2023
2 parents 2850cea + 5af337e commit 81c3d33
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# changelog

* 2.3.2 _Jul.22.2023_
* [restore ava unit-test](https://github.com/iambumblehead/esmock/pull/213) process at node20 test pipeline
* [investigate problems](https://github.com/iambumblehead/esmock/issues/209) using tsx from @tommy-mitchell
* [reported the issue at the tsx project,](https://github.com/esbuild-kit/tsx/issues/264) where tsx fails import moduleIds with query params
* 2.3.1 _Jun.01.2023_
* [improve README example](https://github.com/iambumblehead/esmock/pull/207) for mocking global values
* use the word 'global' in the global values mocking example only, to improve clarity (hopefully)
Expand Down
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
"test-ts": "node --loader=ts-node/esm --loader=esmock --test *ts",
"test-jest": "NODE_OPTIONS=--loader=esmock jest"
},
"ava": [
"ava is incompatible w/ --loader and node v20 or greater",
"https://github.com/avajs/ava/issues/3195"
],
"jest": {
"runner": "jest-light-runner"
}
Expand Down Expand Up @@ -61,7 +57,7 @@ test('package, alias and local file mocks', async () => {
}
})

assert.strictEqual(cookup('breakfast'), '☕🥓🧂')
assert.equal(cookup('breakfast'), '☕🥓🧂')
})

test('full import tree mocks —third param', async () => {
Expand All @@ -70,25 +66,23 @@ test('full import tree mocks —third param', async () => {
fs: { readFileSync: () => 'returned to 🌲 every caller in the tree' }
})

assert.strictEqual(getFile(), 'returned to 🌲 every caller in the tree')
assert.equal(getFile(), 'returned to 🌲 every caller in the tree')
})

test('mock fetch, Date, setTimeout and any globals', async () => {
// https://github.com/iambumblehead/esmock/wiki#call-esmock-globals
const Users = await esmock('../Users.js', {
// nested esmock defines 'fetch' at req.js' import tree *only*
const { userCount } = await esmock('../Users.js', {
'../req.js': await esmock('../req.js', {
import: {
// define globals, such as 'fetch', using the import namespace
import: { // define globals like 'fetch' on the import namespace
fetch: async () => ({
status: 200,
json: async () => [["jim","😄"],["jen","😊"]]
json: async () => [['jim','😄'],['jen','😊']]
})
}
})
})

assert.deepEqual(await Users.count(), 2)
assert.deepEqual(await userCount(), 2)
})

test('mocks "await import()" using esmock.p', async () => {
Expand All @@ -98,7 +92,7 @@ test('mocks "await import()" using esmock.p', async () => {
})

// mock definition is returned from cache, when import is called
assert.strictEqual(await doAwaitImport('cfg🛠️'), 'cfg🛠️')
assert.equal(await doAwaitImport('cfg🛠️'), 'cfg🛠️')
// a bit more info are found in the wiki guide
})

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "esmock",
"type": "module",
"version": "2.3.1",
"version": "2.3.2",
"license": "ISC",
"readmeFilename": "README.md",
"description": "provides native ESM import and globals mocking for unit tests",
Expand Down
5 changes: 2 additions & 3 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"install:all": "node --version && npm install && npm-run-all install:test*",
"test:test-uvu": "cd tests-uvu && npm test",
"test:test-mocha": "cd tests-mocha && npm test",
"test:test-ava": "cd tests-ava && npm test",
"test:node19-tsm": " cd tests-tsm && npm test",
"test:node18-test-tsm": "npm run isnodenight || npm run test:node19-tsm",
"test:node18-test-node": "cd tests-node && npm test",
Expand All @@ -51,9 +52,7 @@
"test:node18-test-source-map": "cd tests-source-map && npm test",
"test:node18-test-no-loader": "cd tests-no-loader && npm test",
"test:node18:all": "npm run isnodelt18 || npm-run-all test:node18-test*",
"test:nodelt20-test-ava": "cd tests-ava && npm test",
"test:nodelt20:all": "npm run isnodegt19 || npm-run-all test:nodelt20-test*",
"test:all": "npm-run-all test:test* && npm run test:node18:all && npm run test:nodelt20:all",
"test:all": "npm-run-all test:test* && npm run test:node18:all",
"test:all-cover": "c8 --src=../src/* npm run test:all",
"test:all-ci": "npm run mini && npm run test:all"
}
Expand Down
7 changes: 5 additions & 2 deletions tests/tests-ava/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
"url": "https://github.com/iambumblehead/esmock.git"
},
"dependencies": {
"ava": "^5.2.0",
"ava": "^5.3.1",
"run-script-os": "^1.1.6",
"esmock": "file:..",
"sinon": "file:../node_modules/sinon",
"eslint": "file:../node_modules/eslint",
"form-urlencoded": "file:../node_modules/form-urlencoded",
"babelGeneratedDoubleDefault": "file:../local/babelGeneratedDoubleDefault"
},
"scripts": {
"test": "ava --node-arguments=\"--loader=esmock\""
"test:default": "NODE_OPTIONS=--loader=esmock ava",
"test:win32": "set \"NODE_OPTIONS=--loader=esmock\" && ava",
"test": "run-script-os"
}
}

0 comments on commit 81c3d33

Please sign in to comment.