MCPcopy
hub / github.com/jestjs/jest / testCase

Function testCase

packages/pretty-format/__benchmarks__/test.js:27–56  ·  view source on GitHub ↗
(name, fn)

Source from the content-addressed store, hash-verified

25let TIMES_TO_RUN = 100_000;
26
27function testCase(name, fn) {
28 let result, error, time, total;
29
30 try {
31 result = fn();
32 } catch (thrownError) {
33 error = thrownError;
34 }
35
36 if (!error) {
37 const start = process.hrtime();
38
39 for (let i = 0; i < TIMES_TO_RUN; i++) {
40 fn();
41 }
42
43 const diff = process.hrtime(start);
44
45 total = diff[0] * 1e9 + diff[1];
46 time = Math.round(total / TIMES_TO_RUN);
47 }
48
49 return {
50 error,
51 name,
52 result,
53 time,
54 total,
55 };
56}
57
58function test(name, value, ignoreResult, prettyFormatOpts) {
59 const formatted = testCase('prettyFormat() ', () =>

Callers 1

testFunction · 0.85

Calls 1

fnFunction · 0.50

Tested by 1

testFunction · 0.68