Skip to content

Commit 6f6bfdd

Browse files
test: fix
1 parent c257cf3 commit 6f6bfdd

File tree

8 files changed

+6670
-7269
lines changed

8 files changed

+6670
-7269
lines changed

package-lock.json

Lines changed: 6633 additions & 7229 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/client/bundle.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe('bundle', () => {
4848

4949
expect(() => {
5050
let evalStep = 0;
51+
5152
acorn.parse(text, {
5253
ecmaVersion: 5,
5354
onToken: (token) => {

test/client/clients/SockJSClient.test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const express = require('express');
55
const sockjs = require('sockjs');
66
const port = require('../../ports-map').sockJSClient;
77

8-
jest.setMock('../../../client-src/utils/log', {
8+
jest.setMock('../../../client-src/modules/logger', {
99
log: {
1010
error: jest.fn(),
1111
},
1212
});
1313

1414
describe('SockJSClient', () => {
1515
const SockJSClient = require('../../../client-src/clients/SockJSClient');
16-
const { log } = require('../../../client-src/utils/log');
16+
const { log } = require('../../../client-src/modules/logger');
1717
let consoleMock;
1818
let socketServer;
1919
let server;
@@ -62,24 +62,31 @@ describe('SockJSClient', () => {
6262
});
6363

6464
const testError = new Error('test');
65+
6566
client.sock.onerror(testError);
6667

6768
expect(log.error.mock.calls.length).toEqual(1);
6869
expect(log.error.mock.calls[0]).toEqual([testError]);
6970

7071
setTimeout(() => {
7172
expect(data).toMatchSnapshot();
73+
7274
done();
7375
}, 3000);
7476
});
77+
7578
it('should change the protocol from chrome-extension to http', (done) => {
7679
const client = new SockJSClient('chrome-extension://localhost');
80+
7781
expect(client.sock.url).toEqual('http://localhost');
82+
7883
done();
7984
});
85+
8086
it('should change the protocol from file to http', (done) => {
8187
const client = new SockJSClient('file://localhost');
8288
expect(client.sock.url).toEqual('http://localhost');
89+
8390
done();
8491
});
8592
});

test/client/clients/WebsocketClient.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ const express = require('express');
55
const ws = require('ws');
66
const port = require('../../ports-map').WebsocketClient;
77

8-
jest.setMock('../../../client-src/utils/log', {
8+
jest.setMock('../../../client-src/modules/logger', {
99
log: {
1010
error: jest.fn(),
1111
},
1212
});
1313

1414
describe('WebsocketClient', () => {
1515
const WebsocketClient = require('../../../client-src/clients/WebsocketClient');
16-
const { log } = require('../../../client-src/utils/log');
16+
const { log } = require('../../../client-src/modules/logger');
17+
1718
let socketServer;
1819
let server;
1920

@@ -55,24 +56,32 @@ describe('WebsocketClient', () => {
5556
});
5657

5758
const testError = new Error('test');
59+
5860
client.client.onerror(testError);
5961

6062
expect(log.error.mock.calls.length).toEqual(1);
6163
expect(log.error.mock.calls[0]).toEqual([testError]);
6264

6365
setTimeout(() => {
6466
expect(data).toMatchSnapshot();
67+
6568
done();
6669
}, 3000);
6770
});
71+
6872
it('should change the protocol from chrome-extension to http', (done) => {
6973
const client = new WebsocketClient('chrome-extension://localhost/');
74+
7075
expect(client.client.url).toEqual('ws://localhost/');
76+
7177
done();
7278
});
79+
7380
it('should change the protocol from file to http', (done) => {
7481
const client = new WebsocketClient('file://localhost/');
82+
7583
expect(client.client.url).toEqual('ws://localhost/');
84+
7685
done();
7786
});
7887
});

test/client/index.test.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,36 @@ describe('index', () => {
1414
global.__resourceQuery = 'foo';
1515

1616
// log
17-
jest.setMock('../../../client-src/modules/logger', {
17+
jest.setMock('../../client-src/utils/log.js', {
1818
log: {
1919
info: jest.fn(),
2020
warn: jest.fn(),
2121
error: jest.fn(),
2222
},
2323
});
24-
log = require('../../client-src/modules/logger');
24+
log = require('../../client-src/utils/log');
2525

2626
// socket
27-
jest.setMock('../../client-src/default/socket.js', jest.fn());
27+
jest.setMock('../../client-src/socket.js', jest.fn());
2828
socket = require('../../client-src/socket');
2929

3030
// overlay
31-
jest.setMock('../../client-src/default/overlay.js', {
31+
jest.setMock('../../client-src/overlay.js', {
3232
clear: jest.fn(),
3333
showMessage: jest.fn(),
3434
});
3535
overlay = require('../../client-src/overlay');
3636

3737
// reloadApp
38-
jest.setMock('../../client-src/default/utils/reloadApp.js', jest.fn());
38+
jest.setMock('../../client-src/utils/reloadApp.js', jest.fn());
3939
reloadApp = require('../../client-src/utils/reloadApp');
4040

4141
// sendMessage
42-
jest.setMock('../../client-src/default/utils/sendMessage.js', jest.fn());
42+
jest.setMock('../../client-src/utils/sendMessage.js', jest.fn());
4343
sendMessage = require('../../client-src/utils/sendMessage');
4444

4545
// createSocketUrl
46-
jest.setMock(
47-
'../../client-src/default/utils/createSocketUrl.js',
48-
() => 'mock-url'
49-
);
46+
jest.setMock('../../client-src/utils/createSocketUrl.js', () => 'mock-url');
5047

5148
// issue: https://github.com/jsdom/jsdom/issues/2112
5249
delete window.location;

test/client/utils/createSocketUrl.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ describe('createSocketUrl', () => {
1717
];
1818

1919
samples.forEach((url) => {
20-
jest.doMock(
21-
'../../../client-src/default/utils/getCurrentScriptSource.js',
22-
() => () => url
20+
jest.doMock('../../../client-src/utils/getCurrentScriptSource', () => () =>
21+
url
2322
);
2423

2524
const createSocketUrl = require('../../../client-src/utils/createSocketUrl');
@@ -50,7 +49,7 @@ describe('createSocketUrl', () => {
5049

5150
samples2.forEach(([scriptSrc, loc, expected]) => {
5251
jest.doMock(
53-
'../../../client-src/default/utils/getCurrentScriptSource.js',
52+
'../../../client-src/utils/getCurrentScriptSource.js',
5453
() => () => scriptSrc
5554
);
5655

test/e2e/DevServer.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('DevServer', () => {
1010
testBin(null, './test/fixtures/dev-server/default-config.js')
1111
.then((output) => {
1212
expect(output.exitCode).toEqual(0);
13-
expect(output.stdout).toContain('client/default/index.js?');
13+
expect(output.stdout).toContain('client/index.js?');
1414
done();
1515
})
1616
.catch(done);
@@ -22,7 +22,7 @@ describe('DevServer', () => {
2222
testBin('--stats=verbose', './test/fixtures/dev-server/multi-entry.js')
2323
.then((output) => {
2424
expect(output.exitCode).toEqual(0);
25-
expect(output.stdout).toContain('client/default/index.js?');
25+
expect(output.stdout).toContain('client/index.js?');
2626
expect(output.stdout).toContain('foo.js');
2727
done();
2828
})
@@ -36,7 +36,7 @@ describe('DevServer', () => {
3636
testBin(null, './test/fixtures/dev-server/empty-entry.js')
3737
.then((output) => {
3838
expect(output.exitCode).toEqual(0);
39-
expect(output.stdout).toContain('client/default/index.js?');
39+
expect(output.stdout).toContain('client/index.js?');
4040
done();
4141
})
4242
.catch(done);
@@ -61,7 +61,7 @@ describe('DevServer', () => {
6161
testBin('--target web', './test/fixtures/dev-server/default-config.js')
6262
.then((output) => {
6363
expect(output.exitCode).toEqual(0);
64-
expect(output.stdout).toContain('client/default/index.js?');
64+
expect(output.stdout).toContain('client/index.js?');
6565
expect(output.stdout).toContain('foo.js');
6666
done();
6767
})
@@ -72,7 +72,7 @@ describe('DevServer', () => {
7272
testBin('--target node', './test/fixtures/dev-server/default-config.js')
7373
.then((output) => {
7474
expect(output.exitCode).toEqual(0);
75-
expect(output.stdout).not.toContain('client/default/index.js?');
75+
expect(output.stdout).not.toContain('client/index.js?');
7676
expect(output.stdout).toContain('foo.js');
7777
done();
7878
})
@@ -118,7 +118,7 @@ describe('DevServer', () => {
118118
testBin(null, './test/fixtures/dev-server/target-config.js')
119119
.then((output) => {
120120
expect(output.exitCode).toEqual(0);
121-
expect(output.stdout).toContain('client/default/index.js');
121+
expect(output.stdout).toContain('client/index.js');
122122
done();
123123
})
124124
.catch(done);

test/server/utils/routes.test.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,6 @@ describe('routes util', () => {
3434
});
3535
});
3636

37-
it('should handle GET request to inline bundle', (done) => {
38-
req.get('/webpack-dev-server.js').then(({ res }) => {
39-
expect(res.headers['content-type']).toEqual('application/javascript');
40-
expect(res.statusCode).toEqual(200);
41-
done();
42-
});
43-
});
44-
45-
it('should handle HEAD request to inline bundle', (done) => {
46-
req.head('/webpack-dev-server.js').then(({ res }) => {
47-
expect(res.headers['content-type']).toEqual('application/javascript');
48-
expect(res.statusCode).toEqual(200);
49-
done();
50-
});
51-
});
52-
5337
it('should handle GET request to invalidate endpoint', (done) => {
5438
req.get('/webpack-dev-server/invalidate').then(({ res }) => {
5539
expect(res.headers['content-type']).not.toEqual('text/html');

0 commit comments

Comments
 (0)