diff --git a/e2e-tests/path-prefix/cypress/integration/asset-prefix.js b/e2e-tests/path-prefix/cypress/integration/asset-prefix.js index cd2ebf43cd2ea..866246512aba6 100644 --- a/e2e-tests/path-prefix/cypress/integration/asset-prefix.js +++ b/e2e-tests/path-prefix/cypress/integration/asset-prefix.js @@ -5,11 +5,40 @@ const assetPrefixExpression = new RegExp(`^${assetPrefix}`) const assetPrefixMatcher = (chain, attr = `href`) => chain.should(`have.attr`, attr).and(`matches`, assetPrefixExpression) +beforeEach(() => { + cy.intercept(/page-data/).as("page-data") + cy.intercept(/slice-data/).as("slice-data") +}) + describe(`assetPrefix`, () => { beforeEach(() => { cy.visit(`/`).waitForRouteChange() }) + it(`page-data is prefixed with asset prefix`, () => { + cy.wait("@page-data") + + cy.get("@page-data").then((...intercepts) => { + expect(intercepts).to.have.length(1) + + for (const intercept of intercepts) { + expect(intercept.request.url).to.match(assetPrefixExpression) + } + }) + }) + + it(`slice-data is prefixed with asset prefix`, () => { + cy.wait("@slice-data") + + cy.get("@slice-data").then((...intercepts) => { + expect(intercepts).to.have.length(1) + + for (const intercept of intercepts) { + expect(intercept.request.url).to.match(assetPrefixExpression) + } + }) + }) + describe(`runtime`, () => { it(`prefixes styles`, () => { assetPrefixMatcher(cy.get(`head style[data-href]`), `data-href`) diff --git a/e2e-tests/path-prefix/gatsby-node.js b/e2e-tests/path-prefix/gatsby-node.js index 6d4a90e7a0555..6761288ac9c30 100644 --- a/e2e-tests/path-prefix/gatsby-node.js +++ b/e2e-tests/path-prefix/gatsby-node.js @@ -5,3 +5,9 @@ */ // You can delete this file if you're not using it +exports.createPages = async ({ actions }) => { + actions.createSlice({ + id: `header`, + component: require.resolve(`./src/components/header.js`), + }) +} diff --git a/e2e-tests/path-prefix/src/components/layout.js b/e2e-tests/path-prefix/src/components/layout.js index 2659ce0cf585a..013dfcbb67954 100644 --- a/e2e-tests/path-prefix/src/components/layout.js +++ b/e2e-tests/path-prefix/src/components/layout.js @@ -1,8 +1,7 @@ import * as React from "react" import PropTypes from "prop-types" -import { StaticQuery, graphql } from "gatsby" +import { StaticQuery, graphql, Slice } from "gatsby" -import Header from "./header" import "./layout.css" const Layout = ({ children }) => ( @@ -18,7 +17,7 @@ const Layout = ({ children }) => ( `} render={data => ( -
+
{ const jsonPayload = JSON.parse(res.responseText)