diff --git a/README.md b/README.md index cef7665e..dc9fb9b0 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,12 @@ "type": "module", "scripts": { "test": "node --loader=esmock --test", + "test-mocha": "mocha --loader=esmock", "test-tap": "NODE_OPTIONS=--loader=esmock tap", - "test-uvu": "NODE_OPTIONS=--loader=esmock uvu spec", "test-ava": "NODE_OPTIONS=--loader=esmock ava", - "test-mocha": "mocha --loader=esmock", - "test-ts": "node --loader=ts-node/esm --loader=esmock --test *ts" + "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" } } ``` diff --git a/tests/package.json b/tests/package.json index 32cc9cd0..adfe9b72 100644 --- a/tests/package.json +++ b/tests/package.json @@ -24,11 +24,13 @@ "install:esmock": "cd .. && npm install", "install:test-ava": "cd tests-ava && npm install", "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-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-nodets": "npm run isnode18 && cd tests-nodets && npm test || true", "test:all": "npm-run-all test:test*", diff --git a/tests/tests-tsm/esmock.node-tsm.test.ts b/tests/tests-tsm/esmock.node-tsm.test.ts new file mode 100644 index 00000000..4c938782 --- /dev/null +++ b/tests/tests-tsm/esmock.node-tsm.test.ts @@ -0,0 +1,14 @@ +import test from 'node:test'; +import assert from 'assert'; +import esmock from 'esmock'; + +test('should mock ts when using node-ts', { only : true }, async () => { + const main = await esmock('../local/main.ts', { + path: { + basename: () => 'hellow' + } + }); + + assert.strictEqual( main.pathbasenamewrap(), 'hellow' ); + assert.ok(true); +}); diff --git a/tests/tests-tsm/package.json b/tests/tests-tsm/package.json new file mode 100644 index 00000000..ce105036 --- /dev/null +++ b/tests/tests-tsm/package.json @@ -0,0 +1,19 @@ +{ + "type": "module", + "description": "esmock unit tests, tsm with node native runner", + "repository": { + "type": "git", + "url": "https://github.com/iambumblehead/esmock.git" + }, + "dependencies": { + "tsm": "^2.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" + }, + "scripts": { + "test": "node --loader=tsm --loader=esmock --test *test.ts" + } +} diff --git a/tests/tests-tsm/tsconfig.json b/tests/tests-tsm/tsconfig.json new file mode 100644 index 00000000..5b17f4eb --- /dev/null +++ b/tests/tests-tsm/tsconfig.json @@ -0,0 +1,8 @@ +{ + "esm": true, + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "module": "ESNext", + "moduleResolution": "node" + } +}