Skip to content

Commit 3ea9235

Browse files
authored
chore: replace jest with bun test runner (#452)
* chore: replace jest with bun test runner * fix build
1 parent 8cbbb03 commit 3ea9235

9 files changed

+39
-743
lines changed

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 `yarn 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: 15 additions & 700 deletions
Large diffs are not rendered by default.

eslint.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ module.exports = [
2222
"@typescript-eslint/no-namespace": "off",
2323
"@typescript-eslint/no-non-null-assertion": "error",
2424
"@typescript-eslint/no-unsafe-argument": "error",
25-
"@typescript-eslint/no-unsafe-call": "error",
2625
},
2726
},
2827
{

package.json

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@
3030
"cypress": ">=13"
3131
},
3232
"devDependencies": {
33-
"@swc/jest": "0.2.39",
3433
"@total-typescript/ts-reset": "0.6.1",
34+
"@types/babel__generator": "7.27.0",
35+
"@types/bun": "1.3.1",
3536
"@types/react": "19.2.2",
36-
"@types/jest": "30.0.0",
3737
"@types/node": "24.9.2",
3838
"cypress": "15.5.0",
3939
"husky": "9.1.7",
40-
"jest": "30.2.0",
4140
"eslint": "9.39.0",
4241
"eslint-plugin-cypress": "5.2.0",
4342
"react": "19.2.0",
@@ -57,20 +56,6 @@
5756
"lint": "eslint .",
5857
"prepack": "bun run build",
5958
"prepare": "husky",
60-
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
61-
},
62-
"jest": {
63-
"transform": {
64-
"^.+\\.(t|j)sx?$": [
65-
"@swc/jest",
66-
{
67-
"jsc": {
68-
"target": "esnext"
69-
}
70-
}
71-
]
72-
},
73-
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
74-
"clearMocks": true
59+
"test": "bun test"
7560
}
7661
}

test/generate-content-with-exports.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ limitations under the License.
1212
*/
1313

1414
import { generateContentWithExports } from "../src/generate-content-with-exports";
15-
import { expect } from "@jest/globals";
15+
import { describe, expect, it } from "bun:test";
1616

1717
const filePaths = [
1818
"cypress/commands/file/path/1.tsx",

test/generate-content-with-imports.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
1313

14-
import { readFileSync } from "fs";
1514
import { generateContentWithImports } from "../src/generate-content-with-imports";
15+
import { describe, expect, it, mock } from "bun:test";
1616

17-
jest.mock("fs");
18-
import { expect } from "@jest/globals";
17+
const readFileSyncMock = mock();
18+
mock.module("fs", () => ({
19+
readFileSync: readFileSyncMock,
20+
}));
1921

2022
const filePath = "filePath";
2123
const prettierConfig = {
@@ -25,7 +27,7 @@ const prettierConfig = {
2527

2628
describe("generateContentWithImports", () => {
2729
it("should generate types when types do not exist", async () => {
28-
(readFileSync as jest.Mock).mockReturnValue(`// some comment
30+
readFileSyncMock.mockReturnValue(`// some comment
2931
3032
import { mount } from 'cypress/react18';
3133
@@ -68,7 +70,7 @@ import('../commands').then(Cypress.Commands.addAll);
6870
});
6971

7072
it("should do nothing when types exist", async () => {
71-
(readFileSync as jest.Mock).mockReturnValue(`// some comment
73+
readFileSyncMock.mockReturnValue(`// some comment
7274
7375
import { mount } from 'cypress/react18';
7476

test/generate-contents-with-interface.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ limitations under the License.
1212
*/
1313

1414
import { generateContentsWithInterface } from "../src/generate-contents-with-interface";
15-
import { readFileSync } from "fs";
16-
import { expect } from "@jest/globals";
15+
import { describe, expect, it, mock } from "bun:test";
1716

18-
jest.mock("fs");
17+
const readFileSyncMock = mock();
18+
mock.module("fs", () => ({
19+
readFileSync: readFileSyncMock,
20+
}));
1921

2022
const filePath = "filePath";
2123
const prettierConfig = {
@@ -25,7 +27,7 @@ const prettierConfig = {
2527

2628
describe("generateContentsWithInterface", () => {
2729
it("should generate types when types do not exist", async () => {
28-
(readFileSync as jest.Mock).mockReturnValue(`// some comment
30+
readFileSyncMock.mockReturnValue(`// some comment
2931
3032
export function functionExampleOneInput(input1: string) {
3133
cy.log('Here is a custom command!');
@@ -89,7 +91,7 @@ declare global {
8991
});
9092

9193
it("should generate types when types exist", async () => {
92-
(readFileSync as jest.Mock).mockReturnValue(`// some comment
94+
readFileSyncMock.mockReturnValue(`// some comment
9395
9496
export function functionExampleOneInput(input1: string) {
9597
cy.log('Here is a custom command!');
@@ -163,7 +165,7 @@ declare global {
163165
});
164166

165167
it("should preserve formatting", async () => {
166-
(readFileSync as jest.Mock).mockReturnValue(`// some comment
168+
readFileSyncMock.mockReturnValue(`// some comment
167169
168170
export function functionExampleOneInput(input1: string) {
169171
cy.log('Here is a custom command!')
@@ -231,7 +233,7 @@ declare global {
231233
});
232234

233235
it("should handle generic types properly", async () => {
234-
(readFileSync as jest.Mock).mockReturnValue(`// some comment
236+
readFileSyncMock.mockReturnValue(`// some comment
235237
236238
export function functionExampleGenericType(input1: string) {
237239
cy.log<GenericType>('Here is a generic type!');
@@ -259,7 +261,7 @@ declare global {
259261
});
260262

261263
it("should throw error for object-destructured input", async () => {
262-
(readFileSync as jest.Mock).mockReturnValue(`
264+
readFileSyncMock.mockReturnValue(`
263265
export const objectDestructureExample = ({ input1, input2 }: { input1: string; input2: string }) => {
264266
cy.log(input1);
265267
cy.log(input2);
@@ -271,7 +273,7 @@ export const objectDestructureExample = ({ input1, input2 }: { input1: string; i
271273
});
272274

273275
it("should handle file with only exports", async () => {
274-
(readFileSync as jest.Mock).mockReturnValue(`export * from './some-file';
276+
readFileSyncMock.mockReturnValue(`export * from './some-file';
275277
export * from './some-other-file';
276278
`);
277279
const result = await generateContentsWithInterface(

test/tsconfig.json

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

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"lib": ["ESNext", "DOM"],
77
"jsx": "react",
88
"skipLibCheck": true,
9-
"types": ["cypress", "jest"],
9+
"types": ["bun", "cypress"],
1010
"noEmit": true,
1111
"noImplicitAny": true,
1212
"noUncheckedIndexedAccess": true,

0 commit comments

Comments
 (0)