Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby): enable local themes #15856

Merged
merged 15 commits into from Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,12 +1,30 @@
/* global cy */

describe(`Components`, () => {
it(`can be added by themes`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`date`).contains(`6/28/1993`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`date`).contains(`6/28/1993`)
})
it(`local theme`, () => {
cy.visit(`/shadowed-local`).waitForRouteChange()
cy.getTestElement(`header`).contains(
`This is component to test shadowing of local theme`
)
})
})
it(`added by themes can be shadowed`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`time`).contains(`2:39:07 PM`)
describe(`added by themes can be shadowed`, () => {
it(`installed theme`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`time`).contains(`2:39:07 PM`)
})
it(`local theme`, () => {
cy.visit(`/shadowed-local`).waitForRouteChange()
cy.getTestElement(`pre`).contains(`This is in main site`)
cy.getTestElement(`pre`).should(
`not.contain`,
`This is in gatsby-theme-local`
)
})
})
})
29 changes: 21 additions & 8 deletions e2e-tests/themes/development-runtime/cypress/integration/pages.js
@@ -1,14 +1,27 @@
/* global cy */

describe(`Pages`, () => {
it(`can be added by themes`, () => {
cy.visit(`/about`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/about`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
})
it(`local theme`, () => {
cy.visit(`/page-from-local`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Page from local theme`)
})
})
it(`added by themes can be shadowed`, () => {
cy.visit(`/contact`).waitForRouteChange()
cy.getTestElement(`title`).contains(
`A title since the theme didn't have one`
)
describe(`added by themes can be shadowed`, () => {
it(`installed theme`, () => {
cy.visit(`/contact`).waitForRouteChange()
cy.getTestElement(`title`).contains(
`A title since the theme didn't have one`
)
})

it(`local theme`, () => {
cy.visit(`/page-from-local-overwrite`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Overwritten page from local theme`)
})
})
})
@@ -1,12 +1,24 @@
/* global cy */

describe(`Site Metadata`, () => {
it(`can be added by themes`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
})
it(`local theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`description`).contains(`Description placeholder`)
})
})
it(`added by themes can be overridden`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`author`).contains(`Sidhartha Chatterjee`)
describe(`added by themes can be overridden`, () => {
it(`installed theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`author`).contains(`Sidhartha Chatterjee`)
})
it(`local theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`social_twitter`).contains(`chatsidhartha`)
})
})
})
5 changes: 4 additions & 1 deletion e2e-tests/themes/development-runtime/gatsby-config.js
@@ -1,6 +1,9 @@
module.exports = {
siteMetadata: {
author: `Sidhartha Chatterjee`,
social: {
twitter: `chatsidhartha`,
},
},
plugins: [`gatsby-theme-about`],
plugins: [`gatsby-theme-about`, `gatsby-theme-local`],
}
@@ -0,0 +1,16 @@
module.exports = {
siteMetadata: {
description: `Description placeholder`,
social: {
twitter: `twitter placeholder`,
},
},
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/pages`,
},
},
],
}
@@ -0,0 +1 @@
// no-op
@@ -0,0 +1,3 @@
{
"name": "gatsby-theme-local"
}
@@ -0,0 +1,13 @@
import React from "react"
import ToBeShadowed from "./to-be-shadowed"

export default () => (
<>
<header data-testid="header">
This is component to test shadowing of local theme
</header>
<pre data-testid="pre">
<ToBeShadowed />
</pre>
</>
)
@@ -0,0 +1,3 @@
import React from "react"

export default () => <>This is in gatsby-theme-local</>
@@ -0,0 +1,3 @@
import React from "react"

export default () => <h1 data-testid="title">Page from local theme</h1>
@@ -0,0 +1,3 @@
import React from "react"

export default () => <h1 data-testid="title">Page from local theme</h1>
@@ -0,0 +1,3 @@
import React from "react"

export default () => <>This is in main site</>
6 changes: 6 additions & 0 deletions e2e-tests/themes/development-runtime/src/pages/index.js
Expand Up @@ -5,6 +5,8 @@ export default ({ data }) => (
<>
<p data-testid="title">{data.site.siteMetadata.title}</p>
<p data-testid="author">{data.site.siteMetadata.author}</p>
<p data-testid="description">{data.site.siteMetadata.description}</p>
<p data-testid="social_twitter">{data.site.siteMetadata.social.twitter}</p>
</>
)

Expand All @@ -14,6 +16,10 @@ export const pageQuery = graphql`
siteMetadata {
title
author
description
social {
twitter
}
}
}
}
Expand Down
@@ -0,0 +1,5 @@
import React from "react"

export default () => (
<h1 data-testid="title">Overwritten page from local theme</h1>
)
@@ -0,0 +1,5 @@
import React from "react"

import LocalShadowingComponent from "../../plugins/gatsby-theme-local/src/components/shadowing-local"

export default () => <LocalShadowingComponent />
@@ -1,12 +1,30 @@
/* global cy */

