Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 7fe260e

Browse files
authored
chore: Replace Jest with Vitest (#23)
1 parent d032fe1 commit 7fe260e

File tree

10 files changed

+522
-1760
lines changed

10 files changed

+522
-1760
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
${{ runner.os }}-yarn-
1818
- name: Install dependencies
1919
run: yarn --immutable
20-
- name: Run Jest
20+
- name: Run Vitest
2121
run: yarn test:ci

jest.config.js

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

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"eslint-plugin-react": "^7.29.4",
2727
"eslint-plugin-react-hooks": "^4.3.0",
2828
"husky": "^7.0.4",
29-
"jest": "^27.5.1",
3029
"lint-staged": "^12.3.7",
3130
"prettier": "^2.6.1",
32-
"ts-jest": "^27.1.4",
33-
"typescript": "^4.6.3"
31+
"typescript": "^4.6.3",
32+
"vite": "^2.8.6",
33+
"vitest": "^0.8.0"
3434
},
3535
"scripts": {
3636
"develop": "yarn workspace example develop",
@@ -42,9 +42,8 @@
4242
"lint": "eslint . --ignore-path .gitignore --ignore-path .prettierignore --ext .ts,.tsx,.js",
4343
"lint:fix": "yarn lint --fix",
4444
"format": "prettier \"**/*.{md,mdx,json,yaml}\" --write",
45-
"test": "jest",
46-
"test:watch": "jest --watch",
47-
"test:ci": "jest --ci --runInBand",
45+
"test:watch": "vitest watch",
46+
"test:ci": "vitest run",
4847
"changeset": "changeset",
4948
"release": "changeset publish",
5049
"release-update-lockfile": "changeset version && yarn install --mode update-lockfile",

package/src/__tests__/__snapshots__/node-builder.ts.snap

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1
22

3-
exports[`imageTransformation in nodeBuilder should convert nodes one level deep 1`] = `
4-
Object {
5-
"backdrop_path": Object {
3+
exports[`imageTransformation in nodeBuilder > should convert nodes one level deep 1`] = `
4+
{
5+
"backdrop_path": {
66
"original": "https://image.tmdb.org/t/p/original/backdrop_image.png",
77
"source": "/backdrop_image.png",
88
"w1280": "https://image.tmdb.org/t/p/w1280/backdrop_image.png",
99
"w300": "https://image.tmdb.org/t/p/w300/backdrop_image.png",
1010
"w780": "https://image.tmdb.org/t/p/w780/backdrop_image.png",
1111
},
1212
"id": 1,
13-
"logo_path": Object {
13+
"logo_path": {
1414
"original": "https://image.tmdb.org/t/p/original/logo_image.png",
1515
"source": "/logo_image.png",
1616
"w154": "https://image.tmdb.org/t/p/w154/logo_image.png",
@@ -20,7 +20,7 @@ Object {
2020
"w500": "https://image.tmdb.org/t/p/w500/logo_image.png",
2121
"w92": "https://image.tmdb.org/t/p/w92/logo_image.png",
2222
},
23-
"poster_path": Object {
23+
"poster_path": {
2424
"original": "https://image.tmdb.org/t/p/original/poster_image.png",
2525
"source": "/poster_image.png",
2626
"w154": "https://image.tmdb.org/t/p/w154/poster_image.png",
@@ -30,14 +30,14 @@ Object {
3030
"w780": "https://image.tmdb.org/t/p/w780/poster_image.png",
3131
"w92": "https://image.tmdb.org/t/p/w92/poster_image.png",
3232
},
33-
"profile_path": Object {
33+
"profile_path": {
3434
"h632": "https://image.tmdb.org/t/p/h632/profile_image.png",
3535
"original": "https://image.tmdb.org/t/p/original/profile_image.png",
3636
"source": "/profile_image.png",
3737
"w185": "https://image.tmdb.org/t/p/w185/profile_image.png",
3838
"w45": "https://image.tmdb.org/t/p/w45/profile_image.png",
3939
},
40-
"still_path": Object {
40+
"still_path": {
4141
"original": "https://image.tmdb.org/t/p/original/still_image.png",
4242
"source": "/still_image.png",
4343
"w185": "https://image.tmdb.org/t/p/w185/still_image.png",
@@ -48,19 +48,19 @@ Object {
4848
}
4949
`;
5050

51-
exports[`imageTransformation in nodeBuilder should convert nodes two levels deep 1`] = `
52-
Object {
51+
exports[`imageTransformation in nodeBuilder > should convert nodes two levels deep 1`] = `
52+
{
5353
"id": 3,
54-
"items": Array [
55-
Object {
56-
"backdrop_path": Object {
54+
"items": [
55+
{
56+
"backdrop_path": {
5757
"original": "https://image.tmdb.org/t/p/original/backdrop_image.png",
5858
"source": "/backdrop_image.png",
5959
"w1280": "https://image.tmdb.org/t/p/w1280/backdrop_image.png",
6060
"w300": "https://image.tmdb.org/t/p/w300/backdrop_image.png",
6161
"w780": "https://image.tmdb.org/t/p/w780/backdrop_image.png",
6262
},
63-
"logo_path": Object {
63+
"logo_path": {
6464
"original": "https://image.tmdb.org/t/p/original/logo_image.png",
6565
"source": "/logo_image.png",
6666
"w154": "https://image.tmdb.org/t/p/w154/logo_image.png",
@@ -71,8 +71,8 @@ Object {
7171
"w92": "https://image.tmdb.org/t/p/w92/logo_image.png",
7272
},
7373
},
74-
Object {
75-
"poster_path": Object {
74+
{
75+
"poster_path": {
7676
"original": "https://image.tmdb.org/t/p/original/poster_image.png",
7777
"source": "/poster_image.png",
7878
"w154": "https://image.tmdb.org/t/p/w154/poster_image.png",
@@ -82,14 +82,14 @@ Object {
8282
"w780": "https://image.tmdb.org/t/p/w780/poster_image.png",
8383
"w92": "https://image.tmdb.org/t/p/w92/poster_image.png",
8484
},
85-
"profile_path": Object {
85+
"profile_path": {
8686
"h632": "https://image.tmdb.org/t/p/h632/profile_image.png",
8787
"original": "https://image.tmdb.org/t/p/original/profile_image.png",
8888
"source": "/profile_image.png",
8989
"w185": "https://image.tmdb.org/t/p/w185/profile_image.png",
9090
"w45": "https://image.tmdb.org/t/p/w45/profile_image.png",
9191
},
92-
"still_path": Object {
92+
"still_path": {
9393
"original": "https://image.tmdb.org/t/p/original/still_image.png",
9494
"source": "/still_image.png",
9595
"w185": "https://image.tmdb.org/t/p/w185/still_image.png",
@@ -102,9 +102,9 @@ Object {
102102
}
103103
`;
104104

105-
exports[`imageTransformation in nodeBuilder with downloadImages set in endpoint should convert nodes one level deep 1`] = `
106-
Object {
107-
"backdrop_path": Object {
105+
exports[`imageTransformation in nodeBuilder > with downloadImages > set in endpoint should convert nodes one level deep 1`] = `
106+
{
107+
"backdrop_path": {
108108
"localFile": "local-file-node-id",
109109
"original": "https://image.tmdb.org/t/p/original/backdrop_image.png",
110110
"source": "/backdrop_image.png",
@@ -117,12 +117,12 @@ Object {
117117
}
118118
`;
119119

120-
exports[`imageTransformation in nodeBuilder with downloadImages set in endpoint should convert nodes two levels deep 1`] = `
121-
Object {
120+
exports[`imageTransformation in nodeBuilder > with downloadImages > set in endpoint should convert nodes two levels deep 1`] = `
121+
{
122122
"id": 4,
123-
"items": Array [
124-
Object {
125-
"backdrop_path": Object {
123+
"items": [
124+
{
125+
"backdrop_path": {
126126
"localFile": "local-file-node-id",
127127
"original": "https://image.tmdb.org/t/p/original/backdrop_image.png",
128128
"source": "/backdrop_image.png",
@@ -136,9 +136,9 @@ Object {
136136
}
137137
`;
138138

139-
exports[`imageTransformation in nodeBuilder with downloadImages set in pluginOptions should convert nodes one level deep 1`] = `
140-
Object {
141-
"backdrop_path": Object {
139+
exports[`imageTransformation in nodeBuilder > with downloadImages > set in pluginOptions should convert nodes one level deep 1`] = `
140+
{
141+
"backdrop_path": {
142142
"localFile": "local-file-node-id",
143143
"original": "https://image.tmdb.org/t/p/original/backdrop_image.png",
144144
"source": "/backdrop_image.png",
@@ -151,12 +151,12 @@ Object {
151151
}
152152
`;
153153

154-
exports[`imageTransformation in nodeBuilder with downloadImages set in pluginOptions should convert nodes two levels deep 1`] = `
155-
Object {
154+
exports[`imageTransformation in nodeBuilder > with downloadImages > set in pluginOptions should convert nodes two levels deep 1`] = `
155+
{
156156
"id": 4,
157-
"items": Array [
158-
Object {
159-
"backdrop_path": Object {
157+
"items": [
158+
{
159+
"backdrop_path": {
160160
"localFile": "local-file-node-id",
161161
"original": "https://image.tmdb.org/t/p/original/backdrop_image.png",
162162
"source": "/backdrop_image.png",

package/src/__tests__/api-utils.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from "vitest"
12
import { modifyURL, getParam, defaultOptions } from "../api-utils"
23

34
const endpoint01 = `configuration`
@@ -44,40 +45,40 @@ describe(`api-utils`, () => {
4445
describe(`defaultOptions`, () => {
4546
it(`should return defaults with no additional input`, () => {
4647
expect(defaultOptions({ apiKey: `foo`, sessionID: `bar`, plugins: [] })).toMatchInlineSnapshot(`
47-
Object {
48+
{
4849
"apiKey": "foo",
4950
"downloadImages": false,
50-
"endpoints": Array [
51-
Object {
51+
"endpoints": [
52+
{
5253
"url": "account/:account_id/lists",
5354
},
54-
Object {
55+
{
5556
"url": "account/:account_id/favorite/movies",
5657
},
57-
Object {
58+
{
5859
"url": "account/:account_id/favorite/tv",
5960
},
60-
Object {
61+
{
6162
"url": "account/:account_id/watchlist/movies",
6263
},
63-
Object {
64+
{
6465
"url": "account/:account_id/watchlist/tv",
6566
},
66-
Object {
67+
{
6768
"url": "movie/popular",
6869
},
69-
Object {
70+
{
7071
"url": "movie/top_rated",
7172
},
72-
Object {
73+
{
7374
"url": "tv/popular",
7475
},
75-
Object {
76+
{
7677
"url": "tv/top_rated",
7778
},
7879
],
7980
"language": undefined,
80-
"plugins": Array [],
81+
"plugins": [],
8182
"region": undefined,
8283
"sessionID": "bar",
8384
"timezone": undefined,
@@ -99,17 +100,17 @@ describe(`api-utils`, () => {
99100
endpoints: [{ url: `/tv/:tv_id`, downloadImages: true }],
100101
})
101102
).toMatchInlineSnapshot(`
102-
Object {
103+
{
103104
"apiKey": "foo",
104105
"downloadImages": true,
105-
"endpoints": Array [
106-
Object {
106+
"endpoints": [
107+
{
107108
"downloadImages": true,
108109
"url": "/tv/:tv_id",
109110
},
110111
],
111112
"language": "en-GB",
112-
"plugins": Array [],
113+
"plugins": [],
113114
"region": "GB",
114115
"sessionID": "bar",
115116
"timezone": "Europe/Berlin",

package/src/__tests__/node-builder.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect, vi } from "vitest"
12
import { SourceNodesArgs } from "gatsby"
23
import { createNodeHelpers } from "gatsby-node-helpers"
34
import { createRemoteFileNode } from "gatsby-source-filesystem"
@@ -20,31 +21,31 @@ const nodeHelpers = createNodeHelpers({
2021
createContentDigest: (input) => input.toString(),
2122
})
2223

23-
jest.mock(`gatsby-source-filesystem`, () => ({
24-
createRemoteFileNode: jest.fn().mockResolvedValue({
24+
vi.mock(`gatsby-source-filesystem`, () => ({
25+
createRemoteFileNode: vi.fn().mockResolvedValue({
2526
id: `local-file-node-id`,
2627
}),
2728
}))
2829

2930
const gatsbyApi = {
3031
cache: {
31-
set: jest.fn(),
32-
get: jest.fn(),
32+
set: vi.fn(),
33+
get: vi.fn(),
3334
},
3435
actions: {
35-
createNode: jest.fn(),
36+
createNode: vi.fn(),
3637
},
37-
createContentDigest: jest.fn(),
38-
createNodeId: jest.fn(),
39-
store: jest.fn(),
38+
createContentDigest: vi.fn(),
39+
createNodeId: vi.fn(),
40+
store: vi.fn(),
4041
reporter: {
41-
info: jest.fn(),
42-
error: jest.fn(),
43-
panic: jest.fn(),
42+
info: vi.fn(),
43+
error: vi.fn(),
44+
panic: vi.fn(),
4445
activityTimer: (): Record<string, unknown> => ({
45-
start: jest.fn(),
46-
end: jest.fn(),
47-
setStatus: jest.fn(),
46+
start: vi.fn(),
47+
end: vi.fn(),
48+
setStatus: vi.fn(),
4849
}),
4950
},
5051
} as unknown as SourceNodesArgs
@@ -74,7 +75,7 @@ describe(`imageTransformation in nodeBuilder`, () => {
7475
gatsbyApi,
7576
})
7677
expect(result).toMatchSnapshot()
77-
const mock = createRemoteFileNode as jest.Mock
78+
const mock = createRemoteFileNode
7879
expect(mock).not.toHaveBeenCalled()
7980
})
8081
it(`should convert nodes two levels deep`, async () => {
@@ -113,7 +114,7 @@ describe(`imageTransformation in nodeBuilder`, () => {
113114
gatsbyApi,
114115
})
115116
expect(result).toMatchSnapshot()
116-
const mock = createRemoteFileNode as jest.Mock
117+
const mock = createRemoteFileNode
117118
expect(mock).toHaveBeenCalled()
118119
})
119120
it(`set in endpoint should convert nodes two levels deep`, async () => {

package/src/__tests__/plugin-options-schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from "vitest"
12
import { testPluginOptionsSchema } from "gatsby-plugin-utils"
23
import { pluginOptionsSchema } from "../plugin-options-schema"
34

package/src/__tests__/schema-utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect, vi } from "vitest"
12
import { NodePluginSchema } from "gatsby"
23
import {
34
generateTypeName,
@@ -9,7 +10,7 @@ import {
910
} from "../schema-utils"
1011

1112
const schema = {
12-
buildObjectType: jest.fn().mockImplementation(({ name, fields }) => ({
13+
buildObjectType: vi.fn().mockImplementation(({ name, fields }) => ({
1314
name,
1415
fields,
1516
})),

vite.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference types="vitest" />
2+
3+
import { defineConfig } from "vite"
4+
5+
export default defineConfig({
6+
test: {
7+
include: [`**/__tests__/*.ts`],
8+
},
9+
})

0 commit comments

Comments
 (0)