Skip to content

Commit 37386d3

Browse files
committed
add jest to the mix, handle gatsby config files
1 parent f17be99 commit 37386d3

File tree

15 files changed

+107
-64
lines changed

15 files changed

+107
-64
lines changed

.eslintignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
node_modules
22

33
## babel, jest, prettier
4-
*.config.js
5-
6-
## test files
7-
*.test.js
4+
*.config.js

.eslintrc.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,52 @@
11
module.exports = {
22
root: true,
33
parser: '@typescript-eslint/parser',
4-
plugins: ['@typescript-eslint'],
54
extends: [
65
'eslint:recommended',
76
'plugin:prettier/recommended',
8-
'plugin:@typescript-eslint/eslint-recommended',
9-
'plugin:@typescript-eslint/recommended',
107
],
11-
rules: {
12-
'@typescript-eslint/no-explicit-any': 0,
13-
'@typescript-eslint/member-delimiter-style': 0,
14-
'@typescript-eslint/interface-name-prefix': 0,
15-
}
8+
overrides: [
9+
// typescript
10+
{
11+
files: ["*.ts", "*.tsx"],
12+
excludedFiles: ["*.test.js", "gatsby-node.js", "gatsby-config.js"],
13+
plugins: ['@typescript-eslint'],
14+
extends: [
15+
'plugin:@typescript-eslint/eslint-recommended',
16+
'plugin:@typescript-eslint/recommended',
17+
],
18+
rules: {
19+
'@typescript-eslint/no-explicit-any': 0,
20+
'@typescript-eslint/member-delimiter-style': 0,
21+
'@typescript-eslint/interface-name-prefix': 0,
22+
'@typescript-eslint/no-use-before-define': 0,
23+
},
24+
},
25+
26+
// gatsby config files
27+
{
28+
files: ["gatsby-node.js", "gatsby-config.js"],
29+
env: {
30+
"node": true,
31+
}
32+
},
33+
34+
// test files
35+
{
36+
files: ["*.test.js"],
37+
plugins: ['jest'],
38+
env: {
39+
"es6": true,
40+
"node": true,
41+
"jest/globals": true,
42+
},
43+
extends: [
44+
"plugin:jest/recommended"
45+
]
46+
parserOptions: {
47+
ecmaVersion: 2019,
48+
sourceType: "module",
49+
}
50+
}
51+
],
1652
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@typescript-eslint/parser": "^2.19.0",
2525
"eslint": "^6.8.0",
2626
"eslint-config-prettier": "^6.10.0",
27+
"eslint-plugin-jest": "^23.7.0",
2728
"eslint-plugin-prettier": "^3.1.2",
2829
"jest": "^25.1.0",
2930
"lerna": "^3.16.4",

packages/gatsby-plugin-graphql-codegen/src/gatsby-node.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { generateWithConfig } from './graphql-codegen.config'
33

44
jest.mock('./graphql-codegen.config', () => ({ generateWithConfig: jest.fn() }))
55

6-
const delay = (milliseconds) =>
7-
new Promise((resolve) => setTimeout(resolve, milliseconds))
6+
const delay = milliseconds =>
7+
new Promise(resolve => setTimeout(resolve, milliseconds))
88

99
it('early returns if the codegen option is false', async () => {
1010
const mockGetState = jest.fn()
@@ -156,7 +156,7 @@ it('subscribes to the store and debounces the `build` function', async () => {
156156
const mockGatsbyArgs = {
157157
store: {
158158
getState: () => mockState,
159-
subscribe: (listener) => {
159+
subscribe: listener => {
160160
notify = listener
161161
},
162162
},
@@ -210,7 +210,7 @@ it("doesn't call build if the `lastAction.type` isn't 'REPLACE_STATIC_QUERY' or
210210
const mockGatsbyArgs = {
211211
store: {
212212
getState: () => mockState,
213-
subscribe: (listener) => {
213+
subscribe: listener => {
214214
notify = listener
215215
},
216216
},

packages/gatsby-plugin-ts/src/gatsby-node.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jest.mock(
1111
constructor(options) {
1212
this.options = options
1313
}
14-
},
14+
}
1515
)
1616

1717
jest.mock('./require-resolve', () => () => 'mock-resolved.ts')

packages/gatsby-starter-blog-ts/gatsby-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = {
5252
options: {
5353
typeCheck: process.env.NODE_ENV !== 'production',
5454
fileName: `gen/graphql-types.ts`,
55-
}
55+
},
5656
},
5757
// `gatsby-plugin-typescript`,
5858
// `gatsby-plugin-graphql-codegen`,

packages/gatsby-starter-blog-ts/src/components/bio.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* See: https://www.gatsbyjs.org/docs/static-query/
66
*/
77

8-
import React from "react"
9-
import { StaticQuery, graphql } from "gatsby"
10-
import Image from "gatsby-image"
8+
import * as React from 'react'
9+
import { StaticQuery, graphql } from 'gatsby'
10+
import Image from 'gatsby-image'
1111

12-
import { rhythm } from "../utils/typography"
12+
import { rhythm } from '../utils/typography'
1313

1414
function Bio() {
1515
return (

packages/gatsby-starter-blog-ts/src/components/layout.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React from "react"
2-
import { Link } from "gatsby"
1+
import React from 'react'
2+
import { Link } from 'gatsby'
33

4-
import { rhythm, scale } from "../utils/typography"
4+
import { rhythm, scale } from '../utils/typography'
55

66
interface ILayoutProps {
7-
location: Location;
8-
title: string;
7+
location: Location
8+
title: string
99
}
1010

1111
class Layout extends React.Component<ILayoutProps> {

packages/gatsby-starter-blog-ts/src/components/seo.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* See: https://www.gatsbyjs.org/docs/use-static-query/
66
*/
77

8-
import React from "react"
9-
import PropTypes from "prop-types"
10-
import Helmet from "react-helmet"
11-
import { useStaticQuery, graphql } from "gatsby"
8+
import React from 'react'
9+
import PropTypes from 'prop-types'
10+
import Helmet from 'react-helmet'
11+
import { useStaticQuery, graphql } from 'gatsby'
1212

1313
function SEO({ description, lang, meta, title }) {
1414
const { site } = useStaticQuery(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
declare const __PATH_PREFIX__: string
1+
declare const __PATH_PREFIX__: string

0 commit comments

Comments
 (0)