Skip to content

Commit

Permalink
Merge pull request #155 from iambumblehead/add-jest-typescript-test
Browse files Browse the repository at this point in the history
add jest+typescript test
  • Loading branch information
iambumblehead authored Sep 20, 2022
2 parents 146f7d0 + bf4a0f3 commit 3ca10f6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
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"
}
}

0 comments on commit 3ca10f6

Please sign in to comment.