-
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.
feature/WCC v0.15.0 and HTML Web Components (#1284)
* patch support for HTML web components with test case * fix linting * latest WCC patching * latest WCC patches * HTML web components test case * bump to official WCC v0.15.0
- Loading branch information
1 parent
7c9f498
commit b29283c
Showing
16 changed files
with
321 additions
and
7 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
123 changes: 123 additions & 0 deletions
123
...d.config.prerender-html-web-components/build.config.prerender-html-web-components.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,123 @@ | ||
/* | ||
* Use Case | ||
* Run Greenwood build command with prerender config set to true and using HTML (Light DOM) Web Components. | ||
* | ||
* User Result | ||
* Should generate a Greenwood build with the expected generated output using custom elements. | ||
* | ||
* User Command | ||
* greenwood build | ||
* | ||
* User Config | ||
* { | ||
* prerender: true | ||
* } | ||
* | ||
* User Workspace | ||
* src/ | ||
* components/ | ||
* caption.js | ||
* picture-frame.js | ||
* pages/ | ||
* index.html | ||
*/ | ||
import chai from 'chai'; | ||
import { JSDOM } from 'jsdom'; | ||
import path from 'path'; | ||
import { runSmokeTest } from '../../../../../test/smoke-test.js'; | ||
import { getSetupFiles, getOutputTeardownFiles } from '../../../../../test/utils.js'; | ||
import { Runner } from 'gallinago'; | ||
import { fileURLToPath, URL } from 'url'; | ||
import fs from 'fs/promises'; | ||
|
||
const expect = chai.expect; | ||
|
||
describe('Build Greenwood With: ', function() { | ||
const LABEL = 'Prerender Configuration and HTML (Light DOM) Web Components'; | ||
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(); | ||
}); | ||
|
||
describe(LABEL, function() { | ||
|
||
before(function() { | ||
runner.setup(outputPath, getSetupFiles(outputPath)); | ||
runner.runCommand(cliPath, 'build'); | ||
}); | ||
|
||
runSmokeTest(['public', 'index'], LABEL); | ||
|
||
describe('Prerendered output for index.html', function() { | ||
let dom; | ||
let pictureFrame; | ||
let expectedHtml; | ||
let actualHtml; | ||
|
||
before(async function() { | ||
actualHtml = await fs.readFile(new URL('./public/index.html', import.meta.url), 'utf-8'); | ||
dom = new JSDOM(actualHtml); | ||
pictureFrame = dom.window.document.querySelectorAll('wcc-picture-frame'); | ||
expectedHtml = await fs.readFile(new URL('./expected.html', import.meta.url), 'utf-8'); | ||
}); | ||
|
||
describe(LABEL, function() { | ||
it('should not have any <template> tags within the document', function() { | ||
expect(dom.window.document.querySelectorAll('template').length).to.equal(0); | ||
}); | ||
|
||
it('should only have one <wcc-picture-frame> tag', function() { | ||
expect(pictureFrame.length).to.equal(1); | ||
}); | ||
|
||
it('should have the expected image from userland in the HTML', () => { | ||
const img = pictureFrame[0].querySelectorAll('.picture-frame img'); | ||
|
||
expect(img.length).to.equal(1); | ||
expect(img[0].getAttribute('alt')).to.equal('Greenwood logo'); | ||
expect(img[0].getAttribute('src')).to.equal('https://www.greenwoodjs.io/assets/greenwood-logo-og.png'); | ||
}); | ||
|
||
it('should have the expected Author name <span> from userland in the HTML', () => { | ||
const img = pictureFrame[0].querySelectorAll('.picture-frame img + br + span'); | ||
|
||
expect(img.length).to.equal(1); | ||
expect(img[0].textContent).to.equal('Author: Greenwood'); | ||
}); | ||
|
||
it('should have the expected title attribute content in the nested <wcc-caption> tag', () => { | ||
const caption = pictureFrame[0].querySelectorAll('.picture-frame wcc-caption .caption'); | ||
const heading = caption[0].querySelectorAll('.heading'); | ||
|
||
expect(caption.length).to.equal(1); | ||
expect(heading.length).to.equal(1); | ||
expect(heading[0].textContent).to.equal('Greenwood'); | ||
}); | ||
|
||
it('should have the expected copyright content in the nested <wcc-caption> tag', () => { | ||
const caption = pictureFrame[0].querySelectorAll('.picture-frame wcc-caption .caption'); | ||
const span = caption[0].querySelectorAll('span'); | ||
|
||
expect(span.length).to.equal(1); | ||
expect(span[0].textContent).to.equal('© 2024'); | ||
}); | ||
|
||
it('should have the expected recursively generated HTML', () => { | ||
const body = dom.window.document.querySelector('body'); | ||
|
||
expect(expectedHtml.replace(/ /g, '').replace(/\n/g, '')).to.equal(body.innerHTML.replace(/ /g, '').replace(/\n/g, '')); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
after(async function() { | ||
runner.teardown(getOutputTeardownFiles(outputPath)); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/cli/test/cases/build.config.prerender-html-web-components/expected.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,13 @@ | ||
<wcc-picture-frame title="Greenwood"> | ||
<div class="picture-frame"> | ||
<img src="https://www.greenwoodjs.io/assets/greenwood-logo-og.png" alt="Greenwood logo"> | ||
<br> | ||
<span>Author: <span>Greenwood</span></span> | ||
<wcc-caption> | ||
<div class="caption"> | ||
<h6 class="heading">Greenwood</h6> | ||
<span>© 2024</span> | ||
</div> | ||
</wcc-caption> | ||
</div> | ||
</wcc-picture-frame> |
3 changes: 3 additions & 0 deletions
3
packages/cli/test/cases/build.config.prerender-html-web-components/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,3 @@ | ||
export default { | ||
prerender: true | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/cli/test/cases/build.config.prerender-html-web-components/package.json
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 @@ | ||
{ | ||
"type": "module" | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/cli/test/cases/build.config.prerender-html-web-components/src/components/caption.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,11 @@ | ||
export default class Caption extends HTMLElement { | ||
connectedCallback() { | ||
this.innerHTML = ` | ||
<div class="caption"> | ||
${this.innerHTML} | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('wcc-caption', Caption); |
19 changes: 19 additions & 0 deletions
19
...cli/test/cases/build.config.prerender-html-web-components/src/components/picture-frame.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,19 @@ | ||
import './caption.js'; | ||
|
||
export default class PictureFrame extends HTMLElement { | ||
connectedCallback() { | ||
const title = this.getAttribute('title'); | ||
|
||
this.innerHTML = ` | ||
<div class="picture-frame"> | ||
${this.innerHTML} | ||
<wcc-caption> | ||
<h6 class="heading">${title}</h6> | ||
<span>© 2024</span> | ||
</wcc-caption> | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('wcc-picture-frame', PictureFrame); |
17 changes: 17 additions & 0 deletions
17
packages/cli/test/cases/build.config.prerender-html-web-components/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,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script type="module" src="../components/picture-frame.js"></script> | ||
</head> | ||
|
||
<body> | ||
<wcc-picture-frame title="Greenwood"> | ||
<img | ||
src="https://www.greenwoodjs.io/assets/greenwood-logo-og.png" | ||
alt="Greenwood logo" | ||
/> | ||
<br/> | ||
<span>Author: <span>Greenwood</span></span> | ||
</wcc-picture-frame> | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
packages/cli/test/cases/loaders-build.html-web-components/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,3 @@ | ||
export default { | ||
prerender: true | ||
}; |
92 changes: 92 additions & 0 deletions
92
packages/cli/test/cases/loaders-build.html-web-components/loaders-html-webcomponents.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,92 @@ | ||
/* | ||
* Use Case | ||
* Run Greenwood and correctly prerender "HTML" Web Components. | ||
* https://blog.jim-nielsen.com/2023/html-web-components/ | ||
* | ||
* User Result | ||
* Should generate a static Greenwood build with the expected prerender "HTML" Web Components content. | ||
* | ||
* User Command | ||
* greenwood build | ||
* | ||
* User Config | ||
* | ||
* { | ||
* prerender: true, | ||
* } | ||
* | ||
* User Workspace | ||
* src/ | ||
* components/ | ||
* picture-frame.js | ||
* index.html | ||
*/ | ||
import chai from 'chai'; | ||
import { JSDOM } from 'jsdom'; | ||
import path from 'path'; | ||
import { runSmokeTest } from '../../../../../test/smoke-test.js'; | ||
import { getSetupFiles, 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 = 'Prerendering with HTML Web Components'; | ||
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, getSetupFiles(outputPath)); | ||
runner.runCommand(cliPath, 'build'); | ||
}); | ||
|
||
runSmokeTest(['public'], LABEL); | ||
|
||
describe('Prerender HTML Web Component', function() { | ||
let dom; | ||
let pictureFrame; | ||
|
||
before(async function() { | ||
dom = await JSDOM.fromFile(path.resolve(this.context.publicDir, './index.html')); | ||
pictureFrame = dom.window.document.querySelectorAll('app-picture-frame'); | ||
}); | ||
|
||
it('should not have any <template> tags within the document', function() { | ||
expect(dom.window.document.querySelectorAll('template').length).to.equal(0); | ||
}); | ||
|
||
it('should only have one <app-picture-frame> tag', function() { | ||
expect(pictureFrame.length).to.equal(1); | ||
}); | ||
|
||
it('should have the expected title attribute content in the heading of HTML', () => { | ||
const heading = pictureFrame[0].querySelectorAll('.picture-frame .heading'); | ||
|
||
expect(heading.length).to.equal(1); | ||
expect(heading[0].textContent).to.equal('Greenwood'); | ||
}); | ||
|
||
it('should have the expected image from userland in the HTML', () => { | ||
const img = pictureFrame[0].querySelectorAll('.picture-frame img'); | ||
|
||
expect(img.length).to.equal(1); | ||
expect(img[0].getAttribute('alt')).to.equal('Greenwood logo'); | ||
expect(img[0].getAttribute('src')).to.equal('/assets/greenwood.png'); | ||
}); | ||
}); | ||
}); | ||
|
||
after(function() { | ||
runner.teardown(getOutputTeardownFiles(outputPath)); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/cli/test/cases/loaders-build.html-web-components/package.json
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 @@ | ||
{ | ||
"type": "module" | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/cli/test/cases/loaders-build.html-web-components/src/components/picture-frame.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,14 @@ | ||
export default class PictureFrame extends HTMLElement { | ||
connectedCallback() { | ||
const title = this.getAttribute('title'); | ||
|
||
this.innerHTML = ` | ||
<div class="picture-frame"> | ||
<h6 class="heading">${title}</h6> | ||
${this.innerHTML} | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('app-picture-frame', PictureFrame); |
14 changes: 14 additions & 0 deletions
14
packages/cli/test/cases/loaders-build.html-web-components/src/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> | ||
<script type="module" src="./components/picture-frame.js"></script> | ||
</head> | ||
|
||
<body> | ||
<app-picture-frame title="Greenwood"> | ||
<img src="/assets/greenwood.png" alt="Greenwood logo" /> | ||
</app-picture-frame> | ||
</body> | ||
|
||
</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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17174,10 +17174,10 @@ [email protected]: | |
commander "^9.3.0" | ||
debug "^4.3.4" | ||
|
||
wc-compiler@~0.14.0: | ||
version "0.14.0" | ||
resolved "https://registry.yarnpkg.com/wc-compiler/-/wc-compiler-0.14.0.tgz#3bf5caf9e0b26b8c3a7b9806bd0d0711bfa371de" | ||
integrity sha512-5ouvZ2vDfwKTX9mj6IJWaJSF7239VAb+i8gbFqIyDRMuHqP0Bv9sq9oyZTDAqJM3trEiNWwv3VqI0fW4B8LAtg== | ||
wc-compiler@~0.15.0: | ||
version "0.15.0" | ||
resolved "https://registry.yarnpkg.com/wc-compiler/-/wc-compiler-0.15.0.tgz#f8c0a2b074d39490725718ddf0824ca0ee33ae67" | ||
integrity sha512-bzRjWEal5QGKrryZAsD3V9abuQ4blu2LP23GdrIM1UFybDRor6hcRhYJwdBLPriw017x/J69yPuRXLgAm2xUPQ== | ||
dependencies: | ||
"@projectevergreen/acorn-jsx-esm" "~0.1.0" | ||
"@projectevergreen/escodegen-esm" "~0.1.0" | ||
|