Skip to content

Commit

Permalink
feat(wip): add a node-test plugin
Browse files Browse the repository at this point in the history
This adds a node-test plugin using `node:test#run()`. There are quite a
few gotchas with this one:

  * If we want to support Node.js 18 and 20 then we can't use glob
    patterns (the `globPatterns` option) because it's only supported in
    Node.js 22. I think glob patterns are important so I've replicated
    with the glob package.

  * We don't support Node.js 18 less than v18.17.0, this is because
    there wasn't a consistent JavaScript API for the built-in test
    reporters before this version. This is captured in the engines. An
    alternative would be to drop Node.js 18 support in this package as
    we'll be doing this in April 2025 anyway.

  * There is no way of configuring the built-in test runner via a config
    file or similar. This means we need to expose more options than Jest
    or Mocha in the Tool Kit config file.
  • Loading branch information
rowanmanning committed Oct 30, 2024
1 parent 2a5ede5 commit 241d819
Show file tree
Hide file tree
Showing 12 changed files with 598 additions and 25 deletions.
2 changes: 2 additions & 0 deletions lib/schemas/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { JestSchema } from './tasks/jest'
import { MochaSchema } from './tasks/mocha'
import { NodeSchema } from './tasks/node'
import { NodemonSchema } from './tasks/nodemon'
import { NodeTestSchema } from './tasks/node-test'
import { PrettierSchema } from './tasks/prettier'
import { TypeScriptSchema } from './tasks/typescript'
import { UploadAssetsToS3Schema } from './tasks/upload-assets-to-s3'
Expand All @@ -29,6 +30,7 @@ export const TaskSchemas = {
Mocha: MochaSchema,
Node: NodeSchema,
Nodemon: NodemonSchema,
NodeTest: NodeTestSchema,
NpmPrune: z.object({}).describe('Prune development npm dependencies.'),
NpmPublish: z.object({}).describe('Publish package to the npm registry.'),
NTest: SmokeTestSchema,
Expand Down
22 changes: 22 additions & 0 deletions lib/schemas/src/tasks/node-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { z } from 'zod'

export const NodeTestSchema = z
.object({
concurrency: z
.number()
.int()
.or(z.boolean())
.default(false)
.describe('The number of tests to run in parallel. See https://nodejs.org/api/test.html#runoptions'),
files: z.string().array().optional().describe('The glob patterns for test files'),
ignore: z.string().array().optional().describe('Glob patterns for test files to ignore'),
forceExit: z
.boolean()
.default(false)
.describe('Whether to force exit the process once all tests have finished executing')
})
.describe('Runs the built-in Node.js test runner to execute tests.')

export type NodeTestOptions = z.infer<typeof NodeTestSchema>

export const Schema = NodeTestSchema
Loading

0 comments on commit 241d819

Please sign in to comment.