Skip to content

Commit

Permalink
fix(gatsby): add ./ prefix to paths in async-requires (gatsbyjs#20169)
Browse files Browse the repository at this point in the history
* fix(gatsby): add ./ prefix to paths in async-requires

* add test to e2e-tests
  • Loading branch information
wardpeet authored and GatsbyJS Bot committed Dec 17, 2019
1 parent 2e27d97 commit 4f2154a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ describe(`Production build tests`, () => {
cy.getTestElement(`process.env.NOT_EXISTING_VAR`).should(`be.empty`)
})

it(`should be able to create a page from component located in .cache directory`, () => {
cy.visit(`/page-from-cache/`).waitForRouteChange()

// `bar` is set in gatsby-node createPages
cy.getTestElement(`dom-marker`).contains(`[static-page-from-cache]`)
})

describe(`Supports unicode characters in urls`, () => {
it(`Can navigate directly`, () => {
cy.visit(`/안녕/`, {
Expand Down
13 changes: 13 additions & 0 deletions e2e-tests/production-runtime/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
const path = require(`path`)
const fs = require(`fs-extra`)

exports.onPreBootstrap = () => {
fs.copyFileSync(
`./src/templates/static-page-from-cache.js`,
`./.cache/static-page-from-cache.js`
)
}

exports.createPages = ({ actions: { createPage } }) => {
createPage({
Expand Down Expand Up @@ -83,6 +91,11 @@ exports.createPages = ({ actions: { createPage } }) => {
domMarker: `dynamic-and-wildcard`,
},
})

createPage({
path: `/page-from-cache/`,
component: path.resolve(`./.cache/static-page-from-cache.js`),
})
}

exports.onCreatePage = ({ page, actions }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'

const StaticPage = () => (
<pre data-testid="dom-marker">[static-page-from-cache] static-sibling</pre>
)

export default StaticPage
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/requires-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const preferDefault = m => m && m.default || m
)
return ` "${c.componentChunkName}": () => import("${slash(
relativeComponentPath
`./${relativeComponentPath}`
)}" /* webpackChunkName: "${c.componentChunkName}" */)`
})
.join(`,\n`)}
Expand Down

0 comments on commit 4f2154a

Please sign in to comment.