Skip to content

Commit 2f4aa33

Browse files
committed
Add unit tests
1 parent 5d71f7b commit 2f4aa33

File tree

14 files changed

+6761
-862
lines changed

14 files changed

+6761
-862
lines changed

.eslintrc

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

.github/workflows/test-and-lint.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Test and Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
lint:
16+
name: Lint
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 20
27+
cache: 'npm'
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Run linter
33+
run: npm run lint
34+
35+
test:
36+
name: Test (Node ${{ matrix.node-version }} on ${{ matrix.os }})
37+
runs-on: ${{ matrix.os }}
38+
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
os: [ubuntu-latest, windows-latest, macos-latest]
43+
node-version: [20.x, 22.x]
44+
exclude:
45+
# Exclude some combinations to save CI time
46+
- os: windows-latest
47+
node-version: 22.x
48+
- os: macos-latest
49+
node-version: 22.x
50+
51+
steps:
52+
- name: Checkout repository
53+
uses: actions/checkout@v4
54+
55+
- name: Setup Node.js ${{ matrix.node-version }}
56+
uses: actions/setup-node@v4
57+
with:
58+
node-version: ${{ matrix.node-version }}
59+
cache: 'npm'
60+
61+
- name: Install dependencies
62+
run: npm ci
63+
64+
- name: Run tests with coverage
65+
run: npm run test:coverage
66+
67+
- name: Upload coverage to Codecov
68+
if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x'
69+
uses: codecov/codecov-action@v4
70+
with:
71+
token: ${{ secrets.CODECOV_TOKEN }}
72+
files: ./coverage/lcov.info
73+
fail_ci_if_error: false
74+
verbose: true
75+
76+
build:
77+
name: Build
78+
runs-on: ubuntu-latest
79+
needs: [lint, test]
80+
81+
steps:
82+
- name: Checkout repository
83+
uses: actions/checkout@v4
84+
85+
- name: Setup Node.js
86+
uses: actions/setup-node@v4
87+
with:
88+
node-version: 20
89+
cache: 'npm'
90+
91+
- name: Install dependencies
92+
run: npm ci
93+
94+
- name: Build
95+
run: npm run build
96+
97+
- name: Verify build succeeded
98+
run: |
99+
if [ ! -f "dist/index.js" ]; then
100+
echo "::error::Build failed - dist/index.js not found"
101+
exit 1
102+
fi
103+
echo "Build completed successfully"
104+
105+
# This job is used as a required check in branch protection rules
106+
ci-status:
107+
name: CI Status
108+
runs-on: ubuntu-latest
109+
needs: [lint, test, build]
110+
if: always()
111+
112+
steps:
113+
- name: Check CI status
114+
run: |
115+
if [[ "${{ needs.lint.result }}" == "failure" || "${{ needs.test.result }}" == "failure" || "${{ needs.build.result }}" == "failure" ]]; then
116+
echo "::error::One or more CI jobs failed"
117+
exit 1
118+
fi
119+
echo "All CI checks passed successfully"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Clean Workflow Action
22

3+
[![Test and Lint](https://github.com/igorjs/gh-actions-clean-workflow/actions/workflows/test-and-lint.yml/badge.svg)](https://github.com/igorjs/gh-actions-clean-workflow/actions/workflows/test-and-lint.yml)
4+
35
Clean workflow run logs based on configuration.
46

57
## Usage

dist/index.js

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

eslint.config.js

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,78 @@
11
const js = require("@eslint/js");
2+
const tsPlugin = require("@typescript-eslint/eslint-plugin");
3+
const tsParser = require("@typescript-eslint/parser");
4+
const globals = require("globals");
5+
6+
// Available global sets from the globals package:
7+
// - globals.browser - Browser environment globals
8+
// - globals.node - Node.js globals (includes CommonJS)
9+
// - globals.nodeBuiltin - Node.js built-ins only (no CommonJS)
10+
// - globals.es2015 to globals.es2025 - ECMAScript globals by year
11+
// - globals.jest, globals.mocha, globals.jasmine, globals.vitest - Testing frameworks
12+
// - globals.commonjs - CommonJS specific (require, module, exports)
13+
// - globals.worker - Web Worker environment
14+
// - globals.serviceworker - Service Worker environment
15+
// - globals.jquery - jQuery globals
16+
// - globals['shared-node-browser'] - Shared between Node.js and browsers
217

318
module.exports = [
19+
// Base JavaScript configuration
20+
js.configs.recommended,
21+
22+
// JavaScript files configuration
423
{
24+
files: ["**/*.js"],
525
languageOptions: {
26+
ecmaVersion: 2022,
27+
sourceType: "module",
628
globals: {
7-
console: "readonly",
8-
process: "readonly",
29+
...globals.node,
30+
...globals.es2021,
931
},
1032
},
1133
},
34+
35+
// TypeScript configuration
1236
{
13-
ignores: [".github/**", "dist/**", "node_modules/**"],
37+
files: ["**/*.ts"],
38+
languageOptions: {
39+
parser: tsParser,
40+
parserOptions: {
41+
ecmaVersion: 2022,
42+
sourceType: "module",
43+
project: "./tsconfig.json",
44+
},
45+
globals: {
46+
...globals.node,
47+
...globals.es2021,
48+
...globals.jest,
49+
},
50+
},
51+
plugins: {
52+
"@typescript-eslint": tsPlugin,
53+
},
54+
rules: {
55+
...tsPlugin.configs.recommended.rules,
56+
"@typescript-eslint/no-explicit-any": "warn",
57+
"@typescript-eslint/no-unused-vars": [
58+
"error",
59+
{ argsIgnorePattern: "^_" },
60+
],
61+
"no-unused-vars": "off", // Turn off base rule as it's handled by TypeScript
62+
},
63+
},
64+
65+
// Ignore patterns
66+
{
67+
ignores: [
68+
".github/**",
69+
"dist/**",
70+
"node_modules/**",
71+
"coverage/**",
72+
"*.config.js",
73+
"*.config.ts",
74+
"**/*.test.ts",
75+
"**/*.spec.ts",
76+
],
1477
},
15-
js.configs.recommended,
1678
];

jest.config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Config } from "jest";
2+
3+
const config: Config = {
4+
preset: "ts-jest",
5+
testEnvironment: "node",
6+
roots: ["<rootDir>/src"],
7+
testMatch: ["**/*.test.ts"],
8+
collectCoverageFrom: [
9+
"src/**/*.ts",
10+
"!src/**/*.d.ts",
11+
"!src/**/__tests__/**",
12+
],
13+
coverageThreshold: {
14+
global: {
15+
branches: 80,
16+
functions: 80,
17+
lines: 80,
18+
statements: 80,
19+
},
20+
},
21+
clearMocks: true,
22+
restoreMocks: true,
23+
maxWorkers: 1, // Run tests sequentially
24+
};
25+
26+
export default config;

0 commit comments

Comments
 (0)