All files / testing / _testing / deno.ts

100.00% Branches 0/0
100.00% Lines 14/14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
 
x58
 
 
x58
x3320
x58
x58
x295
x58
x58
x300
x58
x58
x1655
x331
x58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 







































// Imports
import type { options, Promisable, runner } from "./common.ts"
import { format } from "./common.ts"

/** Deno test runner. */
export const test = Object.assign(function (name: string, fn: () => Promisable<void>, options?: options) {
  return globalThis.Deno.test({ name: format(name), fn, ...options })
}, {
  only: function (name: string, fn: () => Promisable<void>, options?: options) {
    return globalThis.Deno.test.only({ name: format(name), fn, ...options })
  },
  skip: function (name: string, fn: () => Promisable<void>, options?: options) {
    return globalThis.Deno.test.ignore({ name: format(name), fn, ...options })
  },
  todo: function (name: string, fn: () => Promisable<void>, options?: options) {
    return globalThis.Deno.test.ignore({ name: format(name), fn, ...options })
  },
}) as runner

/*
const original = { env: {} as NonNullable<typeof options["env"]> }
        try {
          if ((runtime === "deno") && options.env) {
            for (const [key, value] of Object.entries(options.env)) {
              if (Deno.env.has(key)) {
                original.env[key] = Deno.env.get(key)!
              }
              Deno.env.set(key, value)
            }
          }
          return testcase(runtime, filename, name, fn, (options as { __dryrun?: boolean })?.__dryrun)
        } finally {
          if ((runtime === "deno") && options.env) {
            for (const key of Object.keys(options.env)) {
              Deno.env.delete(key)
              if (original.env[key] !== undefined) {
                Deno.env.set(key, original.env[key])
              }
            }
          }
        }
          */