Skip to content

Commit

Permalink
Merge pull request #2000 from GoogleChrome/migrate-streams-tests
Browse files Browse the repository at this point in the history
Migrate streams tests to run in a SW environment
  • Loading branch information
philipwalton committed Apr 2, 2019
2 parents adef0e2 + 10d3568 commit bb78e35
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 111 deletions.
21 changes: 1 addition & 20 deletions gulp-tasks/test-integration.js
Expand Up @@ -66,27 +66,8 @@ const runIntegrationTestSuite = async (testPath, nodeEnv, seleniumBrowser,
webdriver,
};

// Use a whitelist while we're migrating node tests to browser tests.
let testMatcher;
if (testPath.includes('workbox-background-sync') ||
testPath.includes('workbox-broadcast-update') ||
testPath.includes('workbox-cacheable-response') ||
testPath.includes('workbox-core') ||
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 {
testMatcher = '*.js';
}

const testFiles = glob.sync(
path.posix.join(__dirname, '..', testPath, testMatcher));
path.posix.join(__dirname, '..', testPath, 'test-*.js'));

await runFiles(testFiles);
} catch (err) {
Expand Down
Expand Up @@ -7,22 +7,32 @@
*/

const {expect} = require('chai');

const activateAndControlSW = require('../../../infra/testing/activate-and-control');
const {runUnitTests} = require('../../../infra/testing/webdriver/runUnitTests');


// Store local references of these globals.
const {webdriver, server} = global.__workbox;

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

describe(`[workbox-streams] Integration Tests`, function() {
const testServerAddress = global.__workbox.server.getAddress();
const testServerAddress = server.getAddress();
const testingURL = `${testServerAddress}/test/workbox-streams/static/`;
const swURL = `${testingURL}sw.js`;

before(async function() {
await global.__workbox.webdriver.get(testingURL);
await webdriver.get(testingURL);
await activateAndControlSW(swURL);
});

for (const testCase of ['concatenate', 'concatenateToResponse', 'strategy']) {
it(`should return the expected response for the '${testCase}' approach`, async function() {
const {text, headers} = await global.__workbox.webdriver.executeAsyncScript(async (testCase, cb) => {
const {text, headers} = await webdriver.executeAsyncScript(async (testCase, cb) => {
try {
const response = await fetch(new URL(testCase, location));
const headers = [...response.headers].sort((a, b) => {
Expand Down
25 changes: 0 additions & 25 deletions test/workbox-streams/node/test-exports.mjs

This file was deleted.

51 changes: 0 additions & 51 deletions test/workbox-streams/node/test-isSupported.mjs

This file was deleted.

22 changes: 22 additions & 0 deletions test/workbox-streams/sw/test-isSupported.mjs
@@ -0,0 +1,22 @@
/*
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.
*/

import {isSupported} from 'workbox-streams/isSupported.mjs';


describe(`isSupported`, function() {
it(`should return true when ReadableStream is available`, async function() {
try {
new ReadableStream({start() {}});

expect(isSupported()).to.be.true;
} catch (error) {
expect(isSupported()).to.be.false;
}
});
});
Expand Up @@ -6,26 +6,26 @@
https://opensource.org/licenses/MIT.
*/

import {expect} from 'chai';
import sinon from 'sinon';
import {createHeaders} from 'workbox-streams/utils/createHeaders.mjs';

import {createHeaders} from '../../../../packages/workbox-streams/utils/createHeaders.mjs';

describe(`[workbox-streams] utils/createHeaders`, function() {
describe(`createHeaders`, function() {
const sandbox = sinon.createSandbox();

beforeEach(function() {
sandbox.restore();
});

afterEach(function() {
sandbox.restore();
});

const DEFAULT_CONTENT_TYPE = ['content-type', 'text/html'];

it(`should use the default Content-Type, and construct with an empty object, when headersInit is undefined`, function() {
const headersSpy = sandbox.spy(global, 'Headers');
const headersSpy = sandbox.spy(self, 'Headers');
const headers = createHeaders();
expect(headers.entries()).to.eql([
DEFAULT_CONTENT_TYPE,
]);
expect([...headers]).to.eql([DEFAULT_CONTENT_TYPE]);
expect(headersSpy.calledOnce).to.be.true;
// See https://github.com/GoogleChrome/workbox/issues/1461
expect(headersSpy.args[0][0]).to.eql({});
Expand All @@ -37,9 +37,10 @@ describe(`[workbox-streams] utils/createHeaders`, function() {
'x-two': '2',
};
const headers = createHeaders(headersInit);
expect(headers.entries()).to.eql([
...Object.entries(headersInit),

expect([...headers]).to.eql([
DEFAULT_CONTENT_TYPE,
...Object.entries(headersInit),
]);
});

Expand All @@ -48,6 +49,6 @@ describe(`[workbox-streams] utils/createHeaders`, function() {
'content-type': 'text/plain',
};
const headers = createHeaders(headersInit);
expect(headers.entries()).to.eql(Object.entries(headersInit));
expect([...headers]).to.eql(Object.entries(headersInit));
});
});

0 comments on commit bb78e35

Please sign in to comment.