forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(themes): Restrict the paths that count as shadowable for an issuer (
- Loading branch information
1 parent
ce28cfe
commit e040947
Showing
3 changed files
with
199 additions
and
47 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/__tests__/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import path from "path" | ||
import ShadowingPlugin from "../" | ||
|
||
describe(`Component Shadowing`, () => { | ||
it(`gets matching themes`, () => { | ||
const plugin = new ShadowingPlugin({ | ||
themes: [`a-theme`, `theme-b`, `gatsby-theme-c`].map(name => { | ||
return { | ||
themeName: name, | ||
themeDir: path.join(path.sep, `some`, `place`, name), | ||
} | ||
}), | ||
}) | ||
expect( | ||
// simple request path to a theme's component | ||
plugin.getMatchingThemesForPath( | ||
path.join( | ||
path.sep, | ||
`some`, | ||
`place`, | ||
`a-theme`, | ||
`src`, | ||
`components`, | ||
`a-component` | ||
) | ||
) | ||
).toEqual([`a-theme`]) | ||
|
||
expect( | ||
// request to a shadowed component in theme b | ||
// component-path is expected to be `a-theme/components/a-component` | ||
plugin.getMatchingThemesForPath( | ||
path.join( | ||
path.sep, | ||
`some`, | ||
`place`, | ||
`theme-b`, | ||
`src`, | ||
`a-theme`, | ||
`components`, | ||
`a-component` | ||
) | ||
) | ||
).toEqual([`theme-b`]) | ||
}) | ||
|
||
it(`can determine if the request path is in the shadow chain for the issuer`, () => { | ||
const plugin = new ShadowingPlugin({ | ||
themes: [`a-theme`, `theme-b`, `gatsby-theme-c`].map(name => { | ||
return { | ||
themeName: name, | ||
themeDir: path.join(path.sep, `some`, `place`, name), | ||
} | ||
}), | ||
}) | ||
expect( | ||
plugin.requestPathIsIssuerShadowPath({ | ||
// issuer is in `theme-b` | ||
issuerPath: path.join( | ||
path.sep, | ||
`some`, | ||
`place`, | ||
`theme-b`, | ||
`src`, | ||
`a-theme`, | ||
`components`, | ||
`a-component` | ||
), | ||
// require'ing a file it is a "shadow child" of in a-theme | ||
requestPath: path.join( | ||
path.sep, | ||
`some`, | ||
`place`, | ||
`a-theme`, | ||
`src`, | ||
`components`, | ||
`a-component` | ||
), | ||
}) | ||
).toEqual(true) | ||
|
||
expect( | ||
plugin.requestPathIsIssuerShadowPath({ | ||
// issuer is in `theme-b` | ||
issuerPath: path.join( | ||
path.sep, | ||
`some`, | ||
`place`, | ||
`theme-b`, | ||
`src`, | ||
`a-theme`, | ||
`components`, | ||
`a-component` | ||
), | ||
// require'ing a file it is NOT a "shadow child" of, also in theme-b | ||
// the `component-path` here would be "components/a-component" | ||
requestPath: path.join( | ||
path.sep, | ||
`some`, | ||
`place`, | ||
`theme-b`, | ||
`src`, | ||
`components`, | ||
`a-component` | ||
), | ||
}) | ||
).toEqual(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters