Skip to content

Commit cce7f4f

Browse files
committed
test: add & configure Jest
Fixes #153 Signed-off-by: Ardalan Amini <[email protected]>
1 parent 5f05b76 commit cce7f4f

File tree

11 files changed

+2610
-34
lines changed

11 files changed

+2610
-34
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ jobs:
3535
env :
3636
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3737
with:
38+
prerelease: ${{ steps.changelog.outputs.prerelease }}
3839
body : |
3940
${{ steps.changelog.outputs.changelog }}
40-
prerelease: ${{ steps.changelog.outputs.prerelease }}

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
- name: Check code styles
3434
run : pnpm lint
3535

36+
- name: Run unit tests
37+
run : pnpm test
38+
3639
- name: Build using TypeScript
3740
run : pnpm build
3841

@@ -50,7 +53,7 @@ jobs:
5053
- name: Changelog
5154
uses: ./
5255
with:
53-
semver: ${{ startsWith(github.ref, 'refs/tags/') }}
56+
semver : ${{ startsWith(github.ref, 'refs/tags/') }}
5457
mention-new-contributors: ${{ github.ref_protected }}
5558

5659
test-with-inputs: # make sure the action works on a clean machine without building

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,23 @@ Using with default inputs:
252252
Using with custom inputs:
253253

