Skip to content

Commit

Permalink
Merge pull request #85 from mohatt/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mohatt authored Feb 4, 2021
2 parents 39d0be4 + 13dbbe7 commit 7b76be8
Show file tree
Hide file tree
Showing 31 changed files with 155 additions and 240 deletions.
6 changes: 0 additions & 6 deletions .babelrc

This file was deleted.

11 changes: 0 additions & 11 deletions jest.config.js

This file was deleted.

16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"scripts": {
"prepare": "cross-env NODE_ENV=production npm run build",
"prebuild": "rimraf 'dist/*'",
"build": "babel src --out-dir dist --copy-files --ignore '**/__tests__,**/*.test.js'",
"build": "babel src --out-dir dist --copy-files --ignore '**/__tests__,**/*.test.js,**/*.fragment.js'",
"postbuild": "rimraf 'dist/**/__tests__' 'dist/**/*.test.js'",
"watch": "babel -w src --out-dir dist --copy-files --ignore '**/__tests__,**/*.test.js'",
"watch": "babel -w src --out-dir dist --copy-files --ignore '**/__tests__,**/*.test.js,**/*.fragment.js'",
"test": "jest --runInBand",
"test:coverage": "jest --runInBand --coverage",
"test:watch": "jest --watch --runInBand",
Expand Down Expand Up @@ -74,6 +74,18 @@
"engines": {
"node": ">=10.13.0"
},
"jest": {
"roots": [
"<rootDir>/test/",
"<rootDir>/src/"
],
"testPathIgnorePatterns": [
"/__tests__/__fixtures__/.*$"
],
"collectCoverageFrom": [
"src/**/*.js"
]
},
"standard": {
"parser": "@babel/eslint-parser",
"env": [
Expand Down
7 changes: 7 additions & 0 deletions src/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [
["babel-preset-gatsby-package", {
"browser": true
}]
]
}
File renamed without changes.
9 changes: 6 additions & 3 deletions src/__tests__/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { withPrefix } from 'gatsby'
import routes from '../../test/__fixtures__/routes'
import routes from './__fixtures__/routes'
import {
getRoutes,
routeExists,
Expand All @@ -10,8 +10,11 @@ import {
generatePath
} from '../api'

// Create a virtual mock for routes.js
jest.doMock('../routes', () => routes, { virtual: true })
// Create a virtual mock for routes.json
jest.doMock(
'gatsby-plugin-advanced-pages-cache/routes.json',
() => routes, { virtual: true }
)

jest.doMock('@reach/router', () => ({
globalHistory: {
Expand Down
2 changes: 1 addition & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pick, compile } from './lib/route-compiler'

// Gets an array of all routes
export function getRoutes () {
return require('./routes')
return require('gatsby-plugin-advanced-pages-cache/routes.json')
}

// Gets a specific route
Expand Down
9 changes: 6 additions & 3 deletions src/components/Link/__tests__/Link.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react'
import TestRenderer from 'react-test-renderer'
import Link from '../Link'
import routes from '../../../../test/__fixtures__/routes'
import routes from '../../../__tests__/__fixtures__/routes'

// Create a virtual mock for routes.js
jest.doMock('../../../routes', () => routes, { virtual: true })
// Create a virtual mock for routes.json
jest.doMock(
'gatsby-plugin-advanced-pages-cache/routes.json',
() => routes, { virtual: true }
)

describe('<Link />', () => {
const render = (props = {}) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { graphql } from "gatsby"
import { graphql } from 'gatsby'

export const pagination = graphql`
export const Pagination = graphql`
fragment Pagination on PageInfo {
perPage
pageCount
Expand Down
2 changes: 1 addition & 1 deletion src/components/Pagination/__tests__/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import ShallowRenderer from 'react-test-renderer/shallow'
import { mapValues, merge } from 'lodash'
import Pagination from '../Pagination'
import testCases, { defaultTestCase } from '../../../../test/__fixtures__/pagination'
import testCases, { defaultTestCase } from './__fixtures__/pagination'

describe('<Pagination />', () => {
const render = (props = {}) => {
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions src/gatsby/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"presets": [
["babel-preset-gatsby-package", { "nodeVersion": "8" }]
["babel-preset-gatsby-package", {
"browser": false,
"nodeVersion": "10.13.0"
}]
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
throw new Error('some error')
}
helper: () => { throw new Error('some error') }
},
{
id: 'bad-helper-empty-call',
Expand All @@ -85,9 +83,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
createAdvancedPage()
}
helper: ({ createAdvancedPage }) => createAdvancedPage()
},
{
id: 'bad-helper-undefined-route',
Expand All @@ -101,11 +97,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
createAdvancedPage({
route: 'blog'
})
}
helper: ({ createAdvancedPage }) => createAdvancedPage({ route: 'blog' })
},
{
id: 'bad-helper-invalid-route-params',
Expand All @@ -119,11 +111,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
createAdvancedPage({
route: 'about'
})
}
helper: ({ createAdvancedPage }) => createAdvancedPage({ route: 'about' })
},
{
id: 'bad-helper-empty-pagination',
Expand All @@ -137,7 +125,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
helper: ({ createAdvancedPage }) => {
createAdvancedPage({
route: 'about',
pagination: {}
Expand All @@ -156,7 +144,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
helper: ({ createAdvancedPage }) => {
createAdvancedPage({
route: 'about',
pagination: {
Expand All @@ -177,7 +165,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
helper: ({ createAdvancedPage }) => {
createAdvancedPage({
route: 'about',
pagination: {
Expand All @@ -199,7 +187,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
helper: ({ createAdvancedPage }) => {
createAdvancedPage({
route: 'about',
pagination: {
Expand All @@ -221,7 +209,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
helper: ({ createAdvancedPage }) => {
createAdvancedPage({
route: 'blog',
pagination: {
Expand All @@ -243,7 +231,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
helper: ({ createAdvancedPage }) => {
createAdvancedPage({
route: 'blog',
pagination: {
Expand All @@ -265,7 +253,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
helper: ({ createAdvancedPage }) => {
createAdvancedPage({
route: 'blog',
pagination: {
Expand All @@ -287,7 +275,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
helper: ({ createAdvancedPage }) => {
for (const slug of ['hello', 'world']) {
createAdvancedPage({
route: 'page',
Expand All @@ -310,7 +298,7 @@ export default [
]
}
],
helper: function ({ createAdvancedPage }) {
helper: ({ createAdvancedPage }) => {
createAdvancedPage({
route: 'about',
params: {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
93 changes: 6 additions & 87 deletions src/gatsby/__tests__/__snapshots__/create-pages.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,7 @@ Array [
]
`;

exports[`createPages correctly creates pages on (blog-paginated-auto-route) 2`] = `
"\\"use strict\\";
module.exports = [
{
\\"name\\": \\"blog\\",
\\"path\\": \\"/blog\\",
\\"scopes\\": {
\\"pagination\\": \\"/blog/page/:page\\"
}
}
];"
`;
exports[`createPages correctly creates pages on (blog-paginated-auto-route) 2`] = `"[{\\"name\\":\\"blog\\",\\"path\\":\\"/blog\\",\\"scopes\\":{\\"pagination\\":\\"/blog/page/:page\\"}}]"`;

exports[`createPages correctly creates pages on (blog-paginated-custom-limit) 1`] = `
Array [
Expand Down Expand Up @@ -101,19 +89,7 @@ Array [
]
`;

exports[`createPages correctly creates pages on (blog-paginated-custom-limit) 2`] = `
"\\"use strict\\";
module.exports = [
{
\\"name\\": \\"blog\\",
\\"path\\": \\"/blog\\",
\\"scopes\\": {
\\"pagination\\": \\"/blog/page/:page\\"
}
}
];"
`;
exports[`createPages correctly creates pages on (blog-paginated-custom-limit) 2`] = `"[{\\"name\\":\\"blog\\",\\"path\\":\\"/blog\\",\\"scopes\\":{\\"pagination\\":\\"/blog/page/:page\\"}}]"`;

exports[`createPages correctly creates pages on (blog-paginated-manual-route) 1`] = `
Array [
Expand Down Expand Up @@ -153,24 +129,7 @@ Array [
]
`;

exports[`createPages correctly creates pages on (blog-paginated-manual-route) 2`] = `
"\\"use strict\\";
module.exports = [
{
\\"name\\": \\"blog\\",
\\"path\\": \\"/blog\\",
\\"scopes\\": {
\\"pagination\\": \\"/blog/what/:page\\"
}
},
{
\\"name\\": \\"blog.paginated\\",
\\"path\\": \\"/blog/what/:page\\",
\\"scopes\\": {}
}
];"
`;
exports[`createPages correctly creates pages on (blog-paginated-manual-route) 2`] = `"[{\\"name\\":\\"blog\\",\\"path\\":\\"/blog\\",\\"scopes\\":{\\"pagination\\":\\"/blog/what/:page\\"}},{\\"name\\":\\"blog.paginated\\",\\"path\\":\\"/blog/what/:page\\",\\"scopes\\":{}}]"`;

exports[`createPages correctly creates pages on (dynamic-page) 1`] = `
Array [
Expand All @@ -197,17 +156,7 @@ Array [
]
`;

exports[`createPages correctly creates pages on (dynamic-page) 2`] = `
"\\"use strict\\";
module.exports = [
{
\\"name\\": \\"page\\",
\\"path\\": \\"/pages/:page\\",
\\"scopes\\": {}
}
];"
`;
exports[`createPages correctly creates pages on (dynamic-page) 2`] = `"[{\\"name\\":\\"page\\",\\"path\\":\\"/pages/:page\\",\\"scopes\\":{}}]"`;

exports[`createPages correctly creates pages on (home-about) 1`] = `
Array [
Expand Down Expand Up @@ -241,27 +190,7 @@ Array [
]
`;

exports[`createPages correctly creates pages on (home-about) 2`] = `
"\\"use strict\\";
module.exports = [
{
\\"name\\": \\"home\\",
\\"path\\": \\"/\\",
\\"scopes\\": {}
},
{
\\"name\\": \\"about\\",
\\"path\\": \\"/about\\",
\\"scopes\\": {}
},
{
\\"name\\": \\"aboutme\\",
\\"path\\": \\"/aboutme\\",
\\"scopes\\": {}
}
];"
`;
exports[`createPages correctly creates pages on (home-about) 2`] = `"[{\\"name\\":\\"home\\",\\"path\\":\\"/\\",\\"scopes\\":{}},{\\"name\\":\\"about\\",\\"path\\":\\"/about\\",\\"scopes\\":{}},{\\"name\\":\\"aboutme\\",\\"path\\":\\"/aboutme\\",\\"scopes\\":{}}]"`;

exports[`createPages correctly creates pages on (page-context) 1`] = `
Array [
Expand Down Expand Up @@ -296,17 +225,7 @@ Array [
]
`;

exports[`createPages correctly creates pages on (page-context) 2`] = `
"\\"use strict\\";
module.exports = [
{
\\"name\\": \\"about\\",
\\"path\\": \\"/about/:name\\",
\\"scopes\\": {}
}
];"
`;
exports[`createPages correctly creates pages on (page-context) 2`] = `"[{\\"name\\":\\"about\\",\\"path\\":\\"/about/:name\\",\\"scopes\\":{}}]"`;

exports[`createPages throws error on (bad-helper-empty-call) 1`] = `[Error: Route name passed to createAdvancedPage() at "/path/to/helper.js" must be a non-empty string]`;

Expand Down
Loading

0 comments on commit 7b76be8

Please sign in to comment.