Skip to content

Commit

Permalink
Merge pull request #7168 from webpack/test/jest-improvements
Browse files Browse the repository at this point in the history
Test/jest improvements
  • Loading branch information
sokra committed May 1, 2018
2 parents afd889a + 91bcdfb commit 7543c45
Show file tree
Hide file tree
Showing 79 changed files with 2,674 additions and 2,460 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"type-lint": "tsc --pretty",
"fix": "yarn code-lint --fix",
"pretty": "prettier \"setup/**/*.js\" \"lib/**/*.js\" \"bin/*.js\" \"hot/*.js\" \"buildin/*.js\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\" \"declarations.d.ts\" --write",
"schema-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.lint.js\"",
"schema-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.lint.js\" --no-verbose",
"benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.benchmark.js\" --runInBand",
"cover": "yarn cover:init && yarn cover:all && yarn cover:report",
"cover:init": "rimraf coverage",
Expand Down
14 changes: 1 addition & 13 deletions test/StatsTestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,7 @@ describe("StatsTestCases", () => {
.replace(/[\t ]*Version:.+\n/g, "")
.replace(path.join(base, testName), "Xdir/" + testName)
.replace(/ dependencies:Xms/g, "");
const expected = fs
.readFileSync(path.join(base, testName, "expected.txt"), "utf-8")
.replace(/\r/g, "");
if (actual !== expected) {
fs.writeFileSync(
path.join(base, testName, "actual.txt"),
actual,
"utf-8"
);
} else if (fs.existsSync(path.join(base, testName, "actual.txt"))) {
fs.unlinkSync(path.join(base, testName, "actual.txt"));
}
expect(actual).toBe(expected);
expect(actual).toMatchSnapshot();
done();
});
});
Expand Down
76 changes: 42 additions & 34 deletions test/WatchTestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require("path");
const fs = require("fs");
const vm = require("vm");
const mkdirp = require("mkdirp");
const rimraf = require("rimraf");
const checkArrayExpectation = require("./checkArrayExpectation");
const { remove } = require("./helpers/remove");

Expand Down Expand Up @@ -76,9 +77,7 @@ describe("WatchTestCases", () => {
"js",
"watch-src",
category.name,
`${testName}-${Math.random()
.toPrecision(21)
.slice(2)}`
testName
);
const testDirectory = path.join(casesPath, category.name, testName);
const runs = fs
Expand All @@ -89,7 +88,9 @@ describe("WatchTestCases", () => {
})
.map(name => ({ name }));

let exportedTests = [];
beforeAll(done => {
rimraf(tempDirectory, done);
});

it(
testName + " should compile",
Expand Down Expand Up @@ -201,6 +202,8 @@ describe("WatchTestCases", () => {
)
return;

const exportedTests = [];

function _it(title, fn) {
exportedTests.push({ title, fn, timeout: 45000 });
}
Expand Down Expand Up @@ -293,38 +296,43 @@ describe("WatchTestCases", () => {
if (exportedTests.length < 1)
return done(new Error("No tests exported by test case"));

runIdx++;
if (runIdx < runs.length) {
run = runs[runIdx];
waitMode = true;
setTimeout(() => {
waitMode = false;
currentWatchStepModule.step = run.name;
copyDiff(
path.join(testDirectory, run.name),
tempDirectory,
false
);
}, 1500);
} else {
watching.close();
const continueStep = () => {
runIdx++;
if (runIdx < runs.length) {
run = runs[runIdx];
waitMode = true;
setTimeout(() => {
waitMode = false;
currentWatchStepModule.step = run.name;
copyDiff(
path.join(testDirectory, run.name),
tempDirectory,
false
);
}, 1500);
} else {
watching.close();

const asyncSuite = describe("exported tests", () => {
exportedTests.forEach(
({ title, fn, timeout }) =>
fn
? fit(title, fn, timeout)
: fit(title, () => {}).pend("Skipped")
);
});
// workaround for jest running clearSpies on the wrong suite (invoked by clearResourcesForRunnable)
asyncSuite.disabled = true;
done();
}
};

jasmine
.getEnv()
.execute([asyncSuite.id], asyncSuite)
.then(done, done);
}
// Run the tests
const asyncSuite = describe(`step ${run.name}`, () => {
exportedTests.forEach(
({ title, fn, timeout }) =>
fn
? fit(title, fn, timeout)
: fit(title, () => {}).pend("Skipped")
);
});
// workaround for jest running clearSpies on the wrong suite (invoked by clearResourcesForRunnable)
asyncSuite.disabled = true;

jasmine
.getEnv()
.execute([asyncSuite.id], asyncSuite)
.then(continueStep, done);
}
);
}, 300);
Expand Down

0 comments on commit 7543c45

Please sign in to comment.