Skip to content

Add assert and test packages#11213

Merged
brophdawg11 merged 19 commits intomainfrom
brophdawg11/testing-1-assert-unit
Apr 2, 2026
Merged

Add assert and test packages#11213
brophdawg11 merged 19 commits intomainfrom
brophdawg11/testing-1-assert-unit

Conversation

@brophdawg11
Copy link
Copy Markdown
Contributor

@brophdawg11 brophdawg11 commented Mar 31, 2026

Adds 2 new packages for unit testing Remix applications: remix/assert and remix/test and updates all of the demos/ to use the new unit testing framework via the remix-test CLI.

Subsequent PRs to come for additional aspects:

  • Conversion of all packages/ unit tests to use remix-test
  • Adding in-browser and E2E testing support via playwright

@brophdawg11 brophdawg11 marked this pull request as draft March 31, 2026 17:12
@github-actions
Copy link
Copy Markdown
Contributor

Preview Build Available

A 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.

Comment on lines +27 to +58
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
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config values available to the user, also mirrored via CLI args

cleanups.length = 0
},
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 || []
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our describe/it block register test suites onto globalThis.__testSuites which is then picked up by the executor

onSectionStart(label: string): void
}

// ── Spec ─────────────────────────────────────────────────────────────────────
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We offer spec/dot/tap reporters out of the box

Comment thread scripts/generate-remix.ts
version: string
packageJsonPath: string
exports: ExportEntry[]
bins: BinEntry[]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate-remix needed to be updated to automatically detect and make sub-package binaries available

@brophdawg11 brophdawg11 marked this pull request as ready for review March 31, 2026 18:00
@brophdawg11 brophdawg11 requested a review from mjackson March 31, 2026 18:00
@brophdawg11 brophdawg11 force-pushed the brophdawg11/testing-1-assert-unit branch from 7edca9b to 396a999 Compare April 1, 2026 15:57
Comment thread demos/bookstore/remix-test.config.ts Outdated
export default {
// The bookstore tests operate on the same DB so running multiple tests in
// concurrent workers can sometimes cause test failures
concurrency: 1,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor tests to use an in memory db and go back to max concurrency

@brophdawg11 brophdawg11 merged commit f734a0f into main Apr 2, 2026
18 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/testing-1-assert-unit branch April 2, 2026 20:13
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

The preview branch preview/pr-11213 has been deleted now that this PR is merged/closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants