diff --git a/packages/gatsby/src/redux/__tests__/__snapshots__/pages.js.snap b/packages/gatsby/src/redux/__tests__/__snapshots__/pages.ts.snap similarity index 100% rename from packages/gatsby/src/redux/__tests__/__snapshots__/pages.js.snap rename to packages/gatsby/src/redux/__tests__/__snapshots__/pages.ts.snap diff --git a/packages/gatsby/src/redux/__tests__/__snapshots__/redirects.js.snap b/packages/gatsby/src/redux/__tests__/__snapshots__/redirects.ts.snap similarity index 100% rename from packages/gatsby/src/redux/__tests__/__snapshots__/redirects.js.snap rename to packages/gatsby/src/redux/__tests__/__snapshots__/redirects.ts.snap diff --git a/packages/gatsby/src/redux/__tests__/__snapshots__/status.js.snap b/packages/gatsby/src/redux/__tests__/__snapshots__/status.ts.snap similarity index 100% rename from packages/gatsby/src/redux/__tests__/__snapshots__/status.js.snap rename to packages/gatsby/src/redux/__tests__/__snapshots__/status.ts.snap diff --git a/packages/gatsby/src/redux/__tests__/pages.js b/packages/gatsby/src/redux/__tests__/pages.ts similarity index 95% rename from packages/gatsby/src/redux/__tests__/pages.js rename to packages/gatsby/src/redux/__tests__/pages.ts index b69f64b4a6153..e81ca9758236f 100644 --- a/packages/gatsby/src/redux/__tests__/pages.js +++ b/packages/gatsby/src/redux/__tests__/pages.ts @@ -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( diff --git a/packages/gatsby/src/redux/__tests__/redirects.js b/packages/gatsby/src/redux/__tests__/redirects.ts similarity index 92% rename from packages/gatsby/src/redux/__tests__/redirects.js rename to packages/gatsby/src/redux/__tests__/redirects.ts index 35c982055328d..26256c779c0ef 100644 --- a/packages/gatsby/src/redux/__tests__/redirects.js +++ b/packages/gatsby/src/redux/__tests__/redirects.ts @@ -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(), }, @@ -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`, () => { @@ -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, }, diff --git a/packages/gatsby/src/redux/__tests__/status.js b/packages/gatsby/src/redux/__tests__/status.ts similarity index 86% rename from packages/gatsby/src/redux/__tests__/status.js rename to packages/gatsby/src/redux/__tests__/status.ts index 67fef98915510..d0c825eb28893 100644 --- a/packages/gatsby/src/redux/__tests__/status.js +++ b/packages/gatsby/src/redux/__tests__/status.ts @@ -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) @@ -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` }) @@ -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` }) diff --git a/packages/gatsby/src/redux/types.ts b/packages/gatsby/src/redux/types.ts index ae1c509bfc008..e862515b28718 100644 --- a/packages/gatsby/src/redux/types.ts +++ b/packages/gatsby/src/redux/types.ts @@ -81,6 +81,7 @@ export interface IGatsbyPlugin { id: Identifier name: string version: string + [key: string]: any } export interface IGatsbyPluginContext {