Skip to content

Commit c00386b

Browse files
hemal7735evenstensberg
authored andcommitted
tests(watch): use switch pattern for verbosity off
1 parent 0952317 commit c00386b

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

test/binCases/watch/info-verbosity-off/info-verbosity-off.test.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,46 @@ test("info-verbosity-off", async done => {
4848
"none"
4949
]);
5050

51-
var firstTimeOutput = true;
52-
var hash1;
51+
// info-verbosity none spits the output in one go.
52+
// So we only need to keep a track of when we change the files
53+
// 1. Hash and other info
54+
// 2. (file changed) Hash and other info
55+
56+
var chunkNumber = 0;
57+
var hash1, hash2;
58+
var summary;
5359

5460
webpackProc.stdout.on("data", data => {
5561
data = data.toString();
56-
62+
chunkNumber++;
5763
// We get webpack output after running test
5864
// Since we are running the webpack in watch mode, changing file will generate additional output
5965
// First time output will be validated fully
6066
// Hash of the The subsequent output will be tested against that of first time output
61-
if (firstTimeOutput) {
62-
hash1 = extractHash(data);
6367

64-
const summary = extractSummary(data);
68+
switch (chunkNumber) {
69+
case 1:
70+
hash1 = extractHash(data);
71+
summary = extractSummary(data);
72+
73+
expect(summary).not.toContain("webpack is watching the files…");
74+
expect(summary).toMatchSnapshot();
75+
76+
// change file
77+
appendDataIfFileExists(__dirname, fileToChange, "//junk-comment");
6578

66-
expect(summary).toEqual(expect.anything());
67-
expect(summary).toContain("");
68-
expect(summary).not.toContain("webpack is watching the files…");
69-
expect(summary).toMatchSnapshot();
79+
break;
80+
case 2:
81+
hash2 = extractHash(data);
7082

71-
// change file
72-
appendDataIfFileExists(__dirname, fileToChange, "//junk-comment");
83+
expect(hash2.hash).not.toBe(hash1.hash);
7384

74-
firstTimeOutput = false;
75-
} else {
76-
const hash2 = extractHash(data);
85+
webpackProc.kill();
86+
done();
7787

78-
expect(hash2.hash).not.toBe(hash1.hash);
79-
webpackProc.kill();
80-
done();
88+
break;
89+
default:
90+
break;
8191
}
8292
});
8393

0 commit comments

Comments
 (0)