Skip to content

Commit

Permalink
test: update syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Aug 5, 2019
1 parent 4cc6f61 commit d0893f1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 63 deletions.
8 changes: 3 additions & 5 deletions test/cli/cli.test.js
Expand Up @@ -25,9 +25,7 @@ describe('CLI', () => {
const { code, stderr } = await testBin('--progress --profile');
expect(code).toEqual(0);
// should profile
expect(output.stderr.includes('after chunk modules optimization')).toBe(
true
);
expect(stderr.includes('after chunk modules optimization')).toBe(true);
});

it('--bonjour', async () => {
Expand Down Expand Up @@ -58,8 +56,8 @@ describe('CLI', () => {
});

it('unspecified port', async () => {
const { output } = await testBin('');
expect(/http:\/\/localhost:[0-9]+/.test(output.stdout)).toEqual(true);
const { stdout } = await testBin('');
expect(/http:\/\/localhost:[0-9]+/.test(stdout)).toEqual(true);
});

it('--color', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/client/socket-helper.test.js
Expand Up @@ -8,7 +8,7 @@ describe('socket', () => {

it('should default to SockJSClient when no __webpack_dev_server_client__ set', () => {
jest.mock('../../client/clients/SockJSClient');
const socket = require('../../client/socket');
const { default: socket } = require('../../client/socket');
const SockJSClient = require('../../client/clients/SockJSClient');

const mockHandler = jest.fn();
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('socket', () => {

it('should use __webpack_dev_server_client__ when set', () => {
jest.mock('../../client/clients/SockJSClient');
const socket = require('../../client/socket');
const { default: socket } = require('../../client/socket');
global.__webpack_dev_server_client__ = require('../../client/clients/SockJSClient');

const mockHandler = jest.fn();
Expand Down
75 changes: 30 additions & 45 deletions test/e2e/ClientOptions.test.js
Expand Up @@ -50,19 +50,17 @@ describe('Client code', () => {
});

afterAll((done) => {
proxy.close(() => {
done();
});
proxy.close(done);
});

it('responds with a 200', (done) => {
it('responds with a 200', async () => {
{
const req = request(`http://localhost:${port2}`);
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
await req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n');
}
{
const req = request(`http://localhost:${port1}`);
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
await req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n');
}
});

Expand Down Expand Up @@ -297,47 +295,34 @@ describe('Client console.log', () => {
},
];

cases.forEach(({ title, options }) => {
it(title, (done) => {
for (const { title, options } of cases) {
it(title, async () => {
const res = [];
const testOptions = Object.assign({}, baseOptions, options);

// TODO: use async/await when Node.js v6 support is dropped
Promise.resolve()
.then(() => {
return new Promise((resolve) => {
testServer.startAwaitingCompilation(config, testOptions, resolve);
});
})
.then(() => {
// make sure the previous Promise is not passing along strange arguments to runBrowser
return runBrowser();
})
.then(({ page, browser }) => {
return new Promise((resolve) => {
page.goto(`http://localhost:${port2}/main`);
page.on('console', ({ _text }) => {
res.push(_text);
});
// wait for load before closing the browser
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
resolve();
});
});
});
});
})
.then(() => {
return new Promise((resolve) => {
testServer.close(resolve);
});
})
.then(() => {
expect(res).toMatchSnapshot();
done();
});
// TODO: refactor(hiroppy)
await new Promise((resolve) => {
testServer.startAwaitingCompilation(config, testOptions, resolve);
});

const { page, browser } = await runBrowser();

page.goto(`http://localhost:${port2}/main`);
page.on('console', ({ _text }) => {
res.push(_text);
});

// wait for load before closing the browser
await page.waitForNavigation({ waitUntil: 'load' });
await page.waitFor(beforeBrowserCloseDelay);
await browser.close();

expect(res).toMatchSnapshot();

// TODO: refactor(hiroppy)
await new Promise((resolve) => {
testServer.close(resolve);
});
});
});
}
});
3 changes: 2 additions & 1 deletion test/server/servers/SockJSServer.test.js
Expand Up @@ -37,7 +37,8 @@ describe('SockJSServer', () => {
const data = [];
let headers;

socketServer.onConnection(async (connection) => {
socketServer.onConnection(async (connection, h) => {
headers = h;
data.push('open');
socketServer.send(connection, 'hello world');

Expand Down
20 changes: 10 additions & 10 deletions test/server/utils/runOpen.test.js
Expand Up @@ -78,13 +78,14 @@ describe('runOpen util', () => {
});
});

it('on specify absolute https URL with page in Google Chrome ', () => {
return runOpen(
it('on specify absolute https URL with page in Google Chrome ', async () => {
await runOpen(
'https://example.com',
{ open: 'Google Chrome', openPage: 'https://example2.com' },
console
).then(() => {
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
);

expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example2.com",
Object {
Expand All @@ -93,16 +94,16 @@ describe('runOpen util', () => {
},
]
`);
});
});

it('on specify absolute http URL with page in Google Chrome ', () => {
return runOpen(
it('on specify absolute http URL with page in Google Chrome ', async () => {
runOpen(
'https://example.com',
{ open: 'Google Chrome', openPage: 'http://example2.com' },
console
).then(() => {
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
);

expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"http://example2.com",
Object {
Expand All @@ -111,7 +112,6 @@ describe('runOpen util', () => {
},
]
`);
});
});

describe('should not open browser', () => {
Expand Down

0 comments on commit d0893f1

Please sign in to comment.