Skip to content

Commit

Permalink
test(server): rearrange bad host test
Browse files Browse the repository at this point in the history
  • Loading branch information
knagaitsev committed Jul 1, 2019
1 parent dd87441 commit 34f3219
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion test/server/__snapshots__/serverMode-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`serverMode option with a bad host header results in an error 1`] = `
exports[`serverMode option passed to server with a bad host header results in an error 1`] = `
Array [
"open",
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
Expand Down
130 changes: 65 additions & 65 deletions test/server/serverMode-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,80 +229,80 @@ describe('serverMode option', () => {
}).toThrow(/serverMode must be a string/);
});
});
});

describe('with a bad host header', () => {
beforeAll((done) => {
server = testServer.start(
config,
{
port,
serverMode: class MySockJSServer extends BaseServer {
constructor(serv) {
super(serv);
this.socket = sockjs.createServer({
// Use provided up-to-date sockjs-client
sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js',
// Limit useless logs
log: (severity, line) => {
if (severity === 'error') {
this.server.log.error(line);
} else {
this.server.log.debug(line);
}
},
});

this.socket.installHandlers(this.server.listeningApp, {
prefix: this.server.sockPath,
});
}

send(connection, message) {
connection.write(message);
}

close(connection) {
connection.close();
}

onConnection(f) {
this.socket.on('connection', (connection) => {
f(connection, {
host: null,
describe('with a bad host header', () => {
beforeAll((done) => {
server = testServer.start(
config,
{
port,
serverMode: class MySockJSServer extends BaseServer {
constructor(serv) {
super(serv);
this.socket = sockjs.createServer({
// Use provided up-to-date sockjs-client
sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js',
// Limit useless logs
log: (severity, line) => {
if (severity === 'error') {
this.server.log.error(line);
} else {
this.server.log.debug(line);
}
},
});
});
}

onConnectionClose(connection, f) {
connection.on('close', f);
}
this.socket.installHandlers(this.server.listeningApp, {
prefix: this.server.sockPath,
});
}

send(connection, message) {
connection.write(message);
}

close(connection) {
connection.close();
}

onConnection(f) {
this.socket.on('connection', (connection) => {
f(connection, {
host: null,
});
});
}

onConnectionClose(connection, f) {
connection.on('close', f);
}
},
},
},
done
);
});
done
);
});

it('results in an error', (done) => {
const data = [];
const client = new SockJS(`http://localhost:${port}/sockjs-node`);
it('results in an error', (done) => {
const data = [];
const client = new SockJS(`http://localhost:${port}/sockjs-node`);

client.onopen = () => {
data.push('open');
};
client.onopen = () => {
data.push('open');
};

client.onmessage = (e) => {
data.push(e.data);
};
client.onmessage = (e) => {
data.push(e.data);
};

client.onclose = () => {
data.push('close');
};
client.onclose = () => {
data.push('close');
};

setTimeout(() => {
expect(data).toMatchSnapshot();
done();
}, 5000);
setTimeout(() => {
expect(data).toMatchSnapshot();
done();
}, 5000);
});
});
});
});

0 comments on commit 34f3219

Please sign in to comment.