Skip to content

Commit 7b52dc4

Browse files
authored
Rollup bundles in generateSW, and more for v5 (#2068)
* WIP. * GenerateSW with code splitting * More WIP. * WIP/ * Support a custom fs for rollup output * Separate the bundling from the writing * Remove generateSWString * Remove the generateSWString test * Use underscore separators. * Test remidiation. * generateSW test remediation * Linting. * Fixed the InjectManifest tests. * Fixed getManfiest test. * Added an extra dependency. * populateSWTemplate isn't async * bundle and escape-regexp unit tests * Test for the existence of output files. * Return filePaths from build commands. * Change to log message. * Ensure swSrc and swDest are different * Set moduleSideEffects to false * Explicitly require @babel/preset-env * Review feedback * Review feedback. * __WB_MANIFEST again * Use a module registry * Linting. * Review feedback.
1 parent 8379c51 commit 7b52dc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3293
-1369
lines changed

infra/testing/validator/service-worker-runtime.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function stringifyFunctionsInArray(arr) {
1818
return arr.map((item) => typeof item === 'function' ? item.toString() : item);
1919
}
2020

21-
function setupSpiesAndContext() {
21+
function setupSpiesAndContextForInjectManifest() {
2222
const cacheableResponsePluginSpy = sinon.spy();
2323
class CacheableResponsePlugin {
2424
constructor(...args) {
@@ -101,6 +101,39 @@ function setupSpiesAndContext() {
101101
return {addEventListener, context, methodsToSpies};
102102
}
103103

104+
function setupSpiesAndContextForGenerateSW() {
105+
const addEventListener = sinon.spy();
106+
const importScripts = sinon.spy();
107+
108+
const workboxContext = {
109+
CacheFirst: sinon.stub().returns({name: 'CacheFirst'}),
110+
clientsClaim: sinon.spy(),
111+
enable: sinon.spy(),
112+
getCacheKeyForURL: sinon.stub().returns('/urlWithCacheKey'),
113+
initialize: sinon.spy(),
114+
NetworkFirst: sinon.stub().returns({name: 'NetworkFirst'}),
115+
Plugin: sinon.spy(),
116+
Plugin$1: sinon.spy(),
117+
Plugin$2: sinon.spy(),
118+
precacheAndRoute: sinon.spy(),
119+
registerNavigationRoute: sinon.spy(),
120+
registerRoute: sinon.spy(),
121+
setCacheNameDetails: sinon.spy(),
122+
skipWaiting: sinon.spy(),
123+
};
124+
125+
const context = Object.assign({
126+
importScripts,
127+
define: (_, scripts, callback) => {
128+
importScripts(...scripts);
129+
callback(workboxContext);
130+
},
131+
}, makeServiceWorkerEnv());
132+
context.self.addEventListener = addEventListener;
133+
134+
return {addEventListener, context, methodsToSpies: workboxContext};
135+
}
136+
104137
function validateMethodCalls({methodsToSpies, expectedMethodCalls}) {
105138
for (const [method, spy] of Object.entries(methodsToSpies)) {
106139
if (spy.called) {
@@ -132,6 +165,7 @@ function validateMethodCalls({methodsToSpies, expectedMethodCalls}) {
132165
*/
133166
module.exports = async ({
134167
addEventListenerValidation,
168+
entryPoint,
135169
expectedMethodCalls,
136170
swFile,
137171
swString,
@@ -143,7 +177,9 @@ module.exports = async ({
143177
swString = await fse.readFile(swFile, 'utf8');
144178
}
145179

146-
const {addEventListener, context, methodsToSpies} = setupSpiesAndContext();
180+
const {addEventListener, context, methodsToSpies} = entryPoint === 'injectManifest' ?
181+
setupSpiesAndContextForInjectManifest() :
182+
setupSpiesAndContextForGenerateSW();
147183

148184
vm.runInNewContext(swString, context);
149185

package-lock.json

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)