Skip to content

Commit

Permalink
Merge pull request #84 from iambumblehead/add-jest-light-runner-example
Browse files Browse the repository at this point in the history
add jest-light-runner unit-test and README entry
  • Loading branch information
iambumblehead authored Jul 25, 2022
2 parents ee463e2 + c6ad429 commit c1612ca
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# changelog

* 1.8.6 _Jul.24.2022_
* adds jest-light-runner example and unit-tests
* 1.8.5 _Jul.23.2022_
* adds typescript and node-native runner tests [for windows CI](https://github.com/iambumblehead/esmock/pull/80)
* renames esmockLoader.mjs to esmockLoader.js
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
```
[![npm version](https://badge.fury.io/js/esmock.svg)](https://badge.fury.io/js/esmock) [![Build Status](https://github.com/iambumblehead/esmock/workflows/nodejs-ci/badge.svg)][2] [![install size](https://packagephobia.now.sh/badge?p=esmock)](https://packagephobia.now.sh/result?p=esmock) [![downloads](https://badgen.now.sh/npm/dm/esmock)](https://npmjs.org/package/esmock)

**esmock provides native ESM import mocking for unit tests.** Use examples below as a quick-start guide or use the [descriptive and friendly esmock guide here.][10]
**esmock provides native ESM import mocking for unit tests.** Use examples below as a quick-start guide, see the [descriptive and friendly esmock guide here,][10] or browse [esmock's test runner examples.][3]

[10]: https://github.com/iambumblehead/esmock/wiki
[0]: http://www.bumblehead.com "bumblehead"
[1]: https://github.com/iambumblehead/esmock/workflows/nodejs-ci/badge.svg "nodejs-ci pipeline"
[2]: https://github.com/iambumblehead/esmock "esmock"

[3]: https://github.com/iambumblehead/esmock/tree/master/tests "tests"


`esmock` is used with node's --loader
Expand All @@ -30,8 +30,12 @@
"test-ava": "NODE_OPTIONS=--loader=esmock ava",
"test-uvu": "NODE_OPTIONS=--loader=esmock uvu spec",
"test-tsm": "node --loader=tsm --loader=esmock --test *ts",
"test-ts-node": "node --loader=ts-node/esm --loader=esmock --test *ts"
}
"test-ts-node": "node --loader=ts-node/esm --loader=esmock --test *ts",
"test": "NODE_OPTIONS='--loader=esmock' jest"
},
"jest": {
"runner": "jest-light-runner"
},
}
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esmock",
"version": "1.8.5",
"version": "1.8.6",
"license": "ISC",
"readmeFilename": "README.md",
"description": "provides native ESM import mocking for unit tests",
Expand Down
2 changes: 2 additions & 0 deletions tests/local/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ export default () => {
export const wildexports = wildfileexports;

export const wild = wildfile;

export const pathbasenamewrap = n => basename(n);
2 changes: 2 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
"install:test-uvu": "cd tests-uvu && npm install",
"install:test-tsm": "cd tests-tsm && npm install",
"install:test-node": "cd tests-node && npm install",
"install:test-jest": "cd tests-jest && npm install",
"install:test-nodets": "cd tests-nodets && npm install",
"install:all": "npm install && npm-run-all install:test*",
"test:test-ava": "cd tests-ava && npm test",
"test:test-uvu": "cd tests-uvu && npm test",
"test:test-tsm": "npm run isnode18 && cd tests-tsm && npm test || true",
"test:test-node": "npm run isnode18 && cd tests-node && npm test || true",
"test:test-jest": "npm run isnode18 && cd tests-jest && npm test || true",
"test:test-nodets": "npm run isnode18 && cd tests-nodets && npm test || true",
"test:all": "npm-run-all test:test*",
"test:all-cover": "c8 --src=../src/* npm run test:all",
Expand Down
11 changes: 11 additions & 0 deletions tests/tests-jest/__tests__/esmock.node-jest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import esmock from 'esmock';

test('should mock modules when using jest', async () => {
const main = await esmock('../../local/main.js', {
path : {
basename : () => 'hellow'
}
});

expect(main.pathbasenamewrap()).toBe('hellow');
});
23 changes: 23 additions & 0 deletions tests/tests-jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "module",
"description": "esmock unit tests, tsm with node native runner",
"repository": {
"type": "git",
"url": "https://github.com/iambumblehead/esmock.git"
},
"dependencies": {
"jest": "^28.1.3",
"jest-light-runner": "0.2.2",
"esmock": "file:..",
"sinon": "file:../node_modules/sinon",
"eslint": "file:../node_modules/eslint",
"form-urlencoded": "file:../node_modules/form-urlencoded",
"babelGeneratedDoubleDefault": "file:../local/babelGeneratedDoubleDefault"
},
"jest": {
"runner": "jest-light-runner"
},
"scripts": {
"test": "NODE_OPTIONS='--loader=esmock' jest"
}
}

0 comments on commit c1612ca

Please sign in to comment.