Skip to content

Commit ef3ff0a

Browse files
committed
Update CI configuration, remove husky pre-commit, and add simple-git-hooks; introduce Jest configuration and TypeScript settings
1 parent 6f59958 commit ef3ff0a

7 files changed

Lines changed: 93 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [16.x, 18.x]
15+
node-version: [20.x]
1616

1717
env:
1818
CI: true
19-
COVERAGE: ${{ matrix.node-version == '18.x' && true || false }}
19+
COVERAGE: ${{ matrix.node-version == '20.x' && true || false }}
2020

2121
steps:
2222
- uses: actions/checkout@v3

.husky/pre-commit

Lines changed: 0 additions & 8 deletions
This file was deleted.

jest.config.cjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const tsPreset = require("ts-jest/presets/default-esm/jest-preset.js");
2+
const puppeteerPreset = require("jest-puppeteer/jest-preset.js");
3+
4+
const baseConfig = {
5+
verbose: true,
6+
resolver: require.resolve("ts-jest-resolver"),
7+
testTimeout: 100000,
8+
testEnvironment: "node",
9+
collectCoverage: true,
10+
clearMocks: true,
11+
transform: {
12+
"^.+\\.m?tsx?$": [
13+
"ts-jest",
14+
{
15+
useESM: false,
16+
tsconfig: "./tsconfig.jest.json",
17+
},
18+
],
19+
},
20+
moduleNameMapper: {
21+
"^(\\.{1,2}/.*)\\.js$": "$1",
22+
},
23+
testMatch: [
24+
"**/tests/**/*.test.ts",
25+
"**/tests/**/*.test.js",
26+
],
27+
coveragePathIgnorePatterns: [
28+
"<rootDir>/node-modules/",
29+
"<rootDir>/tests/",
30+
"<rootDir>/src/internal/util.inspect.polyfill.ts",
31+
],
32+
};
33+
34+
module.exports = {
35+
...tsPreset,
36+
...puppeteerPreset,
37+
...baseConfig,
38+
};

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232
},
3333
"scripts": {
34-
"prepare": "husky install",
34+
"prepare": "simple-git-hooks",
3535
"build": "npm run build-types && npm run build-server && npm run build-browser",
3636
"build-browser": "node build.js",
3737
"build-types": "tsc -b tsconfig.types.json",
@@ -42,35 +42,18 @@
4242
"lint": "eslint --ext .js,.ts .",
4343
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
4444
"pretest": "node scripts/free-test-port.cjs",
45-
"test": "JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest",
45+
"test": "JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest --config ./jest.config.cjs",
4646
"test-puppeteer-serve": "npm run build-browser && node tests/support/browser/server/index.cjs -p 4444",
47-
"coverage": "JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest --coverage",
47+
"coverage": "JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest --config ./jest.config.cjs --coverage",
4848
"docsify-init": "docsify init ./docs",
4949
"docsify-serve": "cd docs && docsify serve",
5050
"pre-publish": "npm run build",
51-
"release": "np --any-branch"
51+
"release": "np --any-branch",
52+
"pre-commit-hook": "bash ./scripts/pre-commit.sh"
5253
},
5354
"engines": {
5455
"node": ">=16"
5556
},
56-
"jest": {
57-
"verbose": true,
58-
"preset": "./jest-preset",
59-
"resolver": "ts-jest-resolver",
60-
"testTimeout": 100000,
61-
"testEnvironment": "node",
62-
"collectCoverage": true,
63-
"clearMocks": true,
64-
"testMatch": [
65-
"**/tests/**/*.test.ts",
66-
"**/tests/**/*.test.js"
67-
],
68-
"coveragePathIgnorePatterns": [
69-
"<rootDir>/node-modules/",
70-
"<rootDir>/tests/",
71-
"<rootDir>/src/internal/util.inspect.polyfill.ts"
72-
]
73-
},
7457
"np": {
7558
"yarn": false,
7659
"contents": "."
@@ -84,6 +67,9 @@
8467
],
8568
"exec": "node --experimental-specifier-resolution=node --enable-source-maps --no-warnings --loader ts-node/esm"
8669
},
70+
"simple-git-hooks": {
71+
"pre-commit": "npm run pre-commit-hook"
72+
},
8773
"devDependencies": {
8874
"@jest/types": "^30.0.5",
8975
"@types/expect-puppeteer": "^5.0.6",
@@ -95,14 +81,14 @@
9581
"esbuild": "^0.25.10",
9682
"eslint": "^9.36.0",
9783
"eslint-config-prettier": "^10.1.8",
98-
"husky": "^9.1.7",
9984
"jest": "^30.1.3",
10085
"jest-puppeteer": "^11.0.0",
10186
"kill-port": "^2.0.1",
10287
"nodemon": "^3.1.10",
10388
"np": "^10.2.0",
10489
"prettier": "^3.6.2",
10590
"puppeteer": "^24.22.3",
91+
"simple-git-hooks": "^2.13.1",
10692
"ts-jest": "^29.4.4",
10793
"ts-jest-resolver": "^2.0.1",
10894
"ts-node": "^10.9.2",

scripts/pre-commit.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Ensure npm is available, falling back to nvm for non-login shells.
5+
if ! command -v npm >/dev/null 2>&1; then
6+
export NVM_DIR="${NVM_DIR:-"$HOME/.nvm"}"
7+
if [ -s "$NVM_DIR/nvm.sh" ]; then
8+
# shellcheck disable=SC1090
9+
. "$NVM_DIR/nvm.sh"
10+
nvm use --silent >/dev/null 2>&1 || nvm use >/dev/null 2>&1
11+
fi
12+
fi
13+
14+
if ! command -v npm >/dev/null 2>&1; then
15+
echo "pre-commit: npm command not found. Install Node.js or ensure it is in PATH." >&2
16+
exit 127
17+
fi
18+
19+
npm run test
20+
npm run format
21+
npm run lint
22+
npm run build
23+
npm run docsify-init

tsconfig.jest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "http://json.schemastore.org/tsconfig",
3+
"extends": "./tsconfig.json",
4+
"compilerOptions": {
5+
"isolatedModules": true,
6+
"module": "CommonJS",
7+
"moduleResolution": "node10"
8+
}
9+
}

0 commit comments

Comments
 (0)