-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathit.ts
27 lines (22 loc) · 767 Bytes
/
it.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2021-Present the Unitest authors. All rights reserved. MIT license.
// This module is browser compatible.
import { gray, green, red } from "../deps.ts";
const START = "START";
const END = "END";
const TEST = "TEST";
/** Compat for deno.test */
function it(name: string, fn: () => void | (() => Promise<void>)) {
performance.mark(START);
try {
fn();
performance.mark(END);
const { duration } = performance.measure(TEST, START, END);
console.log(`test ${name} ... ${green("ok")} ${gray(`(${duration}ms)`)}`);
} catch (e) {
performance.mark(END);
const { duration } = performance.measure(TEST, START, END);
console.log(`test ${name} ... ${red("FAILED")} ${gray(`(${duration}ms)`)}`);
throw e;
}
}
export { it };