Skip to content

Commit d1a86d7

Browse files
committed
fix(test): replace include.toBeTruthy with toContain
For better test output.
1 parent 75e620a commit d1a86d7

File tree

2 files changed

+33
-49
lines changed

2 files changed

+33
-49
lines changed

test/cli/cli.test.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,25 @@ describe('CLI', () => {
2020
testBin('--progress')
2121
.then((output) => {
2222
expect(output.code).toEqual(0);
23-
expect(output.stderr.includes('0% compiling')).toBe(true);
23+
expect(output.stderr).toContain('0% compiling');
2424
// should not profile
25-
expect(
26-
output.stderr.includes('ms after chunk modules optimization')
27-
).toBe(false);
25+
expect(output.stderr).not.toContain(
26+
'ms after chunk modules optimization'
27+
);
2828
done();
2929
})
3030
.catch(done);
3131
});
3232

3333
it('--quiet', async (done) => {
34-
const output = await testBin(`--quiet --port ${port1}`);
34+
const output = await testBin(`--quiet --colors=false --port ${port1}`);
3535
expect(output.code).toEqual(0);
3636
expect(output.stdout.split('\n').length === 3).toBe(true);
37-
expect(
38-
output.stdout.includes(`Project is running at http://localhost:${port1}/`)
39-
).toBe(true);
40-
expect(output.stdout.includes('webpack output is served from /')).toBe(
41-
true
37+
expect(output.stdout).toContain(
38+
`Project is running at http://localhost:${port1}/`
4239
);
43-
expect(
44-
output.stdout.includes('Content not from webpack is served from')
45-
).toBe(true);
40+
expect(output.stdout).toContain('webpack output is served from /');
41+
expect(output.stdout).toContain('Content not from webpack is served from');
4642
done();
4743
});
4844

@@ -51,9 +47,7 @@ describe('CLI', () => {
5147
.then((output) => {
5248
expect(output.code).toEqual(0);
5349
// should profile
54-
expect(output.stderr.includes('after chunk modules optimization')).toBe(
55-
true
56-
);
50+
expect(output.stderr).toContain('after chunk modules optimization');
5751
done();
5852
})
5953
.catch(done);
@@ -63,7 +57,7 @@ describe('CLI', () => {
6357
testBin('--bonjour')
6458
.then((output) => {
6559
expect(output.code).toEqual(0);
66-
expect(output.stdout.includes('Bonjour')).toBe(true);
60+
expect(output.stdout).toContain('Bonjour');
6761
done();
6862
})
6963
.catch(done);
@@ -73,7 +67,7 @@ describe('CLI', () => {
7367
testBin('--https')
7468
.then((output) => {
7569
expect(output.code).toEqual(0);
76-
expect(output.stdout.includes('Project is running at')).toBe(true);
70+
expect(output.stdout).toContain('Project is running at');
7771
done();
7872
})
7973
.catch(done);
@@ -85,7 +79,7 @@ describe('CLI', () => {
8579
)
8680
.then((output) => {
8781
expect(output.code).toEqual(0);
88-
expect(output.stdout.includes('Project is running at')).toBe(true);
82+
expect(output.stdout).toContain('Project is running at');
8983
done();
9084
})
9185
.catch(done);
@@ -115,9 +109,9 @@ describe('CLI', () => {
115109
testBin('--color')
116110
.then((output) => {
117111
// https://github.com/webpack/webpack-dev-server/blob/master/lib/utils/colors.js
118-
expect(
119-
output.stdout.includes('\u001b[39m \u001b[90m「wds」\u001b[39m:')
120-
).toEqual(true);
112+
expect(output.stdout).toContain(
113+
'\u001b[39m \u001b[90m「wds」\u001b[39m:'
114+
);
121115
done();
122116
})
123117
.catch(done);
@@ -134,7 +128,7 @@ describe('CLI', () => {
134128
if (process.platform === 'win32') {
135129
done();
136130
} else {
137-
expect(output.stdout.includes(socketPath)).toBe(true);
131+
expect(output.stdout).toContain(socketPath);
138132

139133
unlink(socketPath, () => {
140134
done();
@@ -155,7 +149,7 @@ describe('CLI', () => {
155149
})
156150
.catch((err) => {
157151
// for windows
158-
expect(err.stdout.includes('Compiled successfully.')).toEqual(true);
152+
expect(err.stdout).toContain('Compiled successfully.');
159153
done();
160154
});
161155
});

test/e2e/ClientOptions.test.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ describe('Client code', () => {
7272
.then((requestObj) => {
7373
page.waitFor(beforeBrowserCloseDelay).then(() => {
7474
browser.close().then(() => {
75-
expect(
76-
requestObj
77-
.url()
78-
.includes(`http://localhost:${port1}/sockjs-node`)
79-
).toBeTruthy();
75+
expect(requestObj.url()).toContain(
76+
`http://localhost:${port1}/sockjs-node`
77+
);
8078
done();
8179
});
8280
});
@@ -115,11 +113,9 @@ describe('Client complex inline script path', () => {
115113
.then((requestObj) => {
116114
page.waitFor(beforeBrowserCloseDelay).then(() => {
117115
browser.close().then(() => {
118-
expect(
119-
requestObj
120-
.url()
121-
.includes(`http://myhost.test:${port2}/foo/test/bar/`)
122-
).toBeTruthy();
116+
expect(requestObj.url()).toContain(
117+
`http://myhost.test:${port2}/foo/test/bar/`
118+
);
123119
done();
124120
});
125121
});
@@ -158,11 +154,9 @@ describe('Client complex inline script path with sockPort', () => {
158154
.then((requestObj) => {
159155
page.waitFor(beforeBrowserCloseDelay).then(() => {
160156
browser.close().then(() => {
161-
expect(
162-
requestObj
163-
.url()
164-
.includes(`http://localhost:${port3}/foo/test/bar`)
165-
).toBeTruthy();
157+
expect(requestObj.url()).toContain(
158+
`http://localhost:${port3}/foo/test/bar`
159+
);
166160
done();
167161
});
168162
});
@@ -202,11 +196,9 @@ describe('Client complex inline script path with sockPort, no sockPath', () => {
202196
.then((requestObj) => {
203197
page.waitFor(beforeBrowserCloseDelay).then(() => {
204198
browser.close().then(() => {
205-
expect(
206-
requestObj
207-
.url()
208-
.includes(`http://localhost:${port3}/sockjs-node`)
209-
).toBeTruthy();
199+
expect(requestObj.url()).toContain(
200+
`http://localhost:${port3}/sockjs-node`
201+
);
210202
done();
211203
});
212204
});
@@ -242,11 +234,9 @@ describe('Client complex inline script path with sockHost', () => {
242234
.then((requestObj) => {
243235
page.waitFor(beforeBrowserCloseDelay).then(() => {
244236
browser.close().then(() => {
245-
expect(
246-
requestObj
247-
.url()
248-
.includes(`http://myhost.test:${port2}/sockjs-node`)
249-
).toBeTruthy();
237+
expect(requestObj.url()).toContain(
238+
`http://myhost.test:${port2}/sockjs-node`
239+
);
250240
done();
251241
});
252242
});

0 commit comments

Comments
 (0)