-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add config for the `jest` unit testing framework. - Add tests for `utils/math.ts`. - Add gh-actions workflow to run unit tests.
- Loading branch information
1 parent
9927069
commit 7e6073f
Showing
6 changed files
with
4,019 additions
and
1,225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: "test" | ||
|
||
on: | ||
pull_request: | ||
types: ["opened", "reopened", "synchronize"] | ||
push: | ||
schedule: | ||
# Run daily at 00:15 UTC (the 15 is to avoid periods of high load) | ||
- cron: "15 0 * * *" | ||
workflow_dispatch: | ||
|
||
permissions: {} | ||
|
||
concurrency: | ||
group: "${{github.workflow}}-${{github.ref}}" | ||
|
||
# Cancel in-progress jobs for efficiency | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- uses: "actions/checkout@v4" | ||
with: | ||
submodules: "recursive" | ||
- uses: "actions/setup-node@v4" | ||
with: | ||
node-version: "22" | ||
cache: "npm" | ||
cache-dependency-path: "./package-lock.json" | ||
- run: "npm clean-install" | ||
- run: "npm run test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type {Config} from "jest"; | ||
import os from "node:os"; | ||
import pathPosix from "node:path/posix"; | ||
|
||
|
||
let PRIMARY_REPORTER: string | [string, Record<string, unknown>] = "default"; | ||
if ("undefined" !== typeof process.env.GITHUB_ACTIONS) { | ||
PRIMARY_REPORTER = [ | ||
"github-actions", | ||
{silent: false}, | ||
]; | ||
} | ||
console.log(`Environment variable "GITHUB_ACTIONS"="${process.env.GITHUB_ACTIONS}": ` + | ||
`primary reporter will be "${JSON.stringify(PRIMARY_REPORTER)}".`); | ||
|
||
const JEST_CONFIG: Config = { | ||
collectCoverage: true, | ||
collectCoverageFrom: ["src/**/*.{ts,tsx}"], | ||
coverageProvider: "v8", | ||
coverageReporters: ["text"], | ||
coverageThreshold: { | ||
"global": { | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
}, | ||
// eslint-disable-next-line no-warning-comments | ||
// TODO: Remove/adjust the overrides below as more test cases are added. | ||
"src/": { | ||
branches: 0, | ||
functions: 0, | ||
lines: 0, | ||
}, | ||
"src/utils/math.ts": { | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
}, | ||
}, | ||
displayName: { | ||
name: "yscope-log-viewer", | ||
color: "blue", | ||
}, | ||
errorOnDeprecated: true, | ||
maxConcurrency: os.cpus().length, | ||
maxWorkers: "100%", | ||
openHandlesTimeout: 1000, | ||
reporters: [ | ||
PRIMARY_REPORTER, | ||
"summary", | ||
], | ||
showSeed: true, | ||
testMatch: [ | ||
pathPosix.join(__dirname, "test/**/?(*)test.{ts,tsx}"), | ||
], | ||
testTimeout: 5000, | ||
transform: { | ||
".(ts|tsx)$": [ | ||
"ts-jest", | ||
{useESM: true}, | ||
], | ||
}, | ||
verbose: true, | ||
|
||
// NOTE: Extra properties in types such as `Error`, `Map`, or `Set` are not preserved when | ||
// passing payloads between parent and child threads due to serialization. | ||
// See https://jestjs.io/docs/29.6/configuration#workerthreads | ||
workerThreads: true, | ||
}; | ||
|
||
export default JEST_CONFIG; |
Oops, something went wrong.