Created
March 12, 2021 17:43
-
-
Save mindon/4ef5daeac5950d99446a18819ce920aa to your computer and use it in GitHub Desktop.
A simple helper to test functions not-exported but with _ prefix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple helper to test functions not-exported but with _ prefix | |
const privateCases = async function (flpath: string, cases: Function) { | |
const decoder = new TextDecoder("utf-8"); | |
let body = decoder.decode(await Deno.readFile(flpath)); | |
body = body.replace(/\nfunction _/g, "\nexport function _"); | |
const tmppath = flpath.replace(/([^\/]+)$/, "~$1"), | |
encoder = new TextEncoder(); | |
await Deno.writeFile(tmppath, encoder.encode(body)); | |
cases(await import(tmppath)); | |
await Deno.remove(tmppath); | |
}; | |
// Usage example | |
await privateCases("./hello.ts", (m: any) => { | |
Deno.test("Hello not-exported _demo", () => { | |
const result = m._demo(); | |
// ... | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment