Skip to content

Commit 1ffe67a

Browse files
authored
chore: replace jest with bun test runner (#369)
1 parent d7f4c2e commit 1ffe67a

File tree

15 files changed

+411
-1514
lines changed

15 files changed

+411
-1514
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: bun tsc
3232

3333
- name: Run Unit Tests
34-
run: bun jest
34+
run: bun test
3535

3636
- name: Package
3737
run: bun package

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
dist/
22
lib/
33
node_modules/
4-
test/

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ where "my-new-feature" describes what you're working on.
2020

2121
### 3. Add tests for any bug fixes or new functionality
2222

23-
All functions must be tested with a unit test. Please follow the existing convention of one exported function per file with a corresponding file to test it. Run tests using `npm run test`, or using the [Jest CLI](https://jestjs.io/docs/cli).
23+
All functions must be tested with a unit test. Please follow the existing convention of one exported function per file with a corresponding file to test it. Run tests using `bun test`.
2424

2525
There is also an integration test present in the [test workflow](./.github/workflows/test.yaml), which will actually run this Github Action using the code from this repository. This allows you to test your change to the Github Action right within the pull request you make.
2626

bun.lock

Lines changed: 11 additions & 975 deletions
Large diffs are not rendered by default.

dist/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18928,4 +18928,4 @@ export {
1892818928
RULES_MAP
1892918929
};
1893018930

18931-
//# debugId=A01C63CE64BC71EA64756E2164756E21
18931+
//# debugId=9A10F4DCA142A16C64756E2164756E21

dist/main.js.map

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

package.json

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "package-json-validator",
3-
"packageManager": "bun@1.2.17",
3+
"packageManager": "bun@1.3.1",
44
"private": true,
55
"main": "src/main.ts",
66
"type": "module",
77
"scripts": {
88
"format": "prettier --write .",
9-
"format-check": "prettier --check",
9+
"format-check": "prettier --check .",
1010
"lint": "eslint .",
1111
"package": "bun build src/main.ts --outdir dist/ --target node --sourcemap=external",
1212
"pre-commit": "bun lint && bun format && bun package && git add .",
1313
"prepare": "husky",
14-
"test": "bun jest"
14+
"test": "bun test"
1515
},
1616
"repository": {
1717
"type": "git",
@@ -29,31 +29,12 @@
2929
"@actions/github": "6.0.1"
3030
},
3131
"devDependencies": {
32-
"@swc/jest": "0.2.39",
33-
"@types/jest": "30.0.0",
32+
"@types/bun": "1.3.1",
3433
"eslint": "9.39.0",
3534
"husky": "9.1.7",
36-
"jest": "30.2.0",
3735
"prettier": "3.6.2",
3836
"type-fest": "5.1.0",
3937
"typescript": "5.9.3",
4038
"typescript-eslint": "8.46.2"
41-
},
42-
"jest": {
43-
"transform": {
44-
"^.+\\.(t|j)sx?$": [
45-
"@swc/jest",
46-
{
47-
"jsc": {
48-
"target": "esnext"
49-
}
50-
}
51-
]
52-
},
53-
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
54-
"testPathIgnorePatterns": [
55-
"lib"
56-
],
57-
"clearMocks": true
5839
}
5940
}

test/main.test.ts

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

test/rules/alphabetical.test.ts

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,67 @@
1-
import {PackageJson} from 'type-fest';
2-
import * as core from '@actions/core';
1+
import { PackageJson } from 'type-fest';
32
import { validateAlphabetical } from '../../src/rules/alphabetical';
4-
import { getMultilineInput } from '@actions/core';
3+
import { afterEach, describe, expect, it, mock } from 'bun:test';
54

6-
jest.mock('@actions/core');
7-
8-
(getMultilineInput as jest.Mock).mockReturnValue(['dependencies', 'devDependencies']);
5+
const getMultilineInputMock = mock(() => ['dependencies', 'devDependencies']);
6+
const setFailedMock = mock();
7+
mock.module('@actions/core', () => ({
8+
getMultilineInput: getMultilineInputMock,
9+
setFailed: setFailedMock
10+
}));
911

1012
describe('alphabetical', () => {
11-
it('should fail when dependencies are not in alphabetical order', () => {
12-
const packageJson: PackageJson = {
13-
dependencies: {
14-
'a-package': '1.2.3',
15-
'c-package': '1.2.3',
16-
'b-package': '1.2.3',
17-
},
18-
devDependencies: {
19-
'c-package': '1.2.3',
20-
'd-package': '1.2.3',
21-
'e-package': '1.2.3',
22-
}
23-
};
24-
validateAlphabetical(packageJson);
25-
expect(core.setFailed).toHaveBeenCalled();
26-
});
13+
afterEach(() => {
14+
mock.clearAllMocks();
15+
});
16+
17+
it('should fail when dependencies are not in alphabetical order', () => {
18+
const packageJson: PackageJson = {
19+
dependencies: {
20+
'a-package': '1.2.3',
21+
'c-package': '1.2.3',
22+
'b-package': '1.2.3'
23+
},
24+
devDependencies: {
25+
'c-package': '1.2.3',
26+
'd-package': '1.2.3',
27+
'e-package': '1.2.3'
28+
}
29+
};
30+
validateAlphabetical(packageJson);
31+
expect(setFailedMock).toHaveBeenCalled();
32+
});
2733

28-
it('should fail when devDependencies are not in alphabetical order', () => {
29-
const packageJson: PackageJson = {
30-
dependencies: {
31-
'a-package': '1.2.3',
32-
'b-package': '1.2.3',
33-
'c-package': '1.2.3',
34-
},
35-
devDependencies: {
36-
'd-package': '1.2.3',
37-
'c-package': '1.2.3',
38-
'e-package': '1.2.3',
39-
}
40-
};
41-
validateAlphabetical(packageJson);
42-
expect(core.setFailed).toHaveBeenCalled();
43-
});
34+
it('should fail when devDependencies are not in alphabetical order', () => {
35+
const packageJson: PackageJson = {
36+
dependencies: {
37+
'a-package': '1.2.3',
38+
'b-package': '1.2.3',
39+
'c-package': '1.2.3'
40+
},
41+
devDependencies: {
42+
'd-package': '1.2.3',
43+
'c-package': '1.2.3',
44+
'e-package': '1.2.3'
45+
}
46+
};
47+
validateAlphabetical(packageJson);
48+
expect(setFailedMock).toHaveBeenCalled();
49+
});
4450

45-
it('should not fail when dependencies are in alphabetical order', () => {
46-
const packageJson: PackageJson = {
47-
dependencies: {
48-
'a-package': '1.2.3',
49-
'b-package': '1.2.3',
50-
'c-package': '1.2.3',
51-
},
52-
devDependencies: {
53-
'c-package': '1.2.3',
54-
'd-package': '1.2.3',
55-
'e-package': '1.2.3',
56-
}
57-
};
58-
validateAlphabetical(packageJson);
59-
expect(core.setFailed).not.toHaveBeenCalled();
60-
});
51+
it('should not fail when dependencies are in alphabetical order', () => {
52+
const packageJson: PackageJson = {
53+
dependencies: {
54+
'a-package': '1.2.3',
55+
'b-package': '1.2.3',
56+
'c-package': '1.2.3'
57+
},
58+
devDependencies: {
59+
'c-package': '1.2.3',
60+
'd-package': '1.2.3',
61+
'e-package': '1.2.3'
62+
}
63+
};
64+
validateAlphabetical(packageJson);
65+
expect(setFailedMock).not.toHaveBeenCalled();
66+
});
6167
});

test/rules/keys.test.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
import {validateKeys} from '../../src/rules/keys';
2-
import * as core from '@actions/core';
3-
import { getMultilineInput } from '@actions/core';
1+
import { validateKeys } from '../../src/rules/keys';
42
import dupedPackageJson from '../fixtures/duped-package.json';
53
import dupedScriptsPackageJson from '../fixtures/duped-scripts-package.json';
64
import dedupedPackageJson from '../fixtures/deduped-package.json';
5+
import { afterEach, describe, expect, it, mock } from 'bun:test';
76

8-
jest.mock('@actions/core');
9-
(getMultilineInput as jest.Mock).mockReturnValue(['dependencies', 'devDependencies']);
7+
const getMultilineInputMock = mock(() => ['dependencies', 'devDependencies']);
8+
const setFailedMock = mock();
9+
mock.module('@actions/core', () => ({
10+
getMultilineInput: getMultilineInputMock,
11+
setFailed: setFailedMock
12+
}));
1013

1114
describe('keys', () => {
12-
it('should fail when package.json contains duplicate keys in dependencies', () => {
13-
validateKeys(dupedPackageJson, 'test/fixtures/duped-package.json');
14-
expect(core.setFailed).toHaveBeenCalled();
15-
});
15+
afterEach(() => {
16+
mock.clearAllMocks();
17+
});
1618

17-
it('should fail when package.json contains duplicate keys in scripts', () => {
18-
validateKeys(dupedScriptsPackageJson, 'test/fixtures/duped-scripts-package.json');
19-
expect(core.setFailed).toHaveBeenCalled();
20-
});
19+
it('should fail when package.json contains duplicate keys in dependencies', () => {
20+
validateKeys(dupedPackageJson, 'test/fixtures/duped-package.json');
21+
expect(setFailedMock).toHaveBeenCalled();
22+
});
2123

22-
it('should not fail when package.json contains no duplicate keys or scripts', () => {
23-
validateKeys(dedupedPackageJson, 'test/fixtures/deduped-package.json');
24-
expect(core.setFailed).not.toHaveBeenCalled();
25-
});
24+
it('should fail when package.json contains duplicate keys in scripts', () => {
25+
validateKeys(dupedScriptsPackageJson, 'test/fixtures/duped-scripts-package.json');
26+
expect(setFailedMock).toHaveBeenCalled();
27+
});
28+
29+
it('should not fail when package.json contains no duplicate keys or scripts', () => {
30+
validateKeys(dedupedPackageJson, 'test/fixtures/deduped-package.json');
31+
expect(setFailedMock).not.toHaveBeenCalled();
32+
});
2633
});

0 commit comments

Comments
 (0)