Skip to content

Commit

Permalink
adapt some tests for commit fixing parcel-bundler#1794
Browse files Browse the repository at this point in the history
tests use the ws library to establish a websocket connection, and they
have an undefined origin by default. This is changed

tests have no defined hmrHostname so it was set too.
  • Loading branch information
Carlos Requena L贸pez committed Jan 2, 2019
1 parent 8231917 commit c1d187e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
61 changes: 44 additions & 17 deletions packages/core/integration-tests/test/hmr.js
Expand Up @@ -48,14 +48,17 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
await b.bundle();

ws = new WebSocket('ws://localhost:' + b.options.hmrPort);
ws = new WebSocket('ws://localhost:' + b.options.hmrPort, {
origin: 'http://localhost:1234'
});

const buildEnd = nextEvent(b, 'buildEnd');
await sleep(100);

fs.writeFile(
path.join(__dirname, '/input/local.js'),
'exports.a = 5;\nexports.b = 5;'
Expand All @@ -79,6 +82,7 @@ describe('hmr', function() {
b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true,
hmrHostname: 'localhost',
target: 'node'
});
await b.bundle();
Expand All @@ -103,7 +107,9 @@ describe('hmr', function() {
});
await b.bundle();

ws = new WebSocket('ws://localhost:' + b.options.hmrPort);
ws = new WebSocket('ws://localhost:' + b.options.hmrPort, {
origin: 'http://localhost:1234'
});

const buildEnd = nextEvent(b, 'buildEnd');

Expand All @@ -130,11 +136,14 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
await b.bundle();

ws = new WebSocket('ws://localhost:' + b.options.hmrPort);
ws = new WebSocket('ws://localhost:' + b.options.hmrPort, {
origin: 'http://localhost:1234'
});

const buildEnd = nextEvent(b, 'buildEnd');

Expand All @@ -159,11 +168,14 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
await b.bundle();

ws = new WebSocket('ws://localhost:' + b.options.hmrPort);
ws = new WebSocket('ws://localhost:' + b.options.hmrPort, {
origin: 'http://localhost:1234'
});

const buildEnd = nextEvent(b, 'buildEnd');

Expand Down Expand Up @@ -198,7 +210,8 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
await b.bundle();

Expand All @@ -210,7 +223,9 @@ describe('hmr', function() {
await nextEvent(b, 'buildEnd');
await sleep(50);

ws = new WebSocket('ws://localhost:' + b.options.hmrPort);
ws = new WebSocket('ws://localhost:' + b.options.hmrPort, {
origin: 'http://localhost:1234'
});
let msg = JSON.parse(await nextEvent(ws, 'message'));
assert.equal(msg.type, 'error');
});
Expand All @@ -223,11 +238,14 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
await b.bundle();

ws = new WebSocket('ws://localhost:' + b.options.hmrPort);
ws = new WebSocket('ws://localhost:' + b.options.hmrPort, {
origin: 'http://localhost:1234'
});

const firstBuildEnd = nextEvent(b, 'buildEnd');

Expand Down Expand Up @@ -264,7 +282,8 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
let bundle = await b.bundle();
let outputs = [];
Expand Down Expand Up @@ -295,7 +314,8 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
let bundle = await b.bundle();
let outputs = [];
Expand Down Expand Up @@ -336,7 +356,8 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
let bundle = await b.bundle();
let outputs = [];
Expand Down Expand Up @@ -369,7 +390,8 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
let bundle = await b.bundle();

Expand Down Expand Up @@ -410,7 +432,8 @@ describe('hmr', function() {

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
hmr: true,
hmrHostname: 'localhost'
});
let bundle = await b.bundle();

Expand Down Expand Up @@ -468,11 +491,13 @@ describe('hmr', function() {
b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true,
hmrHostname: 'localhost',
https: true
});
await b.bundle();

ws = new WebSocket('wss://localhost:' + b.options.hmrPort, {
origin: 'http://localhost:1234',
rejectUnauthorized: false
});

Expand Down Expand Up @@ -502,6 +527,7 @@ describe('hmr', function() {
b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true,
hmrHostname: 'localhost',
https: {
key: path.join(__dirname, '/integration/https/private.pem'),
cert: path.join(__dirname, '/integration/https/primary.crt')
Expand All @@ -510,6 +536,7 @@ describe('hmr', function() {
await b.bundle();

ws = new WebSocket('wss://localhost:' + b.options.hmrPort, {
origin: 'http://localhost:1234',
rejectUnauthorized: false
});

Expand Down
5 changes: 4 additions & 1 deletion packages/core/integration-tests/test/utils.js
Expand Up @@ -112,7 +112,10 @@ function prepareBrowserContext(bundle, globals) {
document: fakeDocument,
WebSocket,
console,
location: {hostname: 'localhost'},
location: {
hostname: 'localhost',
origin: 'http://localhost:1234'
},
fetch(url) {
return Promise.resolve({
arrayBuffer() {
Expand Down

0 comments on commit c1d187e

Please sign in to comment.