test(ivy): add ability to find already passing tests (#27449)

PR Close #27449
This commit is contained in:
Misko Hevery
2018-12-03 17:57:07 -08:00
committed by Igor Minar
parent 4b9948c1be
commit f52600e261
35 changed files with 4501 additions and 4410 deletions

View File

@ -8,6 +8,14 @@
import {bazelDefineCompileValue} from './bazel_define_compile_value';
/**
* Set this constant to `true` to run all tests and report which of the tests marked with `fixmeIvy`
* are actually already passing.
*
* This is useful for locating already passing tests. The already passing tests should have their
* `fixmeIvy` removed.
*/
const FIND_PASSING_TESTS = false;
/**
* A function to conditionally include a test or a block of tests only when tests run against Ivy.
@ -33,17 +41,21 @@ export const ivyEnabled = 'aot' === (bazelDefineCompileValue as string);
* when running against Ivy.
*
* ```
* fixmeIvy('some reason') && describe(...);
* fixmeIvy('some reason').describe(...);
* ```
*
* or
*
* ```
* fixmeIvy('some reason') && it(...);
* fixmeIvy('some reason').it(...);
* ```
*/
export function fixmeIvy(reason: string): boolean {
return !ivyEnabled;
export function fixmeIvy(reason: string): JasmineMethods {
if (FIND_PASSING_TESTS) {
return ivyEnabled ? PASSTHROUGH : IGNORE;
} else {
return ivyEnabled ? IGNORE : PASSTHROUGH;
}
}
@ -54,17 +66,17 @@ export function fixmeIvy(reason: string): boolean {
* Any tests disabled using this switch should not be user-facing breaking changes.
*
* ```
* obsoleteInIvy('some reason') && describe(...);
* obsoleteInIvy('some reason').describe(...);
* ```
*
* or
*
* ```
* obsoleteInIvy('some reason') && it(...);
* obsoleteInIvy('some reason').it(...);
* ```
*/
export function obsoleteInIvy(reason: string): boolean {
return !ivyEnabled;
export function obsoleteInIvy(reason: string): JasmineMethods {
return ivyEnabled ? IGNORE : PASSTHROUGH;
}
/**
@ -75,15 +87,87 @@ export function obsoleteInIvy(reason: string): boolean {
* documented as a breaking change.
*
* ```
* modifiedInIvy('some reason') && describe(...);
* modifiedInIvy('some reason').describe(...);
* ```
*
* or
*
* ```
* modifiedInIvy('some reason') && it(...);
* modifiedInIvy('some reason').it(...);
* ```
*/
export function modifiedInIvy(reason: string): boolean {
return !ivyEnabled;
export function modifiedInIvy(reason: string): JasmineMethods {
return ivyEnabled ? IGNORE : PASSTHROUGH;
}
export interface JasmineMethods {
it: typeof it;
fit: typeof fit;
describe: typeof describe;
fdescribe: typeof fdescribe;
fixmeIvy: typeof fixmeIvy;
isEnabled: boolean;
}
const PASSTHROUGH: JasmineMethods = {
it: maybeAppendFindPassingTestsMarker(it),
fit: maybeAppendFindPassingTestsMarker(fit),
describe: maybeAppendFindPassingTestsMarker(describe),
fdescribe: maybeAppendFindPassingTestsMarker(fdescribe),
fixmeIvy: maybeAppendFindPassingTestsMarker(fixmeIvy),
isEnabled: true,
};
const FIND_PASSING_TESTS_MARKER = '__FIND_PASSING_TESTS_MARKER__';
function maybeAppendFindPassingTestsMarker<T extends Function>(fn: T): T {
return FIND_PASSING_TESTS ? function(...args: any[]) {
if (typeof args[0] == 'string') {
args[0] += FIND_PASSING_TESTS_MARKER;
}
return fn.apply(this, args);
} : fn as any;
}
function noop() {}
const IGNORE: JasmineMethods = {
it: noop,
fit: noop,
describe: noop,
fdescribe: noop,
fixmeIvy: (reason) => IGNORE,
isEnabled: false,
};
if (FIND_PASSING_TESTS) {
const env = jasmine.getEnv();
const passingTests: jasmine.CustomReporterResult[] = [];
const stillFailing: jasmine.CustomReporterResult[] = [];
let specCount = 0;
env.clearReporters();
env.addReporter({
specDone: function(result: jasmine.CustomReporterResult) {
specCount++;
if (result.fullName.indexOf(FIND_PASSING_TESTS_MARKER) != -1) {
(result.status == 'passed' ? passingTests : stillFailing).push(result);
}
},
jasmineDone: function(details: jasmine.RunDetails) {
if (passingTests.length) {
passingTests.forEach((result) => {
// tslint:disable-next-line:no-console
console.log('ALREADY PASSING', result.fullName.replace(FIND_PASSING_TESTS_MARKER, ''));
});
// tslint:disable-next-line:no-console
console.log(
`${specCount} specs,`, //
`${passingTests.length} passing specs,`, //
`${stillFailing.length} still failing specs`);
} else {
// tslint:disable-next-line:no-console
console.log('NO PASSING TESTS FOUND.');
}
}
});
}