DenoDDeno
Powered by
v1rtlV
Denoβ€’3y agoβ€’
9 replies
v1rtl

error: BadResource: Bad resource ID

I'm writing tests for https://github.com/deno-libs/tinyhttp/pull/9.

import { describe, expect, it, run } from 'https://deno.land/x/tincan@1.0.1/mod.ts'
import { App } from '../../app.ts'

describe('Request properties', () => {
  it.only('should have default HTTP Request properties', async () => {
    const app = new App()
    app.get('/', (req, res) => {
      res.json({ url: req.url })
    })
    const listener = Deno.listen({ port: 8080, hostname: 'localhost' })

    setTimeout(() => {
      fetch(`http://localhost:8080`).then((res) => res.json()).then((json) => {
        expect(json).toEqual({ url: `http://localhost:8080/` }) 
      })
    }, 0)

    const conn = await listener.accept()
    const requests = Deno.serveHttp(conn)
    const { request, respondWith } = (await requests.nextRequest())!
    const response = await app.handler(request, conn)
    if (response) {
      respondWith(response)
      // Deno.close(conn.rid)
      
      listener.close()
    }
  })
})
import { describe, expect, it, run } from 'https://deno.land/x/tincan@1.0.1/mod.ts'
import { App } from '../../app.ts'

describe('Request properties', () => {
  it.only('should have default HTTP Request properties', async () => {
    const app = new App()
    app.get('/', (req, res) => {
      res.json({ url: req.url })
    })
    const listener = Deno.listen({ port: 8080, hostname: 'localhost' })

    setTimeout(() => {
      fetch(`http://localhost:8080`).then((res) => res.json()).then((json) => {
        expect(json).toEqual({ url: `http://localhost:8080/` }) 
      })
    }, 0)

    const conn = await listener.accept()
    const requests = Deno.serveHttp(conn)
    const { request, respondWith } = (await requests.nextRequest())!
    const response = await app.handler(request, conn)
    if (response) {
      respondWith(response)
      // Deno.close(conn.rid)
      
      listener.close()
    }
  })
})


When running this test I get either this:

Request properties > should have default HTTP Request properties => https://deno.land/x/tincan@1.0.1/src/runner.ts:166:10
error: BadResource: Bad resource ID
      Deno.close(conn.rid)
           ^
    at Object.close (ext:core/01_core.js:396:25)
    at ItNode.fn (file:///home/v1rtl/Coding/deno-libs/tinyhttp/tests/core/request.test.ts:29:12)
    at async wrappedFn (https://deno.land/x/tincan@1.0.1/src/runner.ts:141:9)
Request properties > should have default HTTP Request properties => https://deno.land/x/tincan@1.0.1/src/runner.ts:166:10
error: BadResource: Bad resource ID
      Deno.close(conn.rid)
           ^
    at Object.close (ext:core/01_core.js:396:25)
    at ItNode.fn (file:///home/v1rtl/Coding/deno-libs/tinyhttp/tests/core/request.test.ts:29:12)
    at async wrappedFn (https://deno.land/x/tincan@1.0.1/src/runner.ts:141:9)


or this, if I uncomment that line:

error: AssertionError: Test case is leaking 1 resource:
 - An inbound HTTP connection (rid 8) was accepted during the test, but not closed during the test. Close the inbound HTTP connection by calling `httpConn.close()`.
    at assert (ext:deno_web/00_infra.js:353:11)
    at resourceSanitizer (ext:cli/40_testing.js:414:5)
    at async Object.exitSanitizer [as fn] (ext:cli/40_testing.js:432:7)
error: AssertionError: Test case is leaking 1 resource:
 - An inbound HTTP connection (rid 8) was accepted during the test, but not closed during the test. Close the inbound HTTP connection by calling `httpConn.close()`.
    at assert (ext:deno_web/00_infra.js:353:11)
    at resourceSanitizer (ext:cli/40_testing.js:414:5)
    at async Object.exitSanitizer [as fn] (ext:cli/40_testing.js:432:7)
GitHub
Build software better, together
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 330 million projects.
Build software better, together
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Puppeteer: "BadResource: Bad resource ID" on Ubuntu
DNADDNA / help
3y ago
Bad resource ID ERROR
nekodendislikeNnekodendislike / help
14mo ago
Why Bad resource ID occurs?
jeieaJjeiea / help
3y ago
FsWatcher.close() error : BadResource
VulcanurVVulcanur / help
2y ago