Skip to content

Commit 57ca573

Browse files
authored
chore(gatsby): convert tests to typescript (#24235)
* Convert pages reducer test * Convert status reducer tests * Update snaps * Convert redirects tests * Update snaps
1 parent 81a3181 commit 57ca573

File tree

7 files changed

+18
-13
lines changed

7 files changed

+18
-13
lines changed

packages/gatsby/src/redux/__tests__/pages.js packages/gatsby/src/redux/__tests__/pages.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import { readFile } from "fs-extra"
2+
13
jest.mock(`fs-extra`, () => {
24
return {
35
readFile: jest.fn(() => `contents`),
46
}
57
})
6-
const glob = require(`glob`)
8+
import glob from "glob"
79

8-
const { pagesReducer: reducer } = require(`../reducers/pages`)
9-
const { actions } = require(`../actions`)
10-
const { readFile } = require(`fs-extra`)
10+
import { pagesReducer as reducer } from "../reducers/pages"
11+
import { actions } from "../actions"
1112

1213
afterEach(() => {
13-
readFile.mockClear()
14+
;(readFile as jest.Mock).mockClear()
1415
})
1516

1617
Date.now = jest.fn(

packages/gatsby/src/redux/__tests__/redirects.js packages/gatsby/src/redux/__tests__/redirects.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const { actions } = require(`../actions`)
2-
const { store } = require(`../index`)
1+
import { actions } from "../actions"
2+
import { store } from "../index"
33

44
jest.mock(`../index`, () => {
55
return {
66
store: {
77
getState: jest.fn(),
88
},
9-
dispath: () => {},
9+
dispath: (): void => {},
1010
emitter: {
1111
on: jest.fn(),
1212
},
@@ -23,7 +23,9 @@ const protocolArr = [
2323

2424
describe(`Add redirects`, () => {
2525
beforeEach(() => {
26-
store.getState.mockReturnValue({ program: { pathPrefixs: false } })
26+
;(store.getState as jest.Mock).mockReturnValue({
27+
program: { pathPrefixs: false },
28+
})
2729
})
2830

2931
it(`allows you to add redirects`, () => {
@@ -79,7 +81,7 @@ describe(`Add redirects`, () => {
7981

8082
describe(`Add redirects with path prefixs`, () => {
8183
beforeEach(() => {
82-
store.getState.mockReturnValue({
84+
;(store.getState as jest.Mock).mockReturnValue({
8385
program: {
8486
prefixPaths: true,
8587
},

packages/gatsby/src/redux/__tests__/status.js packages/gatsby/src/redux/__tests__/status.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { statusReducer } from "../reducers/status"
2+
import { IGatsbyState } from "../types"
23

3-
const { actions } = require(`../actions`)
4+
import { actions } from "../actions"
45

56
Date.now = jest.fn(() => 1482363367071)
67

@@ -24,7 +25,7 @@ describe(`Status actions/reducer`, () => {
2425
})
2526

2627
it(`throws an error if status isn't an object`, done => {
27-
function runReducer() {
28+
function runReducer(): IGatsbyState["status"] {
2829
return statusReducer(
2930
undefined,
3031
actions.setPluginStatus(`test job`, { name: `test-plugin` })
@@ -36,7 +37,7 @@ describe(`Status actions/reducer`, () => {
3637
})
3738

3839
it(`throws an error if the plugin name isn't set`, done => {
39-
function runReducer() {
40+
function runReducer(): IGatsbyState["status"] {
4041
return statusReducer(
4142
undefined,
4243
actions.setPluginStatus({ blah: `test job` })

packages/gatsby/src/redux/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface IGatsbyPlugin {
8181
id: Identifier
8282
name: string
8383
version: string
84+
[key: string]: any
8485
}
8586

8687
export interface IGatsbyPluginContext {

0 commit comments

Comments
 (0)