MCPcopy Create free account
hub / github.com/porsager/postgres / test

Function test

deno/tests/test.js:19–61  ·  view source on GitHub ↗
(o, name, options, fn)

Source from the content-addressed store, hash-verified

17t.timeout = 5
18
19async function test(o, name, options, fn) {
20 typeof options !== 'object' && (fn = options, options = {})
21 const line = new Error().stack.split('\n')[3].match(':([0-9]+):')[1]
22
23 await 1
24
25 if (only && !o)
26 return
27
28 tests[line] = { fn, line, name }
29 promise = promise.then(() => Promise.race([
30 new Promise((resolve, reject) =>
31 fn.timer = setTimeout(() => reject('Timed out'), (options.timeout || t.timeout) * 1000)
32 ),
33 failed
34 ? (ignored++, ignore)
35 : fn()
36 ]))
37 .then(async x => {
38 clearTimeout(fn.timer)
39 if (x === ignore)
40 return
41
42 if (!Array.isArray(x))
43 throw new Error('Test should return result array')
44
45 const [expected, got] = await Promise.all(x)
46 if (expected !== got) {
47 failed = true
48 throw new Error(util.inspect(expected) + ' != ' + util.inspect(got))
49 }
50
51 tests[line].succeeded = true
52 process.stdout.write('✅')
53 })
54 .catch(err => {
55 tests[line].failed = failed = true
56 tests[line].error = err instanceof Error ? err : new Error(util.inspect(err))
57 })
58 .then(() => {
59 ++done === Object.keys(tests).length && exit()
60 })
61}
62
63function exit() {
64 let success = true

Callers 2

otFunction · 0.70
tFunction · 0.70

Calls 4

exitFunction · 0.70
writeMethod · 0.65
thenMethod · 0.45
catchMethod · 0.45

Tested by

no test coverage detected