Skip to content

Commit

Permalink
chore(gatsby): convert tests to typescript (#24235)
Browse files Browse the repository at this point in the history
* Convert pages reducer test

* Convert status reducer tests

* Update snaps

* Convert redirects tests

* Update snaps
  • Loading branch information
Kornil authored May 20, 2020
1 parent 81a3181 commit 57ca573
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { readFile } from "fs-extra"

jest.mock(`fs-extra`, () => {
return {
readFile: jest.fn(() => `contents`),
}
})
const glob = require(`glob`)
import glob from "glob"

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

afterEach(() => {
readFile.mockClear()
;(readFile as jest.Mock).mockClear()
})

Date.now = jest.fn(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { actions } = require(`../actions`)
const { store } = require(`../index`)
import { actions } from "../actions"
import { store } from "../index"

jest.mock(`../index`, () => {
return {
store: {
getState: jest.fn(),
},
dispath: () => {},
dispath: (): void => {},
emitter: {
on: jest.fn(),
},
Expand All @@ -23,7 +23,9 @@ const protocolArr = [

describe(`Add redirects`, () => {
beforeEach(() => {
store.getState.mockReturnValue({ program: { pathPrefixs: false } })
;(store.getState as jest.Mock).mockReturnValue({
program: { pathPrefixs: false },
})
})

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

describe(`Add redirects with path prefixs`, () => {
beforeEach(() => {
store.getState.mockReturnValue({
;(store.getState as jest.Mock).mockReturnValue({
program: {
prefixPaths: true,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { statusReducer } from "../reducers/status"
import { IGatsbyState } from "../types"

const { actions } = require(`../actions`)
import { actions } from "../actions"

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

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

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

it(`throws an error if the plugin name isn't set`, done => {
function runReducer() {
function runReducer(): IGatsbyState["status"] {
return statusReducer(
undefined,
actions.setPluginStatus({ blah: `test job` })
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface IGatsbyPlugin {
id: Identifier
name: string
version: string
[key: string]: any
}

export interface IGatsbyPluginContext {
Expand Down

0 comments on commit 57ca573

Please sign in to comment.