Skip to content

Commit fea8d93

Browse files
committed
test(client): improve es5 check
1 parent e4761bf commit fea8d93

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"@commitlint/cli": "^8.3.5",
7676
"@commitlint/config-conventional": "^8.3.4",
7777
"@jest/test-sequencer": "^26.0.1",
78+
"acorn": "^7.3.1",
7879
"babel-jest": "^26.0.1",
7980
"babel-loader": "^8.1.0",
8081
"body-parser": "^1.19.0",

test/client/bundle.test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
const acorn = require('acorn');
4+
const request = require('supertest');
5+
const testServer = require('../helpers/test-server');
6+
const config = require('../fixtures/simple-config/webpack.config');
7+
const port = require('../ports-map').bundle;
8+
const isWebpack5 = require('../helpers/isWebpack5');
9+
10+
describe('bundle', () => {
11+
// the ES5 check test for the bundle will not work on webpack@5,
12+
// because webpack@5 bundle output uses some ES6 syntax
13+
const runBundleTest = isWebpack5 ? describe.skip : describe;
14+
15+
runBundleTest('bundled output', () => {
16+
let server;
17+
let req;
18+
19+
beforeAll((done) => {
20+
server = testServer.start(config, { port }, done);
21+
req = request(server.app);
22+
});
23+
24+
afterAll(testServer.close);
25+
26+
it('should get full user bundle and parse with ES5', async () => {
27+
const { text } = await req
28+
.get('/main.js')
29+
.expect('Content-Type', 'application/javascript; charset=UTF-8')
30+
.expect(200);
31+
32+
expect(() => {
33+
let evalStep = 0;
34+
acorn.parse(text, {
35+
ecmaVersion: 5,
36+
onToken: (token) => {
37+
if (token.type.label === 'name' && token.value === 'eval') {
38+
evalStep += 1;
39+
} else if (token.type.label === '(' && evalStep === 1) {
40+
evalStep += 1;
41+
} else if (token.type.label === 'string' && evalStep === 2) {
42+
const program = token.value;
43+
try {
44+
acorn.parse(program, {
45+
ecmaVersion: 5,
46+
});
47+
} catch (e) {
48+
console.log(program);
49+
}
50+
51+
evalStep = 0;
52+
}
53+
},
54+
});
55+
}).not.toThrow();
56+
});
57+
});
58+
});

test/ports-map.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const portsList = {
4040
'progress-option': 1,
4141
'profile-option': 1,
4242
Iframe: 1,
43+
bundle: 1,
4344
};
4445

4546
let startPort = 8089;

0 commit comments

Comments
 (0)