describe(`Components`, () => {
it(`can be added by themes`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`date`).contains(`6/28/1993`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`date`).contains(`6/28/1993`)
})
it(`local theme`, () => {
cy.visit(`/shadowed-local`).waitForRouteChange()
cy.getTestElement(`header`).contains(
`This is component to test shadowing of local theme`
)
})
})
it(`added by themes can be shadowed`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`time`).contains(`2:39:07 PM`)
describe(`added by themes can be shadowed`, () => {
it(`installed theme`, () => {
cy.visit(`/shadowed`).waitForRouteChange()
cy.getTestElement(`time`).contains(`2:39:07 PM`)
})
it(`local theme`, () => {
cy.visit(`/shadowed-local`).waitForRouteChange()
cy.getTestElement(`pre`).contains(`This is in main site`)
cy.getTestElement(`pre`).should(
`not.contain`,
`This is in gatsby-theme-local`
)
})
})
})
29 changes: 21 additions & 8 deletions e2e-tests/themes/production-runtime/cypress/integration/pages.js
@@ -1,14 +1,27 @@
/* global cy */

describe(`Pages`, () => {
it(`can be added by themes`, () => {
cy.visit(`/about`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/about`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
})
it(`local theme`, () => {
cy.visit(`/page-from-local`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Page from local theme`)
})
})
it(`added by themes can be shadowed`, () => {
cy.visit(`/contact`).waitForRouteChange()
cy.getTestElement(`title`).contains(
`A title since the theme didn't have one`
)
describe(`added by themes can be shadowed`, () => {
it(`installed theme`, () => {
cy.visit(`/contact`).waitForRouteChange()
cy.getTestElement(`title`).contains(
`A title since the theme didn't have one`
)
})

it(`local theme`, () => {
cy.visit(`/page-from-local-overwrite`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Overwritten page from local theme`)
})
})
})
@@ -1,12 +1,24 @@
/* global cy */

describe(`Site Metadata`, () => {
it(`can be added by themes`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
describe(`can be added by themes`, () => {
it(`installed theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`title`).contains(`Blog Title Placeholder`)
})
it(`local theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`description`).contains(`Description placeholder`)
})
})
it(`added by themes can be overridden`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`author`).contains(`Sidhartha Chatterjee`)
describe(`added by themes can be overridden`, () => {
it(`installed theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`author`).contains(`Sidhartha Chatterjee`)
})
it(`local theme`, () => {
cy.visit(`/`).waitForRouteChange()
cy.getTestElement(`social_twitter`).contains(`chatsidhartha`)
})
})
})
5 changes: 4 additions & 1 deletion e2e-tests/themes/production-runtime/gatsby-config.js
@@ -1,6 +1,9 @@
module.exports = {
siteMetadata: {
author: `Sidhartha Chatterjee`,
social: {
twitter: `chatsidhartha`,
},
},
plugins: [`gatsby-theme-about`],
plugins: [`gatsby-theme-about`, `gatsby-theme-local`],
}
@@ -0,0 +1,16 @@
module.exports = {
siteMetadata: {
description: `Description placeholder`,
social: {
twitter: `twitter placeholder`,
},
},
plugins: [
{
resolve: `gatsby-plugin-page-creator`,
options: {
path: `${__dirname}/src/pages`,
},
},
],
}
@@ -0,0 +1 @@
// no-op
@@ -0,0 +1,3 @@
{
"name": "gatsby-theme-local"
}
@@ -0,0 +1,13 @@
import React from "react"
import ToBeShadowed from "./to-be-shadowed"

export default () => (
<>
<header data-testid="header">
This is component to test shadowing of local theme
</header>
<pre data-testid="pre">
<ToBeShadowed />
</pre>
</>
)
@@ -0,0 +1,3 @@
import React from "react"

export default () => <>This is in gatsby-theme-local</>
@@ -0,0 +1,3 @@
import React from "react"

export default () => <h1 data-testid="title">Page from local theme</h1>
@@ -0,0 +1,3 @@
import React from "react"

export default () => <h1 data-testid="title">Page from local theme</h1>
@@ -0,0 +1,3 @@
import React from "react"

export default () => <>This is in main site</>
6 changes: 6 additions & 0 deletions e2e-tests/themes/production-runtime/src/pages/index.js
Expand Up @@ -5,6 +5,8 @@ export default ({ data }) => (
<>
<p data-testid="title">{data.site.siteMetadata.title}</p>
<p data-testid="author">{data.site.siteMetadata.author}</p>
<p data-testid="description">{data.site.siteMetadata.description}</p>
<p data-testid="social_twitter">{data.site.siteMetadata.social.twitter}</p>
</>
)

Expand All @@ -14,6 +16,10 @@ export const pageQuery = graphql`
siteMetadata {
title
author
description
social {
twitter
}
}
}
}
Expand Down
@@ -0,0 +1,5 @@
import React from "react"

export default () => (
<h1 data-testid="title">Overwritten page from local theme</h1>
)
@@ -0,0 +1,5 @@
import React from "react"

import LocalShadowingComponent from "../../plugins/gatsby-theme-local/src/components/shadowing-local"

export default () => <LocalShadowingComponent />