mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-21 15:54:57 +00:00
Compare commits
5 Commits
@rocket/cl
...
@rocket/cl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5f2d69d0c | ||
|
|
795a3613af | ||
|
|
bcf8f4fe83 | ||
|
|
5330740cb3 | ||
|
|
2edd61beaa |
@@ -1,5 +1,17 @@
|
|||||||
# @rocket/cli
|
# @rocket/cli
|
||||||
|
|
||||||
|
## 0.9.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 795a361: The server worker url should respect a set pathPrefix.
|
||||||
|
|
||||||
|
## 0.9.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 5330740: When replacing images with responsive picture tags do this from the bottom up so the initial dom parsing locations still hold true.
|
||||||
|
|
||||||
## 0.9.1
|
## 0.9.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rocket/cli",
|
"name": "@rocket/cli",
|
||||||
"version": "0.9.1",
|
"version": "0.9.3",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
{% set rocketServiceWorkerUrl = '/' + rocketConfig.serviceWorkerName %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.__rocketServiceWorkerUrl = '/{{ rocketConfig.serviceWorkerName }}';
|
window.__rocketServiceWorkerUrl = '{{ rocketServiceWorkerUrl | url }}';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="module" inject-service-worker="" src="{{ '/_assets/scripts/registerServiceWorker.js' | asset | url }}"></script>
|
<script type="module" inject-service-worker="" src="{{ '/_assets/scripts/registerServiceWorker.js' | asset | url }}"></script>
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ async function responsiveImages(images, { inputPath, outputDir, imagePresets = {
|
|||||||
|
|
||||||
function updateHtml(html, changes) {
|
function updateHtml(html, changes) {
|
||||||
let newHtml = html;
|
let newHtml = html;
|
||||||
for (const change of changes) {
|
for (const change of changes.reverse()) {
|
||||||
newHtml = replaceBetween({
|
newHtml = replaceBetween({
|
||||||
html: newHtml,
|
html: newHtml,
|
||||||
start: change.openStart,
|
start: change.openStart,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export function setFixtureDir(importMetaUrl) {
|
|||||||
* @property {boolean} stripStartEndWhitespace
|
* @property {boolean} stripStartEndWhitespace
|
||||||
* @property {boolean} stripScripts
|
* @property {boolean} stripScripts
|
||||||
* @property {boolean} formatHtml
|
* @property {boolean} formatHtml
|
||||||
|
* @property {boolean} replaceImageHashes
|
||||||
* @property {start|build} type
|
* @property {start|build} type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ export async function readOutput(
|
|||||||
stripScripts = false,
|
stripScripts = false,
|
||||||
formatHtml = false,
|
formatHtml = false,
|
||||||
type = 'build',
|
type = 'build',
|
||||||
|
replaceImageHashes = false,
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
if (!cli || !cli.config) {
|
if (!cli || !cli.config) {
|
||||||
@@ -70,6 +72,9 @@ export async function readOutput(
|
|||||||
const scriptCloseTagStart = text.indexOf('</script>', scriptOpenTagEnd) + 9;
|
const scriptCloseTagStart = text.indexOf('</script>', scriptOpenTagEnd) + 9;
|
||||||
text = text.substring(0, scriptOpenTagEnd) + text.substring(scriptCloseTagStart);
|
text = text.substring(0, scriptOpenTagEnd) + text.substring(scriptCloseTagStart);
|
||||||
}
|
}
|
||||||
|
if (replaceImageHashes) {
|
||||||
|
text = text.replace(/\/images\/([a-z0-9]+)-/g, '/images/__HASH__-');
|
||||||
|
}
|
||||||
if (formatHtml) {
|
if (formatHtml) {
|
||||||
text = prettier.format(text, { parser: 'html', printWidth: 100 });
|
text = prettier.format(text, { parser: 'html', printWidth: 100 });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,17 +102,17 @@ describe('RocketCli e2e', () => {
|
|||||||
);
|
);
|
||||||
const assetHtml = await readStartOutput(cli, 'use-assets/index.html');
|
const assetHtml = await readStartOutput(cli, 'use-assets/index.html');
|
||||||
expect(assetHtml).to.equal('<link rel="stylesheet" href="/_merged_assets/some.css">');
|
expect(assetHtml).to.equal('<link rel="stylesheet" href="/_merged_assets/some.css">');
|
||||||
const imageHtml = await readStartOutput(cli, 'image/index.html');
|
const imageHtml = await readStartOutput(cli, 'image/index.html', { replaceImageHashes: true });
|
||||||
expect(imageHtml).to.equal(
|
expect(imageHtml).to.equal(
|
||||||
[
|
[
|
||||||
'<p>',
|
'<p>',
|
||||||
' <figure>',
|
' <figure>',
|
||||||
' <picture>',
|
' <picture>',
|
||||||
'<source type="image/avif" srcset="/images/dd502010-600.avif 600w, /images/dd502010-900.avif 900w" sizes="100vw">',
|
'<source type="image/avif" srcset="/images/__HASH__-600.avif 600w, /images/__HASH__-900.avif 900w" sizes="100vw">',
|
||||||
'<source type="image/jpeg" srcset="/images/dd502010-600.jpeg 600w, /images/dd502010-900.jpeg 900w" sizes="100vw">',
|
'<source type="image/jpeg" srcset="/images/__HASH__-600.jpeg 600w, /images/__HASH__-900.jpeg 900w" sizes="100vw">',
|
||||||
' <img',
|
' <img',
|
||||||
' alt="My Image Alternative Text" rocket-image="responsive"',
|
' alt="My Image Alternative Text" rocket-image="responsive"',
|
||||||
' src="/images/dd502010-600.jpeg"',
|
' src="/images/__HASH__-600.jpeg"',
|
||||||
' ',
|
' ',
|
||||||
' ',
|
' ',
|
||||||
' width="600"',
|
' width="600"',
|
||||||
@@ -143,16 +143,17 @@ describe('RocketCli e2e', () => {
|
|||||||
expect(assetHtml).to.equal(
|
expect(assetHtml).to.equal(
|
||||||
'<html><head><link rel="stylesheet" href="../41297ffa.css">\n\n</head><body>\n\n</body></html>',
|
'<html><head><link rel="stylesheet" href="../41297ffa.css">\n\n</head><body>\n\n</body></html>',
|
||||||
);
|
);
|
||||||
const imageHtml = await readBuildOutput(cli, 'image/index.html');
|
let imageHtml = await readBuildOutput(cli, 'image/index.html');
|
||||||
|
imageHtml = imageHtml.replace(/\.\.\/([a-z0-9]+)\./g, '../__HASH__.');
|
||||||
expect(imageHtml).to.equal(
|
expect(imageHtml).to.equal(
|
||||||
[
|
[
|
||||||
'<html><head>',
|
'<html><head>',
|
||||||
'</head><body><p>',
|
'</head><body><p>',
|
||||||
' </p><figure>',
|
' </p><figure>',
|
||||||
' <picture>',
|
' <picture>',
|
||||||
'<source type="image/avif" srcset="../e64e2277.avif 600w, ../37453c88.avif 900w" sizes="100vw">',
|
'<source type="image/avif" srcset="../__HASH__.avif 600w, ../__HASH__.avif 900w" sizes="100vw">',
|
||||||
'<source type="image/jpeg" srcset="../d0f18b5a.jpeg 600w, ../81998598.jpeg 900w" sizes="100vw">',
|
'<source type="image/jpeg" srcset="../__HASH__.jpeg 600w, ../__HASH__.jpeg 900w" sizes="100vw">',
|
||||||
' <img alt="My Image Alternative Text" rocket-image="responsive" src="../d0f18b5a.jpeg" width="600" height="316" loading="lazy" decoding="async">',
|
' <img alt="My Image Alternative Text" rocket-image="responsive" src="../__HASH__.jpeg" width="600" height="316" loading="lazy" decoding="async">',
|
||||||
' </picture>',
|
' </picture>',
|
||||||
' <figcaption>My Image Description</figcaption>',
|
' <figcaption>My Image Description</figcaption>',
|
||||||
'</figure>',
|
'</figure>',
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ describe('RocketCli images', () => {
|
|||||||
describe('Images', () => {
|
describe('Images', () => {
|
||||||
it('does render content images responsive', async () => {
|
it('does render content images responsive', async () => {
|
||||||
cli = await executeStart('e2e-fixtures/images/rocket.config.js');
|
cli = await executeStart('e2e-fixtures/images/rocket.config.js');
|
||||||
const indexHtml = await readStartOutput(cli, 'index.html', { formatHtml: true });
|
const indexHtml = await readStartOutput(cli, 'index.html', {
|
||||||
|
formatHtml: true,
|
||||||
|
replaceImageHashes: true,
|
||||||
|
});
|
||||||
expect(indexHtml).to.equal(
|
expect(indexHtml).to.equal(
|
||||||
[
|
[
|
||||||
'<p>',
|
'<p>',
|
||||||
@@ -30,18 +33,18 @@ describe('RocketCli images', () => {
|
|||||||
' <picture>',
|
' <picture>',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/avif"',
|
' type="image/avif"',
|
||||||
' srcset="/images/d67643ad-600.avif 600w, /images/d67643ad-900.avif 900w"',
|
' srcset="/images/__HASH__-600.avif 600w, /images/__HASH__-900.avif 900w"',
|
||||||
' sizes="100vw"',
|
' sizes="100vw"',
|
||||||
' />',
|
' />',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/jpeg"',
|
' type="image/jpeg"',
|
||||||
' srcset="/images/d67643ad-600.jpeg 600w, /images/d67643ad-900.jpeg 900w"',
|
' srcset="/images/__HASH__-600.jpeg 600w, /images/__HASH__-900.jpeg 900w"',
|
||||||
' sizes="100vw"',
|
' sizes="100vw"',
|
||||||
' />',
|
' />',
|
||||||
' <img',
|
' <img',
|
||||||
' alt="My Image Alternative Text"',
|
' alt="My Image Alternative Text"',
|
||||||
' rocket-image="responsive"',
|
' rocket-image="responsive"',
|
||||||
' src="/images/d67643ad-600.jpeg"',
|
' src="/images/__HASH__-600.jpeg"',
|
||||||
' width="600"',
|
' width="600"',
|
||||||
' height="316"',
|
' height="316"',
|
||||||
' loading="lazy"',
|
' loading="lazy"',
|
||||||
@@ -57,47 +60,57 @@ describe('RocketCli images', () => {
|
|||||||
|
|
||||||
it('renders multiple images in the correct order', async () => {
|
it('renders multiple images in the correct order', async () => {
|
||||||
cli = await executeStart('e2e-fixtures/images/rocket.config.js');
|
cli = await executeStart('e2e-fixtures/images/rocket.config.js');
|
||||||
const indexHtml = await readStartOutput(cli, 'two-images/index.html', { formatHtml: true });
|
const indexHtml = await readStartOutput(cli, 'two-images/index.html', {
|
||||||
|
formatHtml: true,
|
||||||
|
replaceImageHashes: true,
|
||||||
|
});
|
||||||
expect(indexHtml).to.equal(
|
expect(indexHtml).to.equal(
|
||||||
[
|
[
|
||||||
|
'<h2 id="one">',
|
||||||
|
' <a aria-hidden="true" tabindex="-1" href="#one"><span class="icon icon-link"></span></a>one',
|
||||||
|
'</h2>',
|
||||||
'<p>',
|
'<p>',
|
||||||
' <picture>',
|
' <picture>',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/avif"',
|
' type="image/avif"',
|
||||||
' srcset="/images/d67643ad-600.avif 600w, /images/d67643ad-900.avif 900w"',
|
' srcset="/images/__HASH__-600.avif 600w, /images/__HASH__-900.avif 900w"',
|
||||||
' sizes="100vw"',
|
' sizes="100vw"',
|
||||||
' />',
|
' />',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/jpeg"',
|
' type="image/jpeg"',
|
||||||
' srcset="/images/d67643ad-600.jpeg 600w, /images/d67643ad-900.jpeg 900w"',
|
' srcset="/images/__HASH__-600.jpeg 600w, /images/__HASH__-900.jpeg 900w"',
|
||||||
' sizes="100vw"',
|
' sizes="100vw"',
|
||||||
' />',
|
' />',
|
||||||
' <img',
|
' <img',
|
||||||
' alt="one"',
|
' alt="one"',
|
||||||
' rocket-image="responsive"',
|
' rocket-image="responsive"',
|
||||||
' src="/images/d67643ad-600.jpeg"',
|
' src="/images/__HASH__-600.jpeg"',
|
||||||
' width="600"',
|
' width="600"',
|
||||||
' height="316"',
|
' height="316"',
|
||||||
' loading="lazy"',
|
' loading="lazy"',
|
||||||
' decoding="async"',
|
' decoding="async"',
|
||||||
' />',
|
' />',
|
||||||
' </picture>',
|
' </picture>',
|
||||||
'',
|
'</p>',
|
||||||
|
'<h2 id="two">',
|
||||||
|
' <a aria-hidden="true" tabindex="-1" href="#two"><span class="icon icon-link"></span></a>two',
|
||||||
|
'</h2>',
|
||||||
|
'<p>',
|
||||||
' <picture>',
|
' <picture>',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/avif"',
|
' type="image/avif"',
|
||||||
' srcset="/images/d67643ad-600.avif 600w, /images/d67643ad-900.avif 900w"',
|
' srcset="/images/__HASH__-600.avif 600w, /images/__HASH__-900.avif 900w"',
|
||||||
' sizes="100vw"',
|
' sizes="100vw"',
|
||||||
' />',
|
' />',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/jpeg"',
|
' type="image/jpeg"',
|
||||||
' srcset="/images/d67643ad-600.jpeg 600w, /images/d67643ad-900.jpeg 900w"',
|
' srcset="/images/__HASH__-600.jpeg 600w, /images/__HASH__-900.jpeg 900w"',
|
||||||
' sizes="100vw"',
|
' sizes="100vw"',
|
||||||
' />',
|
' />',
|
||||||
' <img',
|
' <img',
|
||||||
' alt="two"',
|
' alt="two"',
|
||||||
' rocket-image="responsive"',
|
' rocket-image="responsive"',
|
||||||
' src="/images/d67643ad-600.jpeg"',
|
' src="/images/__HASH__-600.jpeg"',
|
||||||
' width="600"',
|
' width="600"',
|
||||||
' height="316"',
|
' height="316"',
|
||||||
' loading="lazy"',
|
' loading="lazy"',
|
||||||
@@ -111,7 +124,10 @@ describe('RocketCli images', () => {
|
|||||||
|
|
||||||
it('can configure those responsive images', async () => {
|
it('can configure those responsive images', async () => {
|
||||||
cli = await executeStart('e2e-fixtures/images/small.rocket.config.js');
|
cli = await executeStart('e2e-fixtures/images/small.rocket.config.js');
|
||||||
const indexHtml = await readStartOutput(cli, 'index.html', { formatHtml: true });
|
const indexHtml = await readStartOutput(cli, 'index.html', {
|
||||||
|
formatHtml: true,
|
||||||
|
replaceImageHashes: true,
|
||||||
|
});
|
||||||
expect(indexHtml).to.equal(
|
expect(indexHtml).to.equal(
|
||||||
[
|
[
|
||||||
'<p>',
|
'<p>',
|
||||||
@@ -119,18 +135,18 @@ describe('RocketCli images', () => {
|
|||||||
' <picture>',
|
' <picture>',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/avif"',
|
' type="image/avif"',
|
||||||
' srcset="/images/d67643ad-30.avif 30w, /images/d67643ad-60.avif 60w"',
|
' srcset="/images/__HASH__-30.avif 30w, /images/__HASH__-60.avif 60w"',
|
||||||
' sizes="(min-width: 1024px) 30px, 60px"',
|
' sizes="(min-width: 1024px) 30px, 60px"',
|
||||||
' />',
|
' />',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/jpeg"',
|
' type="image/jpeg"',
|
||||||
' srcset="/images/d67643ad-30.jpeg 30w, /images/d67643ad-60.jpeg 60w"',
|
' srcset="/images/__HASH__-30.jpeg 30w, /images/__HASH__-60.jpeg 60w"',
|
||||||
' sizes="(min-width: 1024px) 30px, 60px"',
|
' sizes="(min-width: 1024px) 30px, 60px"',
|
||||||
' />',
|
' />',
|
||||||
' <img',
|
' <img',
|
||||||
' alt="My Image Alternative Text"',
|
' alt="My Image Alternative Text"',
|
||||||
' rocket-image="responsive"',
|
' rocket-image="responsive"',
|
||||||
' src="/images/d67643ad-30.jpeg"',
|
' src="/images/__HASH__-30.jpeg"',
|
||||||
' width="30"',
|
' width="30"',
|
||||||
' height="15"',
|
' height="15"',
|
||||||
' loading="lazy"',
|
' loading="lazy"',
|
||||||
@@ -146,25 +162,28 @@ describe('RocketCli images', () => {
|
|||||||
|
|
||||||
it('will only render a figure & figcaption if there is a caption/title', async () => {
|
it('will only render a figure & figcaption if there is a caption/title', async () => {
|
||||||
cli = await executeStart('e2e-fixtures/images/small.rocket.config.js');
|
cli = await executeStart('e2e-fixtures/images/small.rocket.config.js');
|
||||||
const indexHtml = await readStartOutput(cli, 'no-title/index.html', { formatHtml: true });
|
const indexHtml = await readStartOutput(cli, 'no-title/index.html', {
|
||||||
|
formatHtml: true,
|
||||||
|
replaceImageHashes: true,
|
||||||
|
});
|
||||||
expect(indexHtml).to.equal(
|
expect(indexHtml).to.equal(
|
||||||
[
|
[
|
||||||
'<p>',
|
'<p>',
|
||||||
' <picture>',
|
' <picture>',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/avif"',
|
' type="image/avif"',
|
||||||
' srcset="/images/d67643ad-30.avif 30w, /images/d67643ad-60.avif 60w"',
|
' srcset="/images/__HASH__-30.avif 30w, /images/__HASH__-60.avif 60w"',
|
||||||
' sizes="(min-width: 1024px) 30px, 60px"',
|
' sizes="(min-width: 1024px) 30px, 60px"',
|
||||||
' />',
|
' />',
|
||||||
' <source',
|
' <source',
|
||||||
' type="image/jpeg"',
|
' type="image/jpeg"',
|
||||||
' srcset="/images/d67643ad-30.jpeg 30w, /images/d67643ad-60.jpeg 60w"',
|
' srcset="/images/__HASH__-30.jpeg 30w, /images/__HASH__-60.jpeg 60w"',
|
||||||
' sizes="(min-width: 1024px) 30px, 60px"',
|
' sizes="(min-width: 1024px) 30px, 60px"',
|
||||||
' />',
|
' />',
|
||||||
' <img',
|
' <img',
|
||||||
' alt="My Image Alternative Text"',
|
' alt="My Image Alternative Text"',
|
||||||
' rocket-image="responsive"',
|
' rocket-image="responsive"',
|
||||||
' src="/images/d67643ad-30.jpeg"',
|
' src="/images/__HASH__-30.jpeg"',
|
||||||
' width="30"',
|
' width="30"',
|
||||||
' height="15"',
|
' height="15"',
|
||||||
' loading="lazy"',
|
' loading="lazy"',
|
||||||
@@ -178,15 +197,18 @@ describe('RocketCli images', () => {
|
|||||||
|
|
||||||
it('will render an img with srcset and sizes if there is only one image format', async () => {
|
it('will render an img with srcset and sizes if there is only one image format', async () => {
|
||||||
cli = await executeStart('e2e-fixtures/images/single-format.rocket.config.js');
|
cli = await executeStart('e2e-fixtures/images/single-format.rocket.config.js');
|
||||||
const indexHtml = await readStartOutput(cli, 'no-title/index.html', { formatHtml: true });
|
const indexHtml = await readStartOutput(cli, 'no-title/index.html', {
|
||||||
|
formatHtml: true,
|
||||||
|
replaceImageHashes: true,
|
||||||
|
});
|
||||||
expect(indexHtml).to.equal(
|
expect(indexHtml).to.equal(
|
||||||
[
|
[
|
||||||
'<p>',
|
'<p>',
|
||||||
' <img',
|
' <img',
|
||||||
' alt="My Image Alternative Text"',
|
' alt="My Image Alternative Text"',
|
||||||
' rocket-image="responsive"',
|
' rocket-image="responsive"',
|
||||||
' src="/images/d67643ad-30.jpeg"',
|
' src="/images/__HASH__-30.jpeg"',
|
||||||
' srcset="/images/d67643ad-30.jpeg 30w, /images/d67643ad-60.jpeg 60w"',
|
' srcset="/images/__HASH__-30.jpeg 30w, /images/__HASH__-60.jpeg 60w"',
|
||||||
' sizes="(min-width: 1024px) 30px, 60px"',
|
' sizes="(min-width: 1024px) 30px, 60px"',
|
||||||
' width="30"',
|
' width="30"',
|
||||||
' height="15"',
|
' height="15"',
|
||||||
|
|||||||
@@ -108,15 +108,18 @@ describe('RocketCli preset', () => {
|
|||||||
it('a preset can provide an adjustImagePresets() function', async () => {
|
it('a preset can provide an adjustImagePresets() function', async () => {
|
||||||
cli = await executeStart('preset-fixtures/use-preset/rocket.config.js');
|
cli = await executeStart('preset-fixtures/use-preset/rocket.config.js');
|
||||||
|
|
||||||
const indexHtml = await readStartOutput(cli, 'index.html', { formatHtml: true });
|
const indexHtml = await readStartOutput(cli, 'index.html', {
|
||||||
|
formatHtml: true,
|
||||||
|
replaceImageHashes: true,
|
||||||
|
});
|
||||||
expect(indexHtml).to.equal(
|
expect(indexHtml).to.equal(
|
||||||
[
|
[
|
||||||
'<p>',
|
'<p>',
|
||||||
' <img',
|
' <img',
|
||||||
' alt="My Image Alternative Text"',
|
' alt="My Image Alternative Text"',
|
||||||
' rocket-image="responsive"',
|
' rocket-image="responsive"',
|
||||||
' src="/images/1f847765-30.jpeg"',
|
' src="/images/__HASH__-30.jpeg"',
|
||||||
' srcset="/images/1f847765-30.jpeg 30w, /images/1f847765-60.jpeg 60w"',
|
' srcset="/images/__HASH__-30.jpeg 30w, /images/__HASH__-60.jpeg 60w"',
|
||||||
' sizes="30px"',
|
' sizes="30px"',
|
||||||
' width="30"',
|
' width="30"',
|
||||||
' height="15"',
|
' height="15"',
|
||||||
|
|||||||
66
packages/cli/test-node/RocketCli.service-worker.test.js
Normal file
66
packages/cli/test-node/RocketCli.service-worker.test.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import chai from 'chai';
|
||||||
|
import chalk from 'chalk';
|
||||||
|
import { executeBuild, readStartOutput, setFixtureDir } from '@rocket/cli/test-helpers';
|
||||||
|
|
||||||
|
const { expect } = chai;
|
||||||
|
|
||||||
|
function getInjectServiceWorker(text) {
|
||||||
|
const scriptOpenTagStart = text.indexOf('<script type="module" inject-service-worker=""');
|
||||||
|
const scriptCloseTagEnd = text.indexOf('</script>', scriptOpenTagStart) + 9;
|
||||||
|
text = text.substring(scriptOpenTagStart, scriptCloseTagEnd);
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getServiceWorkerUrl(text) {
|
||||||
|
const matches = text.match(/window\.__rocketServiceWorkerUrl = '(.*?)';/);
|
||||||
|
return matches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('RocketCli e2e', () => {
|
||||||
|
let cli;
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
// ignore colors in tests as most CIs won't support it
|
||||||
|
chalk.level = 0;
|
||||||
|
setFixtureDir(import.meta.url);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
if (cli?.cleanup) {
|
||||||
|
await cli.cleanup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it.only('will add a script to inject the service worker', async () => {
|
||||||
|
cli = await executeBuild('e2e-fixtures/service-worker/rocket.config.js');
|
||||||
|
const indexHtml = await readStartOutput(cli, 'index.html');
|
||||||
|
const indexInject = getInjectServiceWorker(indexHtml);
|
||||||
|
expect(indexInject).to.equal(
|
||||||
|
'<script type="module" inject-service-worker="" src="/_merged_assets/scripts/registerServiceWorker.js"></script>',
|
||||||
|
);
|
||||||
|
expect(getServiceWorkerUrl(indexHtml)).to.equal('/service-worker.js');
|
||||||
|
const subHtml = await readStartOutput(cli, 'sub/index.html');
|
||||||
|
const subInject = getInjectServiceWorker(subHtml);
|
||||||
|
expect(subInject).to.equal(
|
||||||
|
'<script type="module" inject-service-worker="" src="/_merged_assets/scripts/registerServiceWorker.js"></script>',
|
||||||
|
);
|
||||||
|
expect(getServiceWorkerUrl(subHtml)).to.equal('/service-worker.js');
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: find a way to run these test either by forcing pathPrefix in start or skipping asset gathering for build or ...
|
||||||
|
it.skip('will add a script to inject the service worker', async () => {
|
||||||
|
cli = await executeBuild('e2e-fixtures/service-worker/pathPrefix.rocket.config.js');
|
||||||
|
const indexHtml = await readStartOutput(cli, 'index.html');
|
||||||
|
const indexInject = getInjectServiceWorker(indexHtml);
|
||||||
|
expect(indexInject).to.equal(
|
||||||
|
'<script type="module" inject-service-worker="" src="/my-prefix-folder/_merged_assets/scripts/registerServiceWorker.js"></script>',
|
||||||
|
);
|
||||||
|
expect(getServiceWorkerUrl(indexHtml)).to.equal('/my-prefix-folder/service-worker.js');
|
||||||
|
const subHtml = await readStartOutput(cli, 'sub/index.html');
|
||||||
|
const subInject = getInjectServiceWorker(subHtml);
|
||||||
|
expect(subInject).to.equal(
|
||||||
|
'<script type="module" inject-service-worker="" src="/my-prefix-folder/_merged_assets/scripts/registerServiceWorker.js"></script>',
|
||||||
|
);
|
||||||
|
expect(getServiceWorkerUrl(subHtml)).to.equal('/my-prefix-folder/service-worker.js');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2,4 +2,10 @@
|
|||||||
layout: layout-raw
|
layout: layout-raw
|
||||||
---
|
---
|
||||||
|
|
||||||

|
## one
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## two
|
||||||
|
|
||||||
|

|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
**/*.njk
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
module.exports = 'https://example.com';
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
layout: layout-default
|
||||||
|
---
|
||||||
|
|
||||||
|
Content inside `docs/index.md`
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
layout: layout-default
|
||||||
|
---
|
||||||
|
|
||||||
|
Content inside `docs/sub.md`
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/** @type {Partial<import("../../../types/main").RocketCliOptions>} */
|
||||||
|
const config = {
|
||||||
|
pathPrefix: '/my-prefix-folder/',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
/** @type {Partial<import("../../../types/main").RocketCliOptions>} */
|
||||||
|
const config = {};
|
||||||
|
export default config;
|
||||||
Reference in New Issue
Block a user