@remix-run/test 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +430 -2
  3. package/dist/app/client/entry.d.ts +2 -0
  4. package/dist/app/client/entry.d.ts.map +1 -0
  5. package/dist/app/client/entry.js +324 -0
  6. package/dist/app/client/iframe.d.ts +2 -0
  7. package/dist/app/client/iframe.d.ts.map +1 -0
  8. package/dist/app/client/iframe.js +22 -0
  9. package/dist/app/server.d.ts +6 -0
  10. package/dist/app/server.d.ts.map +1 -0
  11. package/dist/app/server.js +303 -0
  12. package/dist/cli-entry.d.ts +3 -0
  13. package/dist/cli-entry.d.ts.map +1 -0
  14. package/dist/cli-entry.js +14 -0
  15. package/dist/cli.d.ts +8 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +305 -0
  18. package/dist/index.d.ts +6 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +2 -0
  21. package/dist/lib/colors.d.ts +2 -0
  22. package/dist/lib/colors.d.ts.map +1 -0
  23. package/dist/lib/colors.js +2 -0
  24. package/dist/lib/config.d.ts +91 -0
  25. package/dist/lib/config.d.ts.map +1 -0
  26. package/dist/lib/config.js +255 -0
  27. package/dist/lib/context.d.ts +93 -0
  28. package/dist/lib/context.d.ts.map +1 -0
  29. package/dist/lib/context.js +65 -0
  30. package/dist/lib/coverage-loader.d.ts +16 -0
  31. package/dist/lib/coverage-loader.d.ts.map +1 -0
  32. package/dist/lib/coverage-loader.js +20 -0
  33. package/dist/lib/coverage.d.ts +28 -0
  34. package/dist/lib/coverage.d.ts.map +1 -0
  35. package/dist/lib/coverage.js +212 -0
  36. package/dist/lib/executor.d.ts +4 -0
  37. package/dist/lib/executor.d.ts.map +1 -0
  38. package/dist/lib/executor.js +128 -0
  39. package/dist/lib/fake-timers.d.ts +6 -0
  40. package/dist/lib/fake-timers.d.ts.map +1 -0
  41. package/dist/lib/fake-timers.js +45 -0
  42. package/dist/lib/framework.d.ts +107 -0
  43. package/dist/lib/framework.d.ts.map +1 -0
  44. package/dist/lib/framework.js +198 -0
  45. package/dist/lib/import-module.d.ts +2 -0
  46. package/dist/lib/import-module.d.ts.map +1 -0
  47. package/dist/lib/import-module.js +29 -0
  48. package/dist/lib/mock.d.ts +52 -0
  49. package/dist/lib/mock.d.ts.map +1 -0
  50. package/dist/lib/mock.js +61 -0
  51. package/dist/lib/normalize.d.ts +2 -0
  52. package/dist/lib/normalize.d.ts.map +1 -0
  53. package/dist/lib/normalize.js +18 -0
  54. package/dist/lib/playwright.d.ts +15 -0
  55. package/dist/lib/playwright.d.ts.map +1 -0
  56. package/dist/lib/playwright.js +81 -0
  57. package/dist/lib/reporters/dot.d.ts +9 -0
  58. package/dist/lib/reporters/dot.d.ts.map +1 -0
  59. package/dist/lib/reporters/dot.js +56 -0
  60. package/dist/lib/reporters/files.d.ts +9 -0
  61. package/dist/lib/reporters/files.d.ts.map +1 -0
  62. package/dist/lib/reporters/files.js +71 -0
  63. package/dist/lib/reporters/index.d.ts +13 -0
  64. package/dist/lib/reporters/index.d.ts.map +1 -0
  65. package/dist/lib/reporters/index.js +18 -0
  66. package/dist/lib/reporters/results.d.ts +30 -0
  67. package/dist/lib/reporters/results.d.ts.map +1 -0
  68. package/dist/lib/reporters/results.js +1 -0
  69. package/dist/lib/reporters/spec.d.ts +9 -0
  70. package/dist/lib/reporters/spec.d.ts.map +1 -0
  71. package/dist/lib/reporters/spec.js +153 -0
  72. package/dist/lib/reporters/tap.d.ts +9 -0
  73. package/dist/lib/reporters/tap.d.ts.map +1 -0
  74. package/dist/lib/reporters/tap.js +54 -0
  75. package/dist/lib/runner-browser.d.ts +21 -0
  76. package/dist/lib/runner-browser.d.ts.map +1 -0
  77. package/dist/lib/runner-browser.js +117 -0
  78. package/dist/lib/runner.d.ts +14 -0
  79. package/dist/lib/runner.d.ts.map +1 -0
  80. package/dist/lib/runner.js +118 -0
  81. package/dist/lib/runtime.d.ts +2 -0
  82. package/dist/lib/runtime.d.ts.map +1 -0
  83. package/dist/lib/runtime.js +2 -0
  84. package/dist/lib/ts-transform.d.ts +4 -0
  85. package/dist/lib/ts-transform.d.ts.map +1 -0
  86. package/dist/lib/ts-transform.js +29 -0
  87. package/dist/lib/watcher.d.ts +5 -0
  88. package/dist/lib/watcher.d.ts.map +1 -0
  89. package/dist/lib/watcher.js +39 -0
  90. package/dist/lib/worker-e2e.d.ts +2 -0
  91. package/dist/lib/worker-e2e.d.ts.map +1 -0
  92. package/dist/lib/worker-e2e.js +49 -0
  93. package/dist/lib/worker.d.ts +2 -0
  94. package/dist/lib/worker.d.ts.map +1 -0
  95. package/dist/lib/worker.js +57 -0
  96. package/dist/test/coverage/fixture.d.ts +5 -0
  97. package/dist/test/coverage/fixture.d.ts.map +1 -0
  98. package/dist/test/coverage/fixture.js +32 -0
  99. package/dist/test/coverage/test-browser.d.ts +2 -0
  100. package/dist/test/coverage/test-browser.d.ts.map +1 -0
  101. package/dist/test/coverage/test-browser.js +24 -0
  102. package/dist/test/coverage/test-e2e.d.ts +2 -0
  103. package/dist/test/coverage/test-e2e.d.ts.map +1 -0
  104. package/dist/test/coverage/test-e2e.js +60 -0
  105. package/dist/test/coverage/test-unit.d.ts +2 -0
  106. package/dist/test/coverage/test-unit.d.ts.map +1 -0
  107. package/dist/test/coverage/test-unit.js +27 -0
  108. package/dist/test/framework.test.browser.d.ts +2 -0
  109. package/dist/test/framework.test.browser.d.ts.map +1 -0
  110. package/dist/test/framework.test.browser.js +107 -0
  111. package/dist/test/framework.test.e2e.d.ts +2 -0
  112. package/dist/test/framework.test.e2e.d.ts.map +1 -0
  113. package/dist/test/framework.test.e2e.js +34 -0
  114. package/package.json +79 -5
  115. package/src/app/client/entry.ts +353 -0
  116. package/src/app/client/iframe.ts +18 -0
  117. package/src/app/server.ts +336 -0
  118. package/src/cli-entry.ts +15 -0
  119. package/src/cli.ts +384 -0
  120. package/src/index.ts +16 -0
  121. package/src/lib/colors.ts +3 -0
  122. package/src/lib/config.ts +377 -0
  123. package/src/lib/context.ts +168 -0
  124. package/src/lib/coverage-loader.ts +31 -0
  125. package/src/lib/coverage.ts +320 -0
  126. package/src/lib/executor.ts +145 -0
  127. package/src/lib/fake-timers.ts +64 -0
  128. package/src/lib/framework.ts +251 -0
  129. package/src/lib/import-module.ts +29 -0
  130. package/src/lib/mock.ts +89 -0
  131. package/src/lib/normalize.ts +22 -0
  132. package/src/lib/playwright.ts +100 -0
  133. package/src/lib/reporters/dot.ts +58 -0
  134. package/src/lib/reporters/files.ts +77 -0
  135. package/src/lib/reporters/index.ts +27 -0
  136. package/src/lib/reporters/results.ts +29 -0
  137. package/src/lib/reporters/spec.ts +174 -0
  138. package/src/lib/reporters/tap.ts +58 -0
  139. package/src/lib/runner-browser.ts +165 -0
  140. package/src/lib/runner.ts +189 -0
  141. package/src/lib/runtime.ts +2 -0
  142. package/src/lib/ts-transform.ts +36 -0
  143. package/src/lib/watcher.ts +46 -0
  144. package/src/lib/worker-e2e.ts +54 -0
  145. package/src/lib/worker.ts +50 -0
  146. package/src/test/coverage/fixture.ts +34 -0
  147. package/src/test/coverage/test-browser.ts +29 -0
  148. package/src/test/coverage/test-e2e.ts +70 -0
  149. package/src/test/coverage/test-unit.ts +32 -0
  150. package/tsconfig.json +16 -0
