evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.98k stars 1.14k forks source link

With `await esbuild.stop()`, deno test still detect resource leaks #3896

Open loynoir opened 1 month ago

loynoir commented 1 month ago

bug

With await esbuild.stop(), deno test still detect resource leaks

reproduce

/tmp/reproduce/x.ts

import * as esbuild from 'npm:esbuild@0.23.1'

const __filename = '/tmp/reproduce/x.ts'

Deno.test('a', async () => {
  const result = await esbuild.transform('const test: boolean = true', { loader: 'ts' })
  let _ = result

  await esbuild.stop()
})

Deno.test('b', async () => {
  const result = await esbuild.build({
    write: false,
    platform: 'node',
    format: 'esm',
    bundle: true,
    entryPoints: [__filename],
    plugins: [
      {
        name: 'hello-world-plugin',
        setup(build) {
          build.onResolve({ filter: /.*/ }, (args) => {
            if (args.path === __filename) {
              return null
            }

            return { external: true }
          })
        }
      }
    ]
  })
  let _ = result

  await esbuild.stop()
})

actual

$ deno test -A --filter a ./x.ts 
running 1 test from ./x.ts
a ... ok (12ms)

ok | 1 passed | 0 failed | 1 filtered out (13ms)
$ deno test -A --filter b ./x.ts 
running 1 test from ./x.ts
b ... ok (14ms)

ok | 1 passed | 0 failed | 1 filtered out (15ms)
$ deno test -A ./x.ts 
running 2 tests from ./x.ts
a ... ok (11ms)
b ... FAILED (6ms)

 ERRORS 

b => ./x.ts:12:6
error: Leaks detected:
  - A child process was started during the test, but not closed during the test. Close the child process by calling `proc.kill()` or `proc.close()`.
  - An async operation to wait for a subprocess to exit was started in this test, but never completed. This is often caused by not awaiting the result of a `Deno.Process#status` call.
To get more details where leaks occurred, run again with the --trace-leaks flag.

 FAILURES 

b => ./x.ts:12:6

FAILED | 1 passed | 1 failed (19ms)

error: Test failed

expected

With await esbuild.stop(), deno test not detect resource leaks.

env

deno 1.46.0

evanw commented 6 days ago

I'm not sure what's up with Deno here but you're trying to use esbuild's npm library with Deno, not esbuild's Deno library with Deno. I suggest using esbuild's Deno library instead of esbuild's npm library as it's meant for use with Deno:

-import * as esbuild from 'npm:esbuild@0.23.1'
+import * as esbuild from 'https://deno.land/x/esbuild@v0.23.1/mod.js'

I don't consider behavior of esbuild's npm library that doesn't work well with Deno's npm compatibility layer to be a problem with esbuild as esbuild's npm library is meant for npm, not for Deno.