Skip to content

Commit

Permalink
Merge pull request #81 from iambumblehead/add-tsm-demo-and-test
Browse files Browse the repository at this point in the history
adds tsm unit-test and README example
  • Loading branch information
iambumblehead authored Jul 23, 2022
2 parents 137383a + 6e53ec1 commit 1b150e6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```
Expand Down
2 changes: 2 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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*",
Expand Down
14 changes: 14 additions & 0 deletions tests/tests-tsm/esmock.node-tsm.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
19 changes: 19 additions & 0 deletions tests/tests-tsm/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions tests/tests-tsm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"esm": true,
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "ESNext",
"moduleResolution": "node"
}
}

0 comments on commit 1b150e6

Please sign in to comment.