Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add unit testing infra: #115

Merged
merged 24 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a2f4075
Add Jest configuration and tests.
junhaoliao Nov 9, 2024
ba1bb9e
Add GitHub Actions workflow for automated testing.
junhaoliao Nov 9, 2024
1a22afe
Non-zero result: Failed test.
junhaoliao Nov 9, 2024
11825a1
Non-zero result: Failed coverage.
junhaoliao Nov 9, 2024
a82b2f6
Revert "Non-zero result: Failed coverage."
junhaoliao Nov 9, 2024
d313cf4
Revert "Non-zero result: Failed test."
junhaoliao Nov 9, 2024
571100c
Debug github annotations.
junhaoliao Nov 9, 2024
859d317
Fix test case.
junhaoliao Nov 9, 2024
492ba0f
Log primary reporter.
junhaoliao Nov 9, 2024
ea1d7fd
Update test description.
junhaoliao Nov 9, 2024
3afa8dc
Remove `actions: "write"` from permissions list.
junhaoliao Nov 10, 2024
fe366ab
Add line before comment.
junhaoliao Nov 10, 2024
d1f6b68
Update daily run comment.
junhaoliao Nov 10, 2024
1fb3211
Merge remote-tracking branch 'yscope/main' into jest
junhaoliao Nov 15, 2024
cb9325a
Update dependencies in package-lock.json.
junhaoliao Nov 15, 2024
36677d4
Docs - Apply suggestions from code review
junhaoliao Nov 19, 2024
bffe451
Check env var GITHUB_ACTIONS instead of CI - Apply suggestions from c…
junhaoliao Nov 19, 2024
2a95501
Add period to reporter log statement and wrap the JSON strigified PRI…
junhaoliao Nov 20, 2024
9f27111
Remove coverage threshold overrides for individual components.
junhaoliao Nov 20, 2024
475740d
Enforce 100% branches coverage.
junhaoliao Nov 20, 2024
b11ac40
Remove `testEnvironment: "node"` which is the default.
junhaoliao Nov 20, 2024
7256bdb
Add jest.config.ts to npm script `lint:check:js`.
junhaoliao Nov 20, 2024
d701e07
Update docs for `workerThreads` jest config option - Apply suggestion…
junhaoliao Nov 20, 2024
e4f90d4
Run eslint with `.` and add `ignorePatterns` in ESLint config.
junhaoliao Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/test.yaml
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 at midnight UTC every day with 15 minutes delay added to avoid high load periods
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
- 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"
Henry8192 marked this conversation as resolved.
Show resolved Hide resolved
88 changes: 88 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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.CI) {
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
PRIMARY_REPORTER = [
"github-actions",
{silent: false},
];
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved
}
console.log(`Environment variable "CI"="${process.env.CI}": ` +
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
`primary reporter will be ${JSON.stringify(PRIMARY_REPORTER)}`);

const JEST_CONFIG: Config = {
collectCoverage: true,
collectCoverageFrom: ["src/**/*.{ts,tsx}"],
coverageProvider: "v8",
coverageReporters: ["text"],
coverageThreshold: {
"global": {
functions: 90,
lines: 90,
},
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line no-warning-comments
// TODO: Remove / Adjust below overrides as more test cases are added.
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
"src/*.tsx": {
functions: 0,
lines: 0,
},
"src/components/": {
functions: 0,
lines: 0,
},
"src/contexts/": {
functions: 0,
lines: 0,
},
"src/services/": {
functions: 0,
lines: 0,
},
"src/typings/": {
functions: 0,
lines: 0,
},
"src/utils/": {
functions: 0,
lines: 0,
},
"src/utils/math.ts": {
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,
testEnvironment: "node",
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved
testMatch: [
pathPosix.join(__dirname, "test/**/?(*)test.{ts,tsx}"),
],
testTimeout: 5000,
transform: {
".(ts|tsx)$": [
"ts-jest",
{useESM: true},
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved
],
},
verbose: true,

// Caution: Extra properties set on `Error`, `Map` or `Set` will not be passed on through the
// serialization.
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
workerThreads: true,
};

export default JEST_CONFIG;
Loading
Loading