Skip to content

Commit

Permalink
Fix typescript tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fardjad committed Jul 18, 2022
1 parent 591cecf commit 73c6ac5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "c8 --check-coverage --lines 90 imhotap --runner test/runtest --files test/{hook,low-level,other}/*",
"test:ts": "node --test --experimental-specifier-resolution=node --require ts-node/register --loader ./hook.mjs --loader ts-node/esm test/typescript/*.test.mts",
"test:ts": "node --test --experimental-specifier-resolution=node --require ts-node/register --loader ./test/typescript/iitm-ts-node-loader.mjs test/typescript/*.test.mts",
"coverage": "c8 --reporter html imhotap --runner test/runtest --files test/{hook,low-level,other}/* && echo '\nNow open coverage/index.html\n'"
},
"repository": {
Expand Down
18 changes: 18 additions & 0 deletions test/typescript/iitm-ts-node-loader.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as iitm from "../../hook.mjs";
import * as tsNode from "ts-node/esm.mjs";

const makeNext = (loader, fnName, parentResolveOrLoad) => {
return (specifierOrUrl, context) => {
return loader[fnName](specifierOrUrl, context, parentResolveOrLoad);
};
};

export async function resolve(specifier, context, defaultResolve) {
const next = makeNext(tsNode, "resolve", defaultResolve);
return iitm.resolve(specifier, context, next);
}

export async function load(url, context, defaultLoad) {
let next = makeNext(tsNode, "load", defaultLoad);
return iitm.load(url, context, next);
}
File renamed without changes.
6 changes: 3 additions & 3 deletions test/typescript/ts-node.test.mts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import assert from "node:assert/strict";
import test from "node:test";
import { addHook } from "../../index.js";
import { sayHi } from "./say-hi.js";
import { sayHi } from "./say-hi.mjs";

addHook((url, exported) => {
if (url.toLowerCase().endsWith('say-hi.ts')) {
exported.sayHi = () => 'Hooked';
if (url.toLowerCase().endsWith("say-hi.mts")) {
exported.sayHi = () => "Hooked";
}
});

Expand Down

0 comments on commit 73c6ac5

Please sign in to comment.