Skip to content

Commit

Permalink
tests(watch): hash assertion for info-verbosity-off
Browse files Browse the repository at this point in the history
  • Loading branch information
hemal7735 authored and evenstensberg committed Feb 5, 2019
1 parent 1d2ccd5 commit e0a0d97
Showing 1 changed file with 63 additions and 11 deletions.
74 changes: 63 additions & 11 deletions test/binCases/watch/info-verbosity-off/info-verbosity-off.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,38 @@ jest.setTimeout(10e6);
/* eslint-disable node/no-unsupported-features */
/* eslint-disable node/no-unsupported-features/es-syntax */

const { runWatch, extractSummary } = require("../../../testUtils");
const { extractSummary, extractHash, appendDataIfFileExists, runAndGetWatchProc } = require("../../../testUtils");
const fs = require("fs");
const path = require("path");

test("info-verbosity-off", async done => {
const result = await runWatch(__dirname, [
const fileToChange = "index.js";
const copyFile = "index_copy.js";
const fileToChangePath = path.resolve(__dirname, fileToChange);
const copyFilePath = path.resolve(__dirname, copyFile);

// create copy of "index.js" => "index_copy.js"
beforeEach(() => {
// fs.copyFileSync was added in Added in: v8.5.0
// We should migrate it once we stop support for v6.x
fs.createReadStream(fileToChangePath).pipe(fs.createWriteStream(copyFilePath));
});

afterEach(() => {
try {
// deleting the file as it is modified by the test
// subsequent test-case runs won't pass as snapshot is not matched
fs.unlinkSync(fileToChangePath);
} catch (e) {
console.warn("could not remove the file:" + fileToChangePath + "\n" + e.message);
} finally {
fs.renameSync(copyFilePath, fileToChangePath);
}
});

// It is modifying the index.js
// Which breaks the test-cases second time
test.only("info-verbosity-off", async done => {
var webpackProc = runAndGetWatchProc(__dirname, [
"--entry ",
"./index.js",
"--config",
Expand All @@ -22,15 +50,39 @@ test("info-verbosity-off", async done => {
"--info-verbosity",
"none"
]);
const { stdout, stderr } = result;

const summary = extractSummary(stdout);
var outputCount = 0;
var hash1;

webpackProc.stdout.on("data", data => {
data = data.toString();

if (outputCount === 0) {
hash1 = extractHash(data);

const summary = extractSummary(data);

expect(summary).toEqual(expect.anything());
expect(summary).toContain("");
expect(summary).not.toContain("webpack is watching the files…");
expect(summary).toMatchSnapshot();

// change file
appendDataIfFileExists(__dirname, fileToChange, "//junk-comment");

outputCount++;
} else {
const hash2 = extractHash(data);

expect(summary).toEqual(expect.anything());
expect(summary).toContain("");
expect(summary).not.toContain("webpack is watching the files…");
expect(hash2.hash).not.toBe(hash1.hash);
webpackProc.kill();
done();
}
});

expect(stderr).toHaveLength(0);
expect(summary).toMatchSnapshot();
done();
webpackProc.stderr.on("data", error => {
// fail test case if there is any error
expect(true).toBe(false);
done();
});
});

0 comments on commit e0a0d97

Please sign in to comment.