@@ -0,0 +1,54 @@
1
+ import { workerData, parentPort } from 'node:worker_threads'
2
+ import { runTests } from './executor.ts'
3
+ import { importModule } from './import-module.ts'
4
+ import {
5
+ getBrowserLauncher,
6
+ getPlaywrightLaunchOptions,
7
+ getPlaywrightPageOptions,
8
+ } from './playwright.ts'
9
+ import type { TestResults } from './reporters/results.ts'
10
+
11
+ try {
12
+ await importModule(workerData.file, import.meta)
13
+
14
+ let launcher = await getBrowserLauncher(workerData.playwrightUseOpts)
15
+ let opts = getPlaywrightLaunchOptions(workerData.playwrightUseOpts)
16
+ let browser = await launcher.launch(opts)
17
+ try {
18
+ let results = await runTests({
19
+ browser,
20
+ open: workerData.open,
21
+ playwrightPageOptions: getPlaywrightPageOptions(workerData.playwrightUseOpts),
22
+ coverage: workerData.coverage,
23
+ })
24
+ parentPort!.postMessage(results)
25
+ if (workerData.open) {
26
+ console.log('\nBrowser is open. Press Ctrl+C to close.')
27
+ await new Promise<void>((resolve) => browser.on('disconnected', () => resolve()))
28
+ }
29
+ } finally {
30
+ await browser.close()
31
+ }
32
+ process.exit(0)
33
+ } catch (e) {
34
+ let results: TestResults = {
35
+ passed: 0,
36
+ failed: 1,
37
+ skipped: 0,
38
+ todo: 0,
39
+ tests: [
40
+ {
41
+ name: '',
42
+ suiteName: '',
43
+ status: 'failed',
44
+ duration: 0,
45
+ error: {
46
+ message: e instanceof Error ? e.message : String(e),
47
+ stack: e instanceof Error ? e.stack : undefined,
48
+ },
49
+ },
50
+ ],
51
+ }
52
+ parentPort!.postMessage(results)
53
+ process.exit(0)
54
+ }
@@ -0,0 +1,50 @@
1
+ import * as mod from 'node:module'
2
+ import * as path from 'node:path'
3
+ import { parentPort, workerData } from 'node:worker_threads'
4
+ import { runTests } from './executor.ts'
5
+ import { importModule } from './import-module.ts'
6
+ import type { TestResults } from './reporters/results.ts'
7
+ import { IS_BUN } from './runtime.ts'
8
+ import { IS_RUNNING_FROM_SRC } from './config.ts'
9
+
10
+ try {
11
+ // When coverage is enabled in Node, we use a coverage-friendly TypeScript loader which
12
+ // replaces tsx's minified transformation with a non-minified esbuild transform
13
+ // so V8 coverage byte offsets align with readable source lines. This hook runs
14
+ // before the inherited tsx hook (hooks are LIFO), so it intercepts .ts imports and
15
+ // short-circuits before tsx transforms them.
16
+ if (workerData.coverage && !IS_BUN) {
17
+ // Ensure we load the right file whether we're running in the monorepo (TS) or
18
+ // from a published package (JS)
19
+ let ext = IS_RUNNING_FROM_SRC ? '.ts' : '.js'
20
+ mod.register(new URL(`./coverage-loader${ext}`, import.meta.url), import.meta.url)
21
+ await import(workerData.file)
22
+ } else {
23
+ await importModule(workerData.file, import.meta)
24
+ }
25
+
26
+ let results = await runTests()
27
+ parentPort!.postMessage(results)
28
+ process.exit(0)
29
+ } catch (e) {
30
+ let results: TestResults = {
31
+ passed: 0,
32
+ failed: 1,
33
+ skipped: 0,
34
+ todo: 0,
35
+ tests: [
36
+ {
37
+ name: '',
38
+ suiteName: '',
39
+ status: 'failed',
40
+ duration: 0,
41
+ error: {
42
+ message: e instanceof Error ? e.message : String(e),
43
+ stack: e instanceof Error ? e.stack : undefined,
44
+ },
45
+ },
46
+ ],
47
+ }
48
+ parentPort!.postMessage(results)
49
+ process.exit(0)
50
+ }
@@ -0,0 +1,34 @@
1
+ // This file exists solely to validate coverage accuracy.
2
+ // Each function has a known expected coverage profile based on
3
+ // which paths the associated tests exercise.
4
+
5
+ // Fully covered — both statements and the single branch
6
+ export function add(a: number, b: number): number {
7
+ return a + b
8
+ }
9
+
10
+ // Partially covered — only the `n > 0` branch is tested
11
+ export function classify(n: number): string {
12
+ if (n > 0) {
13
+ return 'positive'
14
+ } else if (n < 0) {
15
+ return 'negative'
16
+ } else {
17
+ return 'zero'
18
+ }
19
+ }
20
+
21
+ // Never called — 0% across the board
22
+ export function uncalledFunction(): string {
23
+ let result = 'never'
24
+ result += ' reached'
25
+ return result
26
+ }
27
+
28
+ // Partially covered — only the truthy `name` branch is tested
29
+ export function greet(name?: string): string {
30
+ if (name) {
31
+ return `Hello, ${name}!`
32
+ }
33
+ return 'Hello, stranger!'
34
+ }
@@ -0,0 +1,29 @@
1
+ import * as assert from '@remix-run/assert'
2
+ import { describe, it } from '../../lib/framework.ts'
3
+ import { add, classify, greet } from './fixture.ts'
4
+
5
+ // Expected coverage for coverage-fixture.ts (same as the server/e2e fixture
6
+ // tests):
7
+ //
8
+ // add — 100% functions, statements, lines, branches
9
+ // classify — function covered, but only the `n > 0` branch is hit
10
+ // (the `n < 0` and `else` branches are uncovered)
11
+ // uncalledFunction — 0% across the board (never imported)
12
+ // greet — function covered, but only the truthy `name` branch is hit
13
+ // (the fallback `Hello, stranger!` line is uncovered)
14
+
15
+ describe('browser coverage fixture', () => {
16
+ it('exercises some but not all code paths in the browser', () => {
17
+ assert.equal(add(2, 3), 5)
18
+ assert.equal(add(-1, 1), 0)
19
+
20
+ assert.equal(classify(42), 'positive')
21
+ assert.equal(classify(1), 'positive')
22
+ // deliberately NOT testing classify(-1) or classify(0)
23
+
24
+ assert.equal(greet('World'), 'Hello, World!')
25
+ // deliberately NOT testing greet() without an argument
26
+
27
+ // deliberately NOT importing or calling uncalledFunction
28
+ })
29
+ })
@@ -0,0 +1,70 @@
1
+ import * as assert from '@remix-run/assert'
2
+ import { createTestServer } from '@remix-run/node-fetch-server/test'
3
+ import * as fsp from 'node:fs/promises'
4
+ import * as path from 'node:path'
5
+ import { describe, it } from '../../lib/framework.ts'
6
+ import { transformTypeScript } from '../../lib/ts-transform.ts'
7
+
8
+ // Expected coverage for coverage/fixture.ts (same as the server fixture test):
9
+ //
10
+ // add — 100% functions, statements, lines, branches
11
+ // classify — function covered, but only the `n > 0` branch is hit
12
+ // uncalledFunction — 0% across the board (never called)
13
+ // greet — function covered, but only the truthy `name` branch is hit
14
+
15
+ describe('e2e coverage fixture', () => {
16
+ it('exercises some but not all code paths in the browser', async (t) => {
17
+ // Compile the fixture TypeScript to browser-ready JS
18
+ let fixturePath = path.resolve(import.meta.dirname, './fixture.ts')
19
+ let fixtureSource = await fsp.readFile(fixturePath, 'utf-8')
20
+ let { code: fixtureJs } = await transformTypeScript(fixtureSource, fixturePath)
21
+
22
+ let handler: (request: Request) => Response = (req) => {
23
+ let url = new URL(req.url)
24
+
25
+ if (url.pathname === '/') {
26
+ return new Response(
27
+ [
28
+ `<!doctype html>`,
29
+ `<html>`,
30
+ `<body>`,
31
+ ` <div id="result"></div>`,
32
+ ` <script type="module">`,
33
+ ` import { add, classify, greet } from '/src/test/coverage/fixture.ts'`,
34
+ ` // Exercise the same paths as the server fixture test:`,
35
+ ` // - add: fully covered`,
36
+ ` // - classify: only positive branch`,
37
+ ` // - greet: only with a name`,
38
+ ` // - uncalledFunction: never imported`,
39
+ ` let results = [`,
40
+ ` add(2, 3),`,
41
+ ` add(-1, 1),`,
42
+ ` classify(42),`,
43
+ ` classify(1),`,
44
+ ` greet('World'),`,
45
+ ` ]`,
46
+ ` document.getElementById('result').textContent = results.join(',')`,
47
+ ` </script>`,
48
+ `</body>`,
49
+ `</html>`,
50
+ ].join('\n'),
51
+ { headers: { 'Content-Type': 'text/html' } },
52
+ )
53
+ }
54
+
55
+ // Serve the compiled fixture at the path the import expects
56
+ if (url.pathname === '/src/test/coverage/fixture.ts') {
57
+ return new Response(fixtureJs, {
58
+ headers: { 'Content-Type': 'application/javascript' },
59
+ })
60
+ }
61
+
62
+ return new Response('Not found', { status: 404 })
63
+ }
64
+ let page = await t.serve(await createTestServer(handler))
65
+
66
+ await page.goto('/')
67
+ let result = await page.locator('#result').textContent()
68
+ assert.equal(result, '5,0,positive,positive,Hello, World!')
69
+ })
70
+ })
@@ -0,0 +1,32 @@
1
+ import * as assert from '@remix-run/assert'
2
+ import { describe, it } from '../../lib/framework.ts'
3
+ import { add, classify, greet } from './fixture.ts'
4
+
5
+ // Expected coverage for coverage-fixture.ts:
6
+ //
7
+ // add — 100% functions, statements, lines, branches
8
+ // classify — function covered, but only the `n > 0` branch is hit
9
+ // (the `n < 0` and `else` branches are uncovered)
10
+ // uncalledFunction — 0% across the board (never imported)
11
+ // greet — function covered, but only the truthy `name` branch is hit
12
+ // (the fallback `Hello, stranger!` line is uncovered)
13
+
14
+ describe('coverage/fixture.ts', () => {
15
+ it('add returns the sum', () => {
16
+ assert.equal(add(2, 3), 5)
17
+ assert.equal(add(-1, 1), 0)
18
+ })
19
+
20
+ it('classify identifies positive numbers only', () => {
21
+ assert.equal(classify(42), 'positive')
22
+ assert.equal(classify(1), 'positive')
23
+ // deliberately NOT testing classify(-1) or classify(0)
24
+ })
25
+
26
+ // deliberately NOT importing or calling uncalledFunction
27
+
28
+ it('greet with a name only', () => {
29
+ assert.equal(greet('World'), 'Hello, World!')
30
+ // deliberately NOT testing greet() without an argument
31
+ })
32
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "lib": ["ES2024", "DOM", "DOM.Iterable"],
5
+ "types": ["node", "dom-navigation"],
6
+ "module": "ES2022",
7
+ "moduleResolution": "Bundler",
8
+ "target": "ESNext",
9
+ "allowImportingTsExtensions": true,
10
+ "rewriteRelativeImportExtensions": true,
11
+ "verbatimModuleSyntax": true,
12
+ "skipLibCheck": true,
13
+ "jsx": "react-jsx",
14
+ "jsxImportSource": "@remix-run/ui"
15
+ }
16
+ }