-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug/issue 1355 handle CSS import attributes with PostCSS plugin when …
…prerendering (#1361)
- Loading branch information
1 parent
14de0b7
commit 0bb7392
Showing
9 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
packages/plugin-postcss/test/cases/loaders-default.import-attributes/greenwood.config.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,8 @@ | ||
import { greenwoodPluginPostCss } from '../../../src/index.js'; | ||
|
||
export default { | ||
prerender: true, | ||
plugins: [ | ||
greenwoodPluginPostCss() | ||
] | ||
}; |
89 changes: 89 additions & 0 deletions
89
...ss/test/cases/loaders-default.import-attributes/loaders-default.import-attributes.spec.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,89 @@ | ||
/* | ||
* Use Case | ||
* Run Greenwood with default PostCSS config when using Import Attributes. | ||
* | ||
* User Result | ||
* Should generate a bare bones Greenwood build with the user's CSS file correctly minified. | ||
* | ||
* User Command | ||
* greenwood build | ||
* | ||
* User Config | ||
* const pluginPostCss = require('@greenwood/plugin-postcss'); | ||
* | ||
* { | ||
* plugins: [ | ||
* pluginPostCss() | ||
* ] | ||
* } | ||
* | ||
* User Workspace | ||
* src/ | ||
* components/ | ||
* header/ | ||
* header.js | ||
* header.css | ||
* pages/ | ||
* index.html | ||
* styles/ | ||
* theme.css | ||
*/ | ||
import chai from 'chai'; | ||
import fs from 'fs'; | ||
import glob from 'glob-promise'; | ||
import path from 'path'; | ||
import { runSmokeTest } from '../../../../../test/smoke-test.js'; | ||
import { getOutputTeardownFiles } from '../../../../../test/utils.js'; | ||
import { Runner } from 'gallinago'; | ||
import { fileURLToPath, URL } from 'url'; | ||
|
||
const expect = chai.expect; | ||
|
||
describe('Build Greenwood With: ', function() { | ||
const LABEL = 'Default PostCSS configuration and CSS Import Attributes'; | ||
const cliPath = path.join(process.cwd(), 'packages/cli/src/index.js'); | ||
const outputPath = fileURLToPath(new URL('.', import.meta.url)); | ||
let runner; | ||
|
||
before(function() { | ||
this.context = { | ||
publicDir: path.join(outputPath, 'public') | ||
}; | ||
runner = new Runner(false, true); | ||
}); | ||
|
||
describe(LABEL, function() { | ||
|
||
before(function() { | ||
runner.setup(outputPath); | ||
runner.runCommand(cliPath, 'build'); | ||
}); | ||
|
||
runSmokeTest(['public', 'index'], LABEL); | ||
|
||
describe('Page referencing external nested CSS file', function() { | ||
it('should output correctly processed nested CSS as non nested', function() { | ||
const expectedCss = 'body{color:red}h1{color:blue}'; | ||
const cssFiles = glob.sync(path.join(this.context.publicDir, 'styles', '*.css')); | ||
const css = fs.readFileSync(cssFiles[0], 'utf-8'); | ||
|
||
expect(cssFiles.length).to.equal(1); | ||
expect(css).to.equal(expectedCss); | ||
}); | ||
|
||
it('should output correctly processed import attributes in header.js bundle output', function() { | ||
const headerFiles = glob.sync(path.join(this.context.publicDir, 'header.*.js')); | ||
const js = fs.readFileSync(headerFiles[0], 'utf-8'); | ||
|
||
expect(headerFiles.length).to.equal(1); | ||
expect(js.indexOf('import e from"/styles/theme.1126086472.css"with{type:"css"};') >= 0).to.equal(true); | ||
expect(js.indexOf('import t from"/header.CaS9Xrom.css"with{type:"css"};') >= 0).to.equal(true); | ||
expect(js.indexOf('const s=new CSSStyleSheet;s.replaceSync(\'.spectrum{--spectrum-font-family-ar:myriad-arabic') >= 0).to.equal(true); | ||
}); | ||
}); | ||
}); | ||
|
||
after(function() { | ||
runner.teardown(getOutputTeardownFiles(outputPath)); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...gin-postcss/test/cases/loaders-default.import-attributes/src/components/header/header.css
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,3 @@ | ||
header { | ||
background-color: aqua; | ||
} |
24 changes: 24 additions & 0 deletions
24
...ugin-postcss/test/cases/loaders-default.import-attributes/src/components/header/header.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,24 @@ | ||
import themeSheet from '../../styles/theme.css' with { type: 'css' }; | ||
import headerSheet from './header.css' with { type: 'css' }; | ||
import SpectrumTypography from '@spectrum-css/typography' with { type: 'css' }; | ||
|
||
export default class Header extends HTMLElement { | ||
connectedCallback() { | ||
if (!this.shadowRoot) { | ||
const template = document.createElement('template'); | ||
|
||
template.innerHTML = ` | ||
<header> | ||
<span>Welcome to my site</span> | ||
</header> | ||
`; | ||
|
||
this.attachShadow({ mode: 'open' }); | ||
this.shadowRoot.appendChild(template.content.cloneNode(true)); | ||
} | ||
|
||
this.shadowRoot.adoptedStyleSheets = [themeSheet, headerSheet, SpectrumTypography]; | ||
} | ||
} | ||
|
||
customElements.define('app-header', Header); |
14 changes: 14 additions & 0 deletions
14
packages/plugin-postcss/test/cases/loaders-default.import-attributes/src/pages/index.html
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,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" prefix="og:http://ogp.me/ns#"> | ||
|
||
<head> | ||
<link rel="stylesheet" href="/styles/theme.css"></link> | ||
<script type="module" src="../components/header/header.js"></script> | ||
</head> | ||
|
||
<body> | ||
<app-header></app-header> | ||
<h1>Hello World!</h1> | ||
</body> | ||
|
||
</html> |
7 changes: 7 additions & 0 deletions
7
packages/plugin-postcss/test/cases/loaders-default.import-attributes/src/styles/theme.css
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,7 @@ | ||
body { | ||
color: red; | ||
} | ||
|
||
h1 { | ||
color: blue; | ||
} |
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