Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add jest+typescript test #155

Merged
merged 6 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# changelog

* 2.0.2 _tbd_
* [simplifications,](https://github.com/iambumblehead/esmock/pull/153) slightly reducing install size
* [add jest+ts-node test example,](https://github.com/iambumblehead/esmock/pull/155) credit @liuxingbaoyu @cspotcode
* 2.0.1 _Sep.15.2022_
* [use newer, smaller resolvewithplus](https://github.com/iambumblehead/resolvewithplus/releases/tag/v1.0.1)
* [use shared moduleId not found error message](https://github.com/iambumblehead/esmock/pull/146)
Expand Down
2 changes: 2 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"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-jest-ts": "cd tests-jest-ts && npm install",
"install:test-source-map": "cd tests-source-map && npm install",
"install:test-no-loader": "cd tests-no-loader && npm install",
"install:test-nodets": "cd tests-nodets && npm install",
Expand All @@ -43,6 +44,7 @@
"test:node18-test-tsm": "cd tests-tsm && npm test",
"test:node18-test-node": "cd tests-node && npm test",
"test:node18-test-jest": "cd tests-jest && npm test",
"test:node18-test-jest-ts": "cd tests-jest-ts && npm test",
"test:node18-test-nodets": "cd tests-nodets && npm test",
"test:node18-test-source-map": "cd tests-source-map && npm test",
"test:node18-test-no-loader": "cd tests-no-loader && npm test",
Expand Down
11 changes: 11 additions & 0 deletions tests/tests-jest-ts/esmock.node-jest.test.ts
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')
})
27 changes: 27 additions & 0 deletions tests/tests-jest-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "module",
"description": "esmock unit tests, jest with jest-light-runner",
"repository": {
"type": "git",
"url": "https://github.com/iambumblehead/esmock.git"
},
"dependencies": {
"ts-node": "^10.9.1",
"jest": "^29.0.3",
"jest-light-runner": "0.4.0",
"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"
},
"jest": {
"runner": "jest-light-runner"
},
"scripts": {
"test:default": "NODE_OPTIONS=\"--loader=ts-node/esm --loader=esmock\" jest esmock.node-jest.test.ts",
"test:win32": "set \"NODE_OPTIONS=--loader=ts-node/esm --loader=esmock\" && jest esmock.node-jest.test.ts",
"test": "run-script-os"
}
}
11 changes: 11 additions & 0 deletions tests/tests-jest-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "ts-node/node16/tsconfig.json",
"ts-node": {
"transpileOnly": true
},
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "ESNext",
"moduleResolution": "node"
}
}