This commit is contained in:
Joseph Garrone 2020-05-14 00:47:15 +02:00
parent 224dc389eb
commit a55f9e86eb
14 changed files with 449 additions and 2 deletions

3
src/index.ts Normal file
View file

@ -0,0 +1,3 @@
export { myFunction } from "./myFunction";
export { myObject } from "./myObject";

2
src/myFunction.ts Normal file
View file

@ -0,0 +1,2 @@
export const myFunction = ()=> Promise.resolve(["a", "b", "c"]);

4
src/myObject.ts Normal file
View file

@ -0,0 +1,4 @@
import { toUpperCase } from "./tools/toUpperCase";
export const myObject= { "p": toUpperCase("foo") };

49
src/test/index.ts Normal file
View file

@ -0,0 +1,49 @@
//This will not run on deno, we need a separate index to run our tests.
import * as child_process from "child_process";
import * as path from "path";
import { Deferred } from "evt/dist/tools/Deferred";
(async () => {
if (!!process.env.FORK) {
process.once("unhandledRejection", error => { throw error; });
require(process.env.FORK);
return;
}
for (const name of [
"myFunction",
"myObject"
]) {
console.log(`Running: ${name}`);
const dExitCode = new Deferred<number>();
child_process.fork(
__filename,
undefined,
{ "env": { "FORK": path.join(__dirname, name) } }
)
.on("message", console.log)
.once("exit", code => dExitCode.resolve(code))
;
const exitCode = await dExitCode.pr;
if (exitCode !== 0) {
console.log(`${name} exited with error code: ${exitCode}`);
process.exit(exitCode);
}
console.log("\n");
}
})();

20
src/test/myFunction.ts Normal file
View file

@ -0,0 +1,20 @@
import { myFunction } from "..";
import { getPromiseAssertionApi } from "evt/dist/tools/testing/getPromiseAssertionApi";
const { mustResolve } = getPromiseAssertionApi({ "takeIntoAccountArraysOrdering": true});
(async () => {
await mustResolve({
"promise": myFunction(),
"expectedData": ["a", "b", "c"],
"delay": 0
});
console.log("PASS");
})();

17
src/test/myObject.ts Normal file
View file

@ -0,0 +1,17 @@
import { assert } from "evt/dist/tools/typeSafety";
import * as inDepth from "evt/dist/tools/inDepth";
import { myObject } from "..";
assert(
inDepth.same(
myObject,
{ "p": "FOO" }
)
);
console.log("PASS");

4
src/tools/toUpperCase.ts Normal file
View file

@ -0,0 +1,4 @@
export function toUpperCase(str: string): string{
return str.toUpperCase();
}