254254
```yaml
255-
- name: Changelog
256-
uses: ardalanamini/auto-changelog@v4
255+
- uses: ardalanamini/auto-changelog@v4
257256
id : changelog
257+
name: Changelog
258258
with:
259259
github-token : ${{ github.token }}
260260
commit-types : |
261-
feat: New Features
262-
fix: Bug Fixes
263-
build: Build System & Dependencies
264-
perf: Performance Improvements
265-
docs: Documentation
266-
test: Tests
261+
feat : New Features
262+
fix : Bug Fixes
263+
build : Build System & Dependencies
264+
perf : Performance Improvements
265+
docs : Documentation
266+
test : Tests
267267
refactor: Refactors
268-
chore: Chores
269-
ci: CI
270-
style: Code Style
271-
revert: Reverts
268+
chore : Chores
269+
ci : CI
270+
style : Code Style
271+
revert : Reverts
272272
default-commit-type : Other Changes
273273
release-name : v1.0.0
274274
release-name-prefix : ""

action/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jest.config.ts

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2024 Ardalan Amini
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
/**
27+
* For a detailed explanation regarding each configuration property, visit:
28+
* https://jestjs.io/docs/configuration
29+
*/
30+
31+
import { type Config } from "jest";
32+
33+
export default {
34+
// All imported modules in your tests should be mocked automatically
35+
// automock: false,
36+
37+
// Stop running tests after `n` failures
38+
// bail: 0,
39+
40+
// The directory where Jest should store its cached dependency information
41+
// cacheDirectory: "/private/var/folders/dp/t3bs9gd575qfbxts2_vk6cm80000gn/T/jest_dx",
42+
43+
// Automatically clear mock calls, instances, contexts and results before every test
44+
clearMocks: true,
45+
46+
// Indicates whether the coverage information should be collected while executing the test
47+
// collectCoverage: false,
48+
49+
// An array of glob patterns indicating a set of files for which coverage information should be collected
50+
collectCoverageFrom: ["<rootDir>/src/**/*.ts"],
51+
52+
// The directory where Jest should output its coverage files
53+
// coverageDirectory: undefined,
54+
55+
// An array of regexp pattern strings used to skip coverage collection
56+
// coveragePathIgnorePatterns: [
57+
// "/node_modules/"
58+
// ],
59+
60+
// Indicates which provider should be used to instrument code for coverage
61+
coverageProvider: "babel",
62+
63+
// A list of reporter names that Jest uses when writing coverage reports
64+
// coverageReporters: [
65+
// "json",
66+
// "text",
67+
// "lcov",
68+
// "clover"
69+
// ],
70+
71+
// An object that configures minimum threshold enforcement for coverage results
72+
// coverageThreshold: undefined,
73+
74+
// A path to a custom dependency extractor
75+
// dependencyExtractor: undefined,
76+
77+
// Make calling deprecated APIs throw helpful error messages
78+
// errorOnDeprecated: false,
79+
80+
// The default configuration for fake timers
81+
// fakeTimers: {
82+
// "enableGlobally": false
83+
// },
84+
85+
// Force coverage collection from ignored files using an array of glob patterns
86+
// forceCoverageMatch: [],
87+
88+
// A path to a module which exports an async function that is triggered once before all test suites
89+
// globalSetup: undefined,
90+
91+
// A path to a module which exports an async function that is triggered once after all test suites
92+
// globalTeardown: undefined,
93+
94+
// A set of global variables that need to be available in all test environments
95+
// globals: {},
96+
97+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
98+
// maxWorkers: "50%",
99+
100+
// An array of directory names to be searched recursively up from the requiring module's location
101+
// moduleDirectories: [
102+
// "node_modules"
103+
// ],
104+
105+
// An array of file extensions your modules use
106+
// moduleFileExtensions: [
107+
// "js",
108+
// "mjs",
109+
// "cjs",
110+
// "jsx",
111+
// "ts",
112+
// "tsx",
113+
// "json",
114+
// "node"
115+
// ],
116+
117+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
118+
moduleNameMapper: {
119+
"^(\\.{1,2}/.*)\\.js$": "$1",
120+
},
121+
122+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
123+
// modulePathIgnorePatterns: [],
124+
125+
// Activates notifications for test results
126+
// notify: false,
127+
128+
// An enum that specifies notification mode. Requires { notify: true }
129+
// notifyMode: "failure-change",
130+
131+
// A preset that is used as a base for Jest's configuration
132+
// preset: undefined,
133+
134+
// Run tests from one or more projects
135+
// projects: undefined,
136+
137+
// Use this configuration option to add custom reporters to Jest
138+
reporters: ["default", "github-actions"],
139+
140+
// Automatically reset mock state before every test
141+
// resetMocks: false,
142+
143+
// Reset the module registry before running each individual test
144+
// resetModules: false,
145+
146+
// A path to a custom resolver
147+
// resolver: undefined,
148+
149+
// Automatically restore mock state and implementation before every test
150+
// restoreMocks: false,
151+
152+
// The root directory that Jest should scan for tests and modules within
153+
// rootDir: undefined,
154+
155+
// A list of paths to directories that Jest should use to search for files in
156+
// roots: [
157+
// "<rootDir>"
158+
// ],
159+
160+
// Allows you to use a custom runner instead of Jest's default test runner
161+
// runner: "jest-runner",
162+
163+
// The paths to modules that run some code to configure or set up the testing environment before each test
164+
// setupFiles: [],
165+
166+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
167+
// setupFilesAfterEnv: [],
168+
169+
// The number of seconds after which a test is considered as slow and reported as such in the results.
170+
// slowTestThreshold: 5,
171+
172+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
173+
// snapshotSerializers: [],
174+
175+
// The test environment that will be used for testing
176+
// testEnvironment: "jest-environment-node",
177+
178+
// Options that will be passed to the testEnvironment
179+
// testEnvironmentOptions: {},
180+
181+
// Adds a location field to test results
182+
// testLocationInResults: false,
183+
184+
// The glob patterns Jest uses to detect test files
185+
testMatch: [
186+
"<rootDir>/tests/**/*.test.ts",
187+
188+
// "**/__tests__/**/*.[jt]s?(x)",
189+
// "**/?(*.)+(spec|test).[tj]s?(x)",
190+
],
191+
192+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
193+
// testPathIgnorePatterns: [
194+
// "/node_modules/"
195+
// ],
196+
197+
// The regexp pattern or array of patterns that Jest uses to detect test files
198+
// testRegex: [],
199+
200+
// This option allows the use of a custom results processor
201+
// testResultsProcessor: undefined,
202+
203+
// This option allows use of a custom test runner
204+
// testRunner: "jest-circus/runner",
205+
206+
// A map from regular expressions to paths to transformers
207+
transform: {
208+
"^.+\\.[cm]?[jt]sx?$": "@swc/jest",
209+
},
210+
211+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
212+
// transformIgnorePatterns: [
213+
// "/node_modules/",
214+
// "\\.pnp\\.[^\\/]+$"
215+
// ],
216+
217+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
218+
// unmockedModulePathPatterns: undefined,
219+
220+
// Indicates whether each individual test should be reported during the run
221+
// verbose: undefined,
222+
223+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
224+
// watchPathIgnorePatterns: [],
225+
226+
// Whether to use watchman for file crawling
227+
// watchman: true,
228+
229+
logHeapUsage: true,
230+
231+
workerIdleMemoryLimit: "512MB",
232+
} satisfies Config;

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"build:watch": "pnpm build --watch",
3232
"package": "ncc build --out action --minify --source-map --license licenses.txt",
3333
"all": "pnpm lint:fix && pnpm build && pnpm package",
34-
"test": "echo \"Error: no test specified\" && exit 1"
34+
"test": "node --expose-gc node_modules/jest/bin/jest -c jest.config.ts",
35+
"test:coverage": "pnpm test -- --coverage"
3536
},
3637
"dependencies": {
3738
"@actions/core": "^1.11.1",
@@ -44,6 +45,9 @@
4445
"@commitlint/cli": "^19.5.0",
4546
"@commitlint/config-conventional": "^19.5.0",
4647
"@commitlint/types": "^19.5.0",
48+
"@swc/core": "^1.7.40",
49+
"@swc/jest": "^0.2.36",
50+
"@types/jest": "^29.5.14",
4751
"@types/semver": "^7.5.8",
4852
"@typescript-eslint/eslint-plugin": "^6.21.0",
4953
"@typescript-eslint/parser": "^6.21.0",
@@ -54,7 +58,9 @@
5458
"eslint-plugin-import": "^2.31.0",
5559
"husky": "^9.1.6",
5660
"is-ci": "^3.0.1",
61+
"jest": "^29.7.0",
5762
"prettier": "^3.3.3",
63+
"ts-node": "^10.9.2",
5864
"typescript": "^5.6.3"
5965
}
6066
}

0 commit comments

Comments
 (0)