UNPKG

@augment-vir/test

Version:

A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.

44 lines (43 loc) 1.47 kB
import { isInsidePlaywrightTest, isRuntimeEnv, RuntimeEnv } from '@augment-vir/core'; const describes = isRuntimeEnv(RuntimeEnv.Node) ? isInsidePlaywrightTest() ? { playwright: await (async () => { const { test } = await import('@playwright/test'); return test.describe; })(), } : { node: (await import('node:test')).describe, } : { mocha: globalThis.describe, }; /** * A test suite declaration. This can be used in both web tests _and_ node tests, so you only have * import from a single place and learn a single interface. * * This should be passed a _noun_ (preferably a single word, when possible) of what is going to be * tested inside the test suite. Its callback should call `it` from this same package. * * Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and * [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test * runners. * * @category Test * @category Package : @augment-vir/test * @example * * ```ts * import {describe, it} from '@augment-vir/test'; * * describe(myFunction.name, () => { * it('does a thing', () => { * myFunction(); * }); * }); * ``` * * @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test) */ export const describe = describes.mocha || describes.playwright || describes.node;