mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-21 15:54:57 +00:00
Compare commits
2 Commits
@rocket/cl
...
@rocket/cl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5f2d69d0c | ||
|
|
795a3613af |
@@ -1,5 +1,11 @@
|
|||||||
# @rocket/cli
|
# @rocket/cli
|
||||||
|
|
||||||
|
## 0.9.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 795a361: The server worker url should respect a set pathPrefix.
|
||||||
|
|
||||||
## 0.9.2
|
## 0.9.2
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rocket/cli",
|
"name": "@rocket/cli",
|
||||||
"version": "0.9.2",
|
"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>
|
||||||
|
|||||||
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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