Build infra for tracking dev-specific failures (#8228)

I'll plan to change all of our console.error and component-tree expects to expectDev. It's a little annoying that we need to make sure tests don't throw (see my change to normalizeCodeLocInfo) but any alternative would seem to require two separate test runs or a much more cumbersome syntax.
This commit is contained in:
Ben Alpert
2016-11-13 14:00:07 -08:00
committed by GitHub
parent c6f10e2cee
commit 64cba04bf9
7 changed files with 87 additions and 18 deletions
+46 -6
View File
@@ -27,19 +27,51 @@ function wrapRunnerFile(runnerPath) {
filename,
`
'use strict';
var runnerPath = ${JSON.stringify(runnerPath)};
var wrap = require(${JSON.stringify(__filename)}).wrapRunner;
var original = require(${JSON.stringify(runnerPath)});
module.exports = wrap(original);
module.exports = wrap(runnerPath);
`
);
return filename;
}
function wrapRunner(original) {
return function runner(config, environment, runtime, testPath) {
return original(config, environment, runtime, testPath)
function wrapRunner(originalPath) {
const original = require(originalPath);
// Assuming originalPath is .../jest-jasmine2/build/index.js
const JasmineReporter = require(
path.join(path.dirname(originalPath), 'reporter.js')
);
// For each spec, we store whether there was any expectDev() failure. This
// relies on the results being returned in the same order as they are run.
const hadDevFailures = [];
let environment;
const oldSpecStarted = JasmineReporter.prototype.specStarted;
JasmineReporter.prototype.specStarted = function(result) {
oldSpecStarted.apply(this, arguments);
environment.global.__suppressDevFailures = true;
environment.global.__hadDevFailures = false;
};
const oldSpecDone = JasmineReporter.prototype.specDone;
JasmineReporter.prototype.specDone = function(result) {
oldSpecDone.apply(this, arguments);
environment.global.__suppressDevFailures = false;
hadDevFailures.push(environment.global.__hadDevFailures);
};
return function runner(config, env, runtime, testPath) {
environment = env;
return original(config, env, runtime, testPath)
.then((results) => {
results.failureMessage = null;
hadDevFailures.forEach((hadFailures, i) => {
results.testResults[i].hadDevFailures = hadFailures;
});
hadDevFailures.length = 0;
return results;
});
};
@@ -91,7 +123,11 @@ function recordTests(trackFacts) {
.then((runResults) => {
const passing = formatResults(
runResults,
(file, test) => test.status === 'passed'
(file, test) => test.status === 'passed' && !test.hadDevFailures
);
const passingExceptDev = formatResults(
runResults,
(file, test) => test.status === 'passed' && test.hadDevFailures
);
const failing = formatResults(
runResults,
@@ -101,6 +137,10 @@ function recordTests(trackFacts) {
path.join(__dirname, 'tests-passing.txt'),
passing + '\n'
);
fs.writeFileSync(
path.join(__dirname, 'tests-passing-except-dev.txt'),
passingExceptDev + '\n'
);
fs.writeFileSync(
path.join(__dirname, 'tests-failing.txt'),
failing + '\n'
-4
View File
@@ -505,10 +505,6 @@ src/renderers/shared/shared/__tests__/ReactTreeTraversal-test.js
* should leave to the window
* should leave to the window from the shallowest
src/renderers/shared/stack/reconciler/__tests__/ReactChildReconciler-test.js
* warns for duplicated keys
* warns for duplicated keys with component stack info
src/renderers/shared/stack/reconciler/__tests__/ReactComponent-test.js
* should throw on invalid render targets
* should throw when supplying a ref outside of render method
@@ -0,0 +1,3 @@
src/renderers/shared/stack/reconciler/__tests__/ReactChildReconciler-test.js
* warns for duplicated keys
* warns for duplicated keys with component stack info
+23
View File
@@ -58,3 +58,26 @@ env.afterEach(() => {
expect(console.error).toBeReset();
expect(console.error).toNotHaveBeenCalled();
});
function wrapDevMatcher(obj, name) {
const original = obj[name];
obj[name] = function devMatcher() {
try {
original.apply(this, arguments);
} catch (e) {
global.__hadDevFailures = e.stack;
}
};
}
const expectDev = function expectDev(actual) {
const expectation = expect(actual);
if (global.__suppressDevFailures) {
Object.keys(expectation).forEach((name) => {
wrapDevMatcher(expectation, name);
wrapDevMatcher(expectation.not, name);
});
}
return expectation;
};
global.expectDev = expectDev;