DEV Community

loading...

Leaking resources in deno test

riviergrullon profile image Rivier Grullon ・1 min read

Recently I was working on the Trex project: Trex testing manually a new version that we gonna release but the fact to test all the functions manually to see that works it was tedious so I decide to see the test documentation of testing in Deno.

First I thought that the unit test was easy because I had not done a test before in Deno and I say How difficult could be do a test?

a few hours passed and the same error appeared that was

AssertionError: Test case is leaking resources.
Before: {
  "0": "stdin",
  "1": "stdout",
  "2": "stderr"
}
After: {
  "0": "stdin",
  "1": "stdout",
  "2": "stderr",
  "4": "child"
}

Make sure to close all open resource handles returned from Deno APIs before
finishing test case.
    at Object.assert ($deno$/util.ts:35:11)
    at Object.resourceSanitizer [as fn] ($deno$/testing.ts:78:5)
    at async TestRunner.[Symbol.asyncIterator] ($deno$/testing.ts:275:11)
    at async Object.runTests ($deno$/testing.ts:358:20)

there are two solutions to this:

  1. Close all the processes when the package was already install with .close()

Alt Text

  1. Reading the testing documentation found this to personalize the test function, by default this options comes to true the sanitizeResources, sanitizeOps
Deno.test({
    name: "Install Package #1",

    fn: async () =>{

        await delay(1000)
        const response = await installPakages(["i","--map","oak"])
        assertEquals(response, { oak: "https://deno.land/x/oak/mod.ts" })
    },
    sanitizeResources: false,
    sanitizeOps: false
});

Remember Guys read documentation :) I hope this post was helpful for u

Discussion (0)

Forem Open with the Forem app