2024-04-25 04:47:33 +03:00
|
|
|
// @ts-expect-error no typings
|
|
|
|
import { describe as _describe, it, beforeEach, afterEach, beforeAll, afterAll } from 'jsr:@std/testing/bdd'
|
|
|
|
// @ts-expect-error no typings
|
2024-04-25 05:25:56 +03:00
|
|
|
import * as vitestSpy from 'npm:@vitest/spy@1.4.0'
|
2024-04-25 04:47:33 +03:00
|
|
|
// @ts-expect-error no typings
|
|
|
|
import * as chai from 'npm:chai'
|
|
|
|
// @ts-expect-error no typings
|
2024-04-25 05:25:56 +03:00
|
|
|
import * as vitestExpect from 'npm:@vitest/expect@1.4.0'
|
2024-04-25 04:47:33 +03:00
|
|
|
import util from 'node:util'
|
2024-04-25 05:25:56 +03:00
|
|
|
import { setupChai, stubGlobal, unstubAllGlobals, waitFor } from './polyfills'
|
2024-04-25 04:47:33 +03:00
|
|
|
|
|
|
|
export { it, beforeEach, afterEach, beforeAll, afterAll }
|
|
|
|
|
|
|
|
setupChai(chai, vitestExpect)
|
|
|
|
|
2024-04-25 05:25:56 +03:00
|
|
|
// https://github.com/denoland/deno_std/issues/2213
|
2024-04-25 04:47:33 +03:00
|
|
|
Object.defineProperty(it, 'each', {
|
|
|
|
value: (items: any[][]) => (name: string, fn: Function) => {
|
|
|
|
return items.map((item) => {
|
|
|
|
return it(`${util.format(name, ...item)}`, () => fn(...item))
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2024-04-25 05:25:56 +03:00
|
|
|
// https://github.com/denoland/deno_std/issues/4634
|
2024-04-25 04:47:33 +03:00
|
|
|
export const describe = (...args) => {
|
|
|
|
const fn = args.find((arg) => typeof arg === 'function')
|
|
|
|
if (fn.toString().startsWith('async')) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return _describe(...args)
|
|
|
|
}
|
|
|
|
describe.skip = _describe.skip
|
|
|
|
describe.only = _describe.only
|
|
|
|
describe.ignore = _describe.ignore
|
|
|
|
|
|
|
|
export const expect = chai.expect
|
|
|
|
|
|
|
|
export const vi = {
|
|
|
|
...vitestSpy,
|
|
|
|
mocked: (fn: any) => fn,
|
|
|
|
stubGlobal,
|
|
|
|
unstubAllGlobals,
|
2024-04-25 05:25:56 +03:00
|
|
|
waitFor,
|
2024-04-25 04:47:33 +03:00
|
|
|
// todo use @sinonjs/fake-timers (see https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/integrations/mock/timers.ts)
|
|
|
|
...['setSystemTime', 'advanceTimersByTimeAsync', 'advanceTimersByTime', 'doMock'].reduce(
|
|
|
|
(acc, name) => ({
|
|
|
|
...acc,
|
|
|
|
[name]: () => {
|
|
|
|
throw new Error(name)
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
}
|