Skip to content

refactor: tests #3462

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

Merged
merged 2 commits into from
Jun 21, 2021
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
28 changes: 14 additions & 14 deletions test/cli/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ describe('basic', () => {
expect(normalizeStderr(stderr)).toMatchSnapshot('stderr');
});

it('should accept the promise function of webpack.config.js', (done) => {
testBin(
false,
path.resolve(__dirname, '../fixtures/promise-config/webpack.config.js')
)
.then((output) => {
expect(output.exitCode).toEqual(0);
done();
})
.catch((err) => {
// for windows
expect(err.stdout).toContain('main.js');
done();
});
it('should accept the promise function of webpack.config.js', async () => {
try {
const { exitCode } = await testBin(
false,
path.resolve(
__dirname,
'../fixtures/promise-config/webpack.config.js'
)
);
expect(exitCode).toEqual(0);
} catch (err) {
// for windows
expect(err.stdout).toContain('main.js');
}
});

it('should exit the process when SIGINT is detected', (done) => {
Expand Down
11 changes: 6 additions & 5 deletions test/integration/MultiCompiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ describe('multi compiler', () => {

afterAll(testServer.close);

it('should handle GET request to bundle', (done) => {
req
.get('/main.js')
.expect('Content-Type', 'application/javascript; charset=utf-8')
.expect(200, done);
it('should handle GET request to bundle', async () => {
const res = await req.get('/main.js');
expect(res.headers['content-type']).toEqual(
'application/javascript; charset=utf-8'
);
expect(res.status).toEqual(200);
});
});
42 changes: 16 additions & 26 deletions test/integration/UniversalCompiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,25 @@ describe('universal compiler', () => {

afterAll(testServer.close);

it('client bundle should have the inlined the client runtime', (done) => {
req
.get('/client.js')
.expect('Content-Type', 'application/javascript; charset=utf-8')
.expect(200)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res.text).toContain('Hello from the client');
expect(res.text).toContain('WebsocketClient');
done();
});
it('client bundle should have the inlined the client runtime', async () => {
const res = await req.get('/client.js');
expect(res.headers['content-type']).toEqual(
'application/javascript; charset=utf-8'
);
expect(res.status).toEqual(200);
expect(res.text).toContain('Hello from the client');
expect(res.text).toContain('WebsocketClient');
});

it('server bundle should NOT have the inlined the client runtime', (done) => {
it('server bundle should NOT have the inlined the client runtime', async () => {
// we wouldn't normally request a server bundle
// but we'll do it here to check the contents
req
.get('/server.js')
.expect('Content-Type', 'application/javascript; charset=utf-8')
.expect(200)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res.text).toContain('Hello from the server');
expect(res.text).not.toContain('WebsocketClient');
done();
});
const res = await req.get('/server.js');
expect(res.headers['content-type']).toEqual(
'application/javascript; charset=utf-8'
);
expect(res.status).toEqual(200);
expect(res.text).toContain('Hello from the server');
expect(res.text).not.toContain('WebsocketClient');
});
});
10 changes: 6 additions & 4 deletions test/server/client-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ describe('client option', () => {
expect(server.options.client.overlay).toBe(true);
});

it('responds with a 200', (done) => {
req.get('/ws').expect(200, done);
it('responds with a 200', async () => {
const res = await req.get('/ws');
expect(res.status).toEqual(200);
});
});

Expand Down Expand Up @@ -65,8 +66,9 @@ describe('client option', () => {
req = request(`http://localhost:${port}`);
});

it('responds with a 200 second', (done) => {
req.get(path).expect(200, done);
it('responds with a 200 second', async () => {
const res = await req.get(path);
expect(res.status).toEqual(200);
});
});

Expand Down
26 changes: 13 additions & 13 deletions test/server/compress-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ describe('compress option', () => {

afterAll(testServer.close);

it('request to bundle file', (done) => {
req.get('/main.js').expect('Content-Encoding', 'gzip').expect(200, done);
it('request to bundle file', async () => {
const res = await req.get('/main.js');
expect(res.headers['content-encoding']).toEqual('gzip');
expect(res.status).toEqual(200);
});
});

Expand All @@ -42,8 +44,10 @@ describe('compress option', () => {

afterAll(testServer.close);

it('request to bundle file', (done) => {
req.get('/main.js').expect('Content-Encoding', 'gzip').expect(200, done);
it('request to bundle file', async () => {
const res = await req.get('/main.js');
expect(res.headers['content-encoding']).toEqual('gzip');
expect(res.status).toEqual(200);
});
});

Expand All @@ -62,15 +66,11 @@ describe('compress option', () => {

afterAll(testServer.close);

it('request to bundle file', (done) => {
req
.get('/main.js')
.expect((res) => {
if (res.header['content-encoding']) {
throw new Error('Expected `content-encoding` header is undefined.');
}
})
.expect(200, done);
it('request to bundle file', async () => {
const res = await req.get('/main.js');
// eslint-disable-next-line no-undefined
expect(res.headers['content-encoding']).toEqual(undefined);
expect(res.status).toEqual(200);
});
});
});
24 changes: 16 additions & 8 deletions test/server/headers-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ describe('headers option', () => {

afterAll(testServer.close);

it('GET request with headers', (done) => {
req.get('/main').expect('X-Foo', '1').expect(200, done);
it('GET request with headers', async () => {
const res = await req.get('/main.js');
expect(res.headers['x-foo']).toEqual('1');
expect(res.status).toEqual(200);
});
});

Expand All @@ -44,10 +46,12 @@ describe('headers option', () => {

afterAll(testServer.close);

it('GET request with headers as an array', (done) => {
it('GET request with headers as an array', async () => {
// https://github.com/webpack/webpack-dev-server/pull/1650#discussion_r254217027
const expected = 'key1=value1, key2=value2';
req.get('/main').expect('X-Bar', expected).expect(200, done);
const res = await req.get('/main.js');
expect(res.headers['x-bar']).toEqual(expected);
expect(res.status).toEqual(200);
});
});

Expand All @@ -68,10 +72,12 @@ describe('headers option', () => {

afterAll(testServer.close);

it('GET request with headers as a function', (done) => {
it('GET request with headers as a function', async () => {
// https://github.com/webpack/webpack-dev-server/pull/1650#discussion_r254217027
const expected = 'key1=value1, key2=value2';
req.get('/main').expect('X-Bar', expected).expect(200, done);
const res = await req.get('/main.js');
expect(res.headers['x-bar']).toEqual(expected);
expect(res.status).toEqual(200);
});
});

Expand All @@ -93,8 +99,10 @@ describe('headers option', () => {

afterAll(testServer.close);

it('GET request with headers', (done) => {
req.get('/main.js').expect('X-Foo', '2').expect(200, done);
it('GET request with headers', async () => {
const res = await req.get('/main.js');
expect(res.headers['x-foo']).toEqual('2');
expect(res.status).toEqual(200);
});
});
});
Loading