MCPcopy
hub / github.com/evanw/esbuild / test

Function test

scripts/deno-tests.js:17–72  ·  view source on GitHub ↗
(name, backends, fn)

Source from the content-addressed store, hash-verified

15Deno.mkdirSync(rootTestDir, { recursive: true })
16
17function test(name, backends, fn) {
18 // Note: Do not try to add a timeout for the tests below. It turns out that
19 // calling "setTimeout" from within "Deno.test" changes how Deno waits for
20 // promises in a way that masks problems that would otherwise occur. We want
21 // test coverage for the way that people will likely be using these API calls.
22 //
23 // Specifically tests that Deno would otherwise have failed with "error:
24 // Promise resolution is still pending but the event loop has already
25 // resolved" were being allowed to pass instead. See this issue for more
26 // information: https://github.com/evanw/esbuild/issues/3682
27
28 for (const backend of backends) {
29 switch (backend) {
30 case 'native':
31 Deno.test(name + '-native', async () => {
32 let testDir = path.join(rootTestDir, name + '-native')
33 await Deno.mkdir(testDir, { recursive: true })
34 try {
35 await fn({ esbuild: esbuildNative, testDir })
36 await Deno.remove(testDir, { recursive: true }).catch(() => null)
37 } finally {
38 await esbuildNative.stop()
39 }
40 })
41 break
42
43 case 'wasm-main':
44 Deno.test(name + '-wasm-main', async () => {
45 let testDir = path.join(rootTestDir, name + '-wasm-main')
46 await esbuildWASM.initialize({ wasmModule, worker: false })
47 await Deno.mkdir(testDir, { recursive: true })
48 try {
49 await fn({ esbuild: esbuildWASM, testDir })
50 await Deno.remove(testDir, { recursive: true }).catch(() => null)
51 } finally {
52 await esbuildWASM.stop()
53 }
54 })
55 break
56
57 case 'wasm-worker':
58 Deno.test(name + '-wasm-worker', async () => {
59 let testDir = path.join(rootTestDir, name + '-wasm-worker')
60 await esbuildWASM.initialize({ wasmModule, worker: true })
61 await Deno.mkdir(testDir, { recursive: true })
62 try {
63 await fn({ esbuild: esbuildWASM, testDir })
64 await Deno.remove(testDir, { recursive: true }).catch(() => null)
65 } finally {
66 await esbuildWASM.stop()
67 }
68 })
69 break
70 }
71 }
72}
73
74addEventListener("unload", (e) => {

Callers 6

runFunction · 0.70
verifyFunction · 0.70
runTestFunction · 0.70
runFunction · 0.70
deno-tests.jsFile · 0.70

Calls 2

joinMethod · 0.80
stopMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…