Skip to content

Commit

Permalink
Merge pull request #1996 from GoogleChrome/migrate-strategies-tests
Browse files Browse the repository at this point in the history
Migrate strategies tests to run in a SW environment
  • Loading branch information
philipwalton committed Apr 2, 2019
2 parents 76ba317 + 90756b4 commit 2cc0f8b
Show file tree
Hide file tree
Showing 22 changed files with 1,338 additions and 1,509 deletions.
4 changes: 4 additions & 0 deletions gulp-tasks/test-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const runIntegrationTestSuite = async (testPath, nodeEnv, seleniumBrowser,
testPath.includes('workbox-expiration') ||
testPath.includes('workbox-google-analytics') ||
testPath.includes('workbox-navigation-preload') ||
testPath.includes('workbox-precaching') ||
testPath.includes('workbox-range-requests') ||
testPath.includes('workbox-routing') ||
testPath.includes('workbox-strategies') ||
testPath.includes('workbox-window')) {
testMatcher = 'test-*.js';
} else {
Expand Down
23 changes: 23 additions & 0 deletions infra/testing/helpers/compareResponses.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/


const compareResponses = async (first, second, shouldBeSame) => {
const firstBody = await first.clone().text();
const secondBody = await second.clone().text();

if (shouldBeSame) {
expect(firstBody).to.equal(secondBody);
} else {
expect(firstBody).to.not.equal(secondBody);
}
};

export {
compareResponses,
};
11 changes: 7 additions & 4 deletions infra/testing/helpers/extendable-event-utils.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 Google LLC
Copyright 2019 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
Expand All @@ -10,13 +10,16 @@
const extendLifetimePromises = new WeakMap();
const eventResponses = new WeakMap();

export const eventDoneWaiting = async (event) => {
export const eventDoneWaiting = async (event, {catchErrors = true} = {}) => {
const promises = extendLifetimePromises.get(event);
let promise;

while (promise = promises.shift()) {
// Ignore errors.
await promise.catch((e) => e);
// Ignore errors by default;
if (catchErrors) {
promise = promise.catch((e) => e);
}
await promise;
}
};

Expand Down
18 changes: 18 additions & 0 deletions infra/testing/helpers/generateOpaqueResponse.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2019 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/


// Cache a resonse value and clone it instead of re-fetching every time.
let response;

export const generateOpaqueResponse = async () => {
if (!response) {
response = await fetch('https://google.com', {mode: 'no-cors'});
}
return response.clone();
};
14 changes: 14 additions & 0 deletions infra/testing/helpers/generateUniqueResponse.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Copyright 2019 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/


let uid = 0;

export const generateUniqueResponse = (responseInit = {}) => {
return new Response(`${++uid}`, responseInit);
};
15 changes: 15 additions & 0 deletions infra/testing/helpers/sleep.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright 2019 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/

/**
* Asynchronously waits for the passed number of milliseconds.
*
* @param {number} ms
* @return {Promise}
*/
export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
16 changes: 16 additions & 0 deletions test/workbox-strategies/integration/test-sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Copyright 2019 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/

const {runUnitTests} = require('../../../infra/testing/webdriver/runUnitTests');


describe(`[workbox-strategies]`, function() {
it(`passes all SW unit tests`, async function() {
await runUnitTests('/test/workbox-strategies/sw/');
});
});

0 comments on commit 2cc0f8b

Please sign in to comment.