Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate streams tests to run in a SW environment #2000

Merged
merged 2 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions gulp-tasks/test-integration.js
Original file line number Diff line number Diff line change
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'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉


await runFiles(testFiles);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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;
}
});
});
Original file line number Diff line number Diff line change
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));
});
});