Add assert and test packages#11213
Conversation
Preview Build AvailableA preview build has been created for this PR. You can install it using: pnpm install "remix-run/remix#preview/pr-11213&path:packages/remix"This preview build will be updated automatically as you push new commits. |
| export interface RemixTestConfig { | ||
| glob?: { | ||
| /** Glob pattern for all test files (--glob.test) */ | ||
| test?: string | ||
| } | ||
| /** Max number of concurrent test workers (--concurrency) */ | ||
| concurrency?: number | string | ||
| /** | ||
| * Coverage configuration. `true` enables with defaults; an object enables with settings; | ||
| * `false` disables. CLI `--coverage` flag overrides the boolean aspect. | ||
| */ | ||
| coverage?: | ||
| | boolean | ||
| | { | ||
| dir?: string | ||
| include?: string[] | ||
| exclude?: string[] | ||
| statements?: number | string | ||
| lines?: number | string | ||
| branches?: number | string | ||
| functions?: number | string | ||
| } | ||
| /** | ||
| * Path to a module that exports `setup` and/or `teardown` functions, | ||
| * called once before and after the test run respectively. (--setup) | ||
| */ | ||
| setup?: string | ||
| /** Test reporter (--reporter) */ | ||
| reporter?: string | ||
| /** Watch mode — re-run tests on file changes (--watch) */ | ||
| watch?: boolean | ||
| } |
There was a problem hiding this comment.
Config values available to the user, also mirrored via CLI args
| cleanups.length = 0 | ||
| }, | ||
| } | ||
| } |
There was a problem hiding this comment.
Context is passed to every test which helps with utils and automatic cleanup:
it('tests something', (t) => {
let fn = t.mock(() => 'mocked')
let spy = t.spy(console, 'log') // Automatically restored after test
t.after(() => { /* local test cleanup logic */ });
});| } | ||
|
|
||
| export async function runTests(options?: { coverage?: boolean }): Promise<TestResults> { | ||
| let suites = (globalThis as any).__testSuites || [] |
There was a problem hiding this comment.
The executor is the shared enviroment-agnostic test runner. It runs tests on globalThis.__testSuites which can be populated from node or in the browser
| } | ||
|
|
||
| // Expose for executor.ts which reads this global | ||
| ;(globalThis as any).__testSuites = rootSuites |
There was a problem hiding this comment.
our describe/it block register test suites onto globalThis.__testSuites which is then picked up by the executor
| onSectionStart(label: string): void | ||
| } | ||
|
|
||
| // ── Spec ───────────────────────────────────────────────────────────────────── |
There was a problem hiding this comment.
We offer spec/dot/tap reporters out of the box
| version: string | ||
| packageJsonPath: string | ||
| exports: ExportEntry[] | ||
| bins: BinEntry[] |
There was a problem hiding this comment.
generate-remix needed to be updated to automatically detect and make sub-package binaries available
7edca9b to
396a999
Compare
| export default { | ||
| // The bookstore tests operate on the same DB so running multiple tests in | ||
| // concurrent workers can sometimes cause test failures | ||
| concurrency: 1, |
There was a problem hiding this comment.
Refactor tests to use an in memory db and go back to max concurrency
|
The preview branch |
Adds 2 new packages for unit testing Remix applications:
remix/assertandremix/testand updates all of thedemos/to use the new unit testing framework via theremix-testCLI.Subsequent PRs to come for additional aspects:
remix-test