Runner: naming improvements, use private members
This commit is contained in:
@@ -1245,7 +1245,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
globalErrors
|
globalErrors
|
||||||
});
|
});
|
||||||
|
|
||||||
let reporter;
|
let reportDispatcher;
|
||||||
let topSuite;
|
let topSuite;
|
||||||
let runner;
|
let runner;
|
||||||
let parallelLoadingState = null; // 'specs', 'helpers', or null for non-parallel
|
let parallelLoadingState = null; // 'specs', 'helpers', or null for non-parallel
|
||||||
@@ -1698,7 +1698,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @interface Reporter
|
* @interface Reporter
|
||||||
* @see custom_reporter
|
* @see custom_reporter
|
||||||
*/
|
*/
|
||||||
reporter = new j$.ReportDispatcher(
|
reportDispatcher = new j$.ReportDispatcher(
|
||||||
j$.reporterEvents,
|
j$.reporterEvents,
|
||||||
function(options) {
|
function(options) {
|
||||||
options.SkipPolicy = j$.NeverSkipPolicy;
|
options.SkipPolicy = j$.NeverSkipPolicy;
|
||||||
@@ -1712,7 +1712,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
totalSpecsDefined: () => suiteBuilder.totalSpecsDefined,
|
totalSpecsDefined: () => suiteBuilder.totalSpecsDefined,
|
||||||
focusedRunables: () => suiteBuilder.focusedRunables,
|
focusedRunables: () => suiteBuilder.focusedRunables,
|
||||||
runableResources,
|
runableResources,
|
||||||
reporter,
|
reporter: reportDispatcher,
|
||||||
runQueue,
|
runQueue,
|
||||||
TreeProcessor: j$.TreeProcessor,
|
TreeProcessor: j$.TreeProcessor,
|
||||||
globalErrors,
|
globalErrors,
|
||||||
@@ -1780,7 +1780,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
throw new Error('Reporters cannot be added via Env in parallel mode');
|
throw new Error('Reporters cannot be added via Env in parallel mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
reporter.addReporter(reporterToAdd);
|
reportDispatcher.addReporter(reporterToAdd);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1792,7 +1792,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @see custom_reporter
|
* @see custom_reporter
|
||||||
*/
|
*/
|
||||||
this.provideFallbackReporter = function(reporterToAdd) {
|
this.provideFallbackReporter = function(reporterToAdd) {
|
||||||
reporter.provideFallbackReporter(reporterToAdd);
|
reportDispatcher.provideFallbackReporter(reporterToAdd);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1806,7 +1806,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
throw new Error('Reporters cannot be removed via Env in parallel mode');
|
throw new Error('Reporters cannot be removed via Env in parallel mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
reporter.clearReporters();
|
reportDispatcher.clearReporters();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1973,12 +1973,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
function specStarted(spec, suite, next) {
|
function specStarted(spec, suite, next) {
|
||||||
runner.currentSpec = spec;
|
runner.currentSpec = spec;
|
||||||
runableResources.initForRunable(spec.id, suite.id);
|
runableResources.initForRunable(spec.id, suite.id);
|
||||||
reporter.specStarted(spec.result).then(next);
|
reportDispatcher.specStarted(spec.result).then(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reportSpecDone(spec, result, next) {
|
function reportSpecDone(spec, result, next) {
|
||||||
spec.reportedDone = true;
|
spec.reportedDone = true;
|
||||||
reporter.specDone(result).then(next);
|
reportDispatcher.specDone(result).then(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.it = function(description, fn, timeout) {
|
this.it = function(description, fn, timeout) {
|
||||||
@@ -9401,20 +9401,31 @@ getJasmineRequireObj().RunableResources = function(j$) {
|
|||||||
|
|
||||||
getJasmineRequireObj().Runner = function(j$) {
|
getJasmineRequireObj().Runner = function(j$) {
|
||||||
class Runner {
|
class Runner {
|
||||||
|
#topSuite;
|
||||||
|
#getTotalSpecsDefined;
|
||||||
|
#getFocusedRunables;
|
||||||
|
#runableResources;
|
||||||
|
#runQueue;
|
||||||
|
#TreeProcessor;
|
||||||
|
#globalErrors;
|
||||||
|
#reportDispatcher;
|
||||||
|
#getConfig;
|
||||||
|
#reportSpecDone;
|
||||||
|
#executedBefore;
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.topSuite_ = options.topSuite;
|
this.#topSuite = options.topSuite;
|
||||||
// TODO use names that read like getters
|
this.#getTotalSpecsDefined = options.totalSpecsDefined;
|
||||||
this.totalSpecsDefined_ = options.totalSpecsDefined;
|
this.#getFocusedRunables = options.focusedRunables;
|
||||||
this.focusedRunables_ = options.focusedRunables;
|
this.#runableResources = options.runableResources;
|
||||||
this.runableResources_ = options.runableResources;
|
this.#runQueue = options.runQueue;
|
||||||
this.runQueue_ = options.runQueue;
|
this.#TreeProcessor = options.TreeProcessor;
|
||||||
this.TreeProcessor_ = options.TreeProcessor;
|
this.#globalErrors = options.globalErrors;
|
||||||
this.globalErrors_ = options.globalErrors;
|
this.#reportDispatcher = options.reporter;
|
||||||
this.reporter_ = options.reporter;
|
this.#getConfig = options.getConfig;
|
||||||
this.getConfig_ = options.getConfig;
|
this.#reportSpecDone = options.reportSpecDone;
|
||||||
this.reportSpecDone_ = options.reportSpecDone;
|
|
||||||
this.hasFailures = false;
|
this.hasFailures = false;
|
||||||
this.executedBefore_ = false;
|
this.#executedBefore = false;
|
||||||
|
|
||||||
this.currentlyExecutingSuites_ = [];
|
this.currentlyExecutingSuites_ = [];
|
||||||
this.currentSpec = null;
|
this.currentSpec = null;
|
||||||
@@ -9431,24 +9442,24 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parallelReset() {
|
parallelReset() {
|
||||||
this.executedBefore_ = false;
|
this.#executedBefore = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(runablesToRun) {
|
async execute(runablesToRun) {
|
||||||
if (this.executedBefore_) {
|
if (this.#executedBefore) {
|
||||||
this.topSuite_.reset();
|
this.#topSuite.reset();
|
||||||
}
|
}
|
||||||
this.executedBefore_ = true;
|
this.#executedBefore = true;
|
||||||
|
|
||||||
this.hasFailures = false;
|
this.hasFailures = false;
|
||||||
const focusedRunables = this.focusedRunables_();
|
const focusedRunables = this.#getFocusedRunables();
|
||||||
const config = this.getConfig_();
|
const config = this.#getConfig();
|
||||||
|
|
||||||
if (!runablesToRun) {
|
if (!runablesToRun) {
|
||||||
if (focusedRunables.length) {
|
if (focusedRunables.length) {
|
||||||
runablesToRun = focusedRunables;
|
runablesToRun = focusedRunables;
|
||||||
} else {
|
} else {
|
||||||
runablesToRun = [this.topSuite_.id];
|
runablesToRun = [this.#topSuite.id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9457,8 +9468,8 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
seed: j$.isNumber_(config.seed) ? config.seed + '' : config.seed
|
seed: j$.isNumber_(config.seed) ? config.seed + '' : config.seed
|
||||||
});
|
});
|
||||||
|
|
||||||
const processor = new this.TreeProcessor_({
|
const processor = new this.#TreeProcessor({
|
||||||
tree: this.topSuite_,
|
tree: this.#topSuite,
|
||||||
runnableIds: runablesToRun,
|
runnableIds: runablesToRun,
|
||||||
runQueue: options => {
|
runQueue: options => {
|
||||||
if (options.isLeaf) {
|
if (options.isLeaf) {
|
||||||
@@ -9473,15 +9484,15 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.runQueue_(options);
|
return this.#runQueue(options);
|
||||||
},
|
},
|
||||||
globalErrors: this.globalErrors_,
|
globalErrors: this.#globalErrors,
|
||||||
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
|
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
|
||||||
detectLateRejectionHandling: config.detectLateRejectionHandling,
|
detectLateRejectionHandling: config.detectLateRejectionHandling,
|
||||||
nodeStart: (suite, next) => {
|
nodeStart: (suite, next) => {
|
||||||
this.currentlyExecutingSuites_.push(suite);
|
this.currentlyExecutingSuites_.push(suite);
|
||||||
this.runableResources_.initForRunable(suite.id, suite.parentSuite.id);
|
this.#runableResources.initForRunable(suite.id, suite.parentSuite.id);
|
||||||
this.reporter_.suiteStarted(suite.result).then(next);
|
this.#reportDispatcher.suiteStarted(suite.result).then(next);
|
||||||
suite.startTimer();
|
suite.startTimer();
|
||||||
},
|
},
|
||||||
nodeComplete: (suite, result, next) => {
|
nodeComplete: (suite, result, next) => {
|
||||||
@@ -9489,7 +9500,7 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
throw new Error('Tried to complete the wrong suite');
|
throw new Error('Tried to complete the wrong suite');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.runableResources_.clearForRunable(suite.id);
|
this.#runableResources.clearForRunable(suite.id);
|
||||||
this.currentlyExecutingSuites_.pop();
|
this.currentlyExecutingSuites_.pop();
|
||||||
|
|
||||||
if (result.status === 'failed') {
|
if (result.status === 'failed') {
|
||||||
@@ -9498,11 +9509,11 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
suite.endTimer();
|
suite.endTimer();
|
||||||
|
|
||||||
if (suite.hadBeforeAllFailure) {
|
if (suite.hadBeforeAllFailure) {
|
||||||
this.reportChildrenOfBeforeAllFailure_(suite).then(() => {
|
this.#reportChildrenOfBeforeAllFailure(suite).then(() => {
|
||||||
this.reportSuiteDone_(suite, result, next);
|
this.#reportSuiteDone(suite, result, next);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.reportSuiteDone_(suite, result, next);
|
this.#reportSuiteDone(suite, result, next);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
orderChildren: function(node) {
|
orderChildren: function(node) {
|
||||||
@@ -9519,13 +9530,13 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.execute2_(runablesToRun, order, processor);
|
return this.#execute2(runablesToRun, order, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute2_(runablesToRun, order, processor) {
|
async #execute2(runablesToRun, order, processor) {
|
||||||
const totalSpecsDefined = this.totalSpecsDefined_();
|
const totalSpecsDefined = this.#getTotalSpecsDefined();
|
||||||
|
|
||||||
this.runableResources_.initForRunable(this.topSuite_.id);
|
this.#runableResources.initForRunable(this.#topSuite.id);
|
||||||
const jasmineTimer = new j$.Timer();
|
const jasmineTimer = new j$.Timer();
|
||||||
jasmineTimer.start();
|
jasmineTimer.start();
|
||||||
|
|
||||||
@@ -9537,7 +9548,7 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
* @property {Boolean} parallel - Whether Jasmine is being run in parallel mode.
|
* @property {Boolean} parallel - Whether Jasmine is being run in parallel mode.
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
await this.reporter_.jasmineStarted({
|
await this.#reportDispatcher.jasmineStarted({
|
||||||
// In parallel mode, the jasmineStarted event is separately dispatched
|
// In parallel mode, the jasmineStarted event is separately dispatched
|
||||||
// by jasmine-npm. This event only reaches reporters in non-parallel.
|
// by jasmine-npm. This event only reaches reporters in non-parallel.
|
||||||
totalSpecsDefined,
|
totalSpecsDefined,
|
||||||
@@ -9545,23 +9556,23 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
parallel: false
|
parallel: false
|
||||||
});
|
});
|
||||||
|
|
||||||
this.currentlyExecutingSuites_.push(this.topSuite_);
|
this.currentlyExecutingSuites_.push(this.#topSuite);
|
||||||
await processor.execute();
|
await processor.execute();
|
||||||
|
|
||||||
if (this.topSuite_.hadBeforeAllFailure) {
|
if (this.#topSuite.hadBeforeAllFailure) {
|
||||||
await this.reportChildrenOfBeforeAllFailure_(this.topSuite_);
|
await this.#reportChildrenOfBeforeAllFailure(this.#topSuite);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.runableResources_.clearForRunable(this.topSuite_.id);
|
this.#runableResources.clearForRunable(this.#topSuite.id);
|
||||||
this.currentlyExecutingSuites_.pop();
|
this.currentlyExecutingSuites_.pop();
|
||||||
let overallStatus, incompleteReason, incompleteCode;
|
let overallStatus, incompleteReason, incompleteCode;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.hasFailures ||
|
this.hasFailures ||
|
||||||
this.topSuite_.result.failedExpectations.length > 0
|
this.#topSuite.result.failedExpectations.length > 0
|
||||||
) {
|
) {
|
||||||
overallStatus = 'failed';
|
overallStatus = 'failed';
|
||||||
} else if (this.focusedRunables_().length > 0) {
|
} else if (this.#getFocusedRunables().length > 0) {
|
||||||
overallStatus = 'incomplete';
|
overallStatus = 'incomplete';
|
||||||
incompleteReason = 'fit() or fdescribe() was found';
|
incompleteReason = 'fit() or fdescribe() was found';
|
||||||
incompleteCode = 'focused';
|
incompleteCode = 'focused';
|
||||||
@@ -9592,33 +9603,33 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
incompleteReason: incompleteReason,
|
incompleteReason: incompleteReason,
|
||||||
incompleteCode: incompleteCode,
|
incompleteCode: incompleteCode,
|
||||||
order: order,
|
order: order,
|
||||||
failedExpectations: this.topSuite_.result.failedExpectations,
|
failedExpectations: this.#topSuite.result.failedExpectations,
|
||||||
deprecationWarnings: this.topSuite_.result.deprecationWarnings
|
deprecationWarnings: this.#topSuite.result.deprecationWarnings
|
||||||
};
|
};
|
||||||
this.topSuite_.reportedDone = true;
|
this.#topSuite.reportedDone = true;
|
||||||
await this.reporter_.jasmineDone(jasmineDoneInfo);
|
await this.#reportDispatcher.jasmineDone(jasmineDoneInfo);
|
||||||
return jasmineDoneInfo;
|
return jasmineDoneInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
reportSuiteDone_(suite, result, next) {
|
#reportSuiteDone(suite, result, next) {
|
||||||
suite.reportedDone = true;
|
suite.reportedDone = true;
|
||||||
this.reporter_.suiteDone(result).then(next);
|
this.#reportDispatcher.suiteDone(result).then(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
async reportChildrenOfBeforeAllFailure_(suite) {
|
async #reportChildrenOfBeforeAllFailure(suite) {
|
||||||
for (const child of suite.children) {
|
for (const child of suite.children) {
|
||||||
if (child instanceof j$.Suite) {
|
if (child instanceof j$.Suite) {
|
||||||
await this.reporter_.suiteStarted(child.result);
|
await this.#reportDispatcher.suiteStarted(child.result);
|
||||||
await this.reportChildrenOfBeforeAllFailure_(child);
|
await this.#reportChildrenOfBeforeAllFailure(child);
|
||||||
|
|
||||||
// Marking the suite passed is consistent with how suites that
|
// Marking the suite passed is consistent with how suites that
|
||||||
// contain failed specs but no suite-level failures are reported.
|
// contain failed specs but no suite-level failures are reported.
|
||||||
child.result.status = 'passed';
|
child.result.status = 'passed';
|
||||||
|
|
||||||
await this.reporter_.suiteDone(child.result);
|
await this.#reportDispatcher.suiteDone(child.result);
|
||||||
} else {
|
} else {
|
||||||
/* a spec */
|
/* a spec */
|
||||||
await this.reporter_.specStarted(child.result);
|
await this.#reportDispatcher.specStarted(child.result);
|
||||||
|
|
||||||
child.addExpectationResult(
|
child.addExpectationResult(
|
||||||
false,
|
false,
|
||||||
@@ -9634,7 +9645,7 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
child.result.status = 'failed';
|
child.result.status = 'failed';
|
||||||
|
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
this.reportSpecDone_(child, child.result, resolve);
|
this.#reportSpecDone(child, child.result, resolve);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,11 +129,11 @@ describe('Runner', function() {
|
|||||||
describe('reporting', function() {
|
describe('reporting', function() {
|
||||||
it('reports the suiteDone event', async function() {
|
it('reports the suiteDone event', async function() {
|
||||||
const TreeProcessor = spyTreeProcessorCtor();
|
const TreeProcessor = spyTreeProcessorCtor();
|
||||||
const reporter = spyReporter();
|
const reportDispatcher = spyReporter();
|
||||||
const subject = new jasmineUnderTest.Runner({
|
const subject = new jasmineUnderTest.Runner({
|
||||||
...defaultCtorOptions(),
|
...defaultCtorOptions(),
|
||||||
TreeProcessor,
|
TreeProcessor,
|
||||||
reporter
|
reportDispatcher
|
||||||
});
|
});
|
||||||
|
|
||||||
const promise = subject.execute();
|
const promise = subject.execute();
|
||||||
@@ -152,13 +152,13 @@ describe('Runner', function() {
|
|||||||
{ status: 'passed' }
|
{ status: 'passed' }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(reporter.suiteDone).toHaveBeenCalled();
|
expect(reportDispatcher.suiteDone).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the suite had a beforeAll failure', function() {
|
describe('when the suite had a beforeAll failure', function() {
|
||||||
it('reports children before the suiteDone event', async function() {
|
it('reports children before the suiteDone event', async function() {
|
||||||
const TreeProcessor = spyTreeProcessorCtor();
|
const TreeProcessor = spyTreeProcessorCtor();
|
||||||
const reporter = spyReporter();
|
const reportDispatcher = spyReporter();
|
||||||
const reportSpecDone = jasmine
|
const reportSpecDone = jasmine
|
||||||
.createSpy('reportSpecDone')
|
.createSpy('reportSpecDone')
|
||||||
.and.callFake(function(child, result, next) {
|
.and.callFake(function(child, result, next) {
|
||||||
@@ -167,7 +167,7 @@ describe('Runner', function() {
|
|||||||
const subject = new jasmineUnderTest.Runner({
|
const subject = new jasmineUnderTest.Runner({
|
||||||
...defaultCtorOptions(),
|
...defaultCtorOptions(),
|
||||||
TreeProcessor,
|
TreeProcessor,
|
||||||
reporter,
|
reportDispatcher,
|
||||||
reportSpecDone
|
reportSpecDone
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -209,8 +209,12 @@ describe('Runner', function() {
|
|||||||
expect(
|
expect(
|
||||||
suiteToRun.children[0].addExpectationResult
|
suiteToRun.children[0].addExpectationResult
|
||||||
).toHaveBeenCalledBefore(reportSpecDone);
|
).toHaveBeenCalledBefore(reportSpecDone);
|
||||||
expect(reportSpecDone).toHaveBeenCalledBefore(reporter.suiteDone);
|
expect(reportSpecDone).toHaveBeenCalledBefore(
|
||||||
expect(reporter.specStarted).toHaveBeenCalledBefore(reportSpecDone);
|
reportDispatcher.suiteDone
|
||||||
|
);
|
||||||
|
expect(reportDispatcher.specStarted).toHaveBeenCalledBefore(
|
||||||
|
reportSpecDone
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -238,7 +242,7 @@ describe('Runner', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function spyReporter() {
|
function spyReporter() {
|
||||||
return jasmine.createSpyObj('reporter', {
|
return jasmine.createSpyObj('reportDispatcher', {
|
||||||
jasmineStarted: Promise.resolve(),
|
jasmineStarted: Promise.resolve(),
|
||||||
jasmineDone: Promise.resolve(),
|
jasmineDone: Promise.resolve(),
|
||||||
suiteStarted: Promise.resolve(),
|
suiteStarted: Promise.resolve(),
|
||||||
@@ -255,7 +259,7 @@ describe('Runner', function() {
|
|||||||
initForRunable: () => {},
|
initForRunable: () => {},
|
||||||
clearForRunable: () => {}
|
clearForRunable: () => {}
|
||||||
},
|
},
|
||||||
reporter: spyReporter(),
|
reportDispatcher: spyReporter(),
|
||||||
focusedRunables: () => [],
|
focusedRunables: () => [],
|
||||||
getConfig: () => ({}),
|
getConfig: () => ({}),
|
||||||
totalSpecsDefined: () => 1
|
totalSpecsDefined: () => 1
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
globalErrors
|
globalErrors
|
||||||
});
|
});
|
||||||
|
|
||||||
let reporter;
|
let reportDispatcher;
|
||||||
let topSuite;
|
let topSuite;
|
||||||
let runner;
|
let runner;
|
||||||
let parallelLoadingState = null; // 'specs', 'helpers', or null for non-parallel
|
let parallelLoadingState = null; // 'specs', 'helpers', or null for non-parallel
|
||||||
@@ -502,7 +502,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @interface Reporter
|
* @interface Reporter
|
||||||
* @see custom_reporter
|
* @see custom_reporter
|
||||||
*/
|
*/
|
||||||
reporter = new j$.ReportDispatcher(
|
reportDispatcher = new j$.ReportDispatcher(
|
||||||
j$.reporterEvents,
|
j$.reporterEvents,
|
||||||
function(options) {
|
function(options) {
|
||||||
options.SkipPolicy = j$.NeverSkipPolicy;
|
options.SkipPolicy = j$.NeverSkipPolicy;
|
||||||
@@ -516,7 +516,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
totalSpecsDefined: () => suiteBuilder.totalSpecsDefined,
|
totalSpecsDefined: () => suiteBuilder.totalSpecsDefined,
|
||||||
focusedRunables: () => suiteBuilder.focusedRunables,
|
focusedRunables: () => suiteBuilder.focusedRunables,
|
||||||
runableResources,
|
runableResources,
|
||||||
reporter,
|
reportDispatcher,
|
||||||
runQueue,
|
runQueue,
|
||||||
TreeProcessor: j$.TreeProcessor,
|
TreeProcessor: j$.TreeProcessor,
|
||||||
globalErrors,
|
globalErrors,
|
||||||
@@ -584,7 +584,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
throw new Error('Reporters cannot be added via Env in parallel mode');
|
throw new Error('Reporters cannot be added via Env in parallel mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
reporter.addReporter(reporterToAdd);
|
reportDispatcher.addReporter(reporterToAdd);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -596,7 +596,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @see custom_reporter
|
* @see custom_reporter
|
||||||
*/
|
*/
|
||||||
this.provideFallbackReporter = function(reporterToAdd) {
|
this.provideFallbackReporter = function(reporterToAdd) {
|
||||||
reporter.provideFallbackReporter(reporterToAdd);
|
reportDispatcher.provideFallbackReporter(reporterToAdd);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -610,7 +610,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
throw new Error('Reporters cannot be removed via Env in parallel mode');
|
throw new Error('Reporters cannot be removed via Env in parallel mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
reporter.clearReporters();
|
reportDispatcher.clearReporters();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -777,12 +777,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
function specStarted(spec, suite, next) {
|
function specStarted(spec, suite, next) {
|
||||||
runner.currentSpec = spec;
|
runner.currentSpec = spec;
|
||||||
runableResources.initForRunable(spec.id, suite.id);
|
runableResources.initForRunable(spec.id, suite.id);
|
||||||
reporter.specStarted(spec.result).then(next);
|
reportDispatcher.specStarted(spec.result).then(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reportSpecDone(spec, result, next) {
|
function reportSpecDone(spec, result, next) {
|
||||||
spec.reportedDone = true;
|
spec.reportedDone = true;
|
||||||
reporter.specDone(result).then(next);
|
reportDispatcher.specDone(result).then(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.it = function(description, fn, timeout) {
|
this.it = function(description, fn, timeout) {
|
||||||
|
|||||||
@@ -1,19 +1,30 @@
|
|||||||
getJasmineRequireObj().Runner = function(j$) {
|
getJasmineRequireObj().Runner = function(j$) {
|
||||||
class Runner {
|
class Runner {
|
||||||
|
#topSuite;
|
||||||
|
#getTotalSpecsDefined;
|
||||||
|
#getFocusedRunables;
|
||||||
|
#runableResources;
|
||||||
|
#runQueue;
|
||||||
|
#TreeProcessor;
|
||||||
|
#globalErrors;
|
||||||
|
#reportDispatcher;
|
||||||
|
#getConfig;
|
||||||
|
#reportSpecDone;
|
||||||
|
#executedBefore;
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.topSuite_ = options.topSuite;
|
this.#topSuite = options.topSuite;
|
||||||
// TODO use names that read like getters
|
this.#getTotalSpecsDefined = options.totalSpecsDefined;
|
||||||
this.totalSpecsDefined_ = options.totalSpecsDefined;
|
this.#getFocusedRunables = options.focusedRunables;
|
||||||
this.focusedRunables_ = options.focusedRunables;
|
this.#runableResources = options.runableResources;
|
||||||
this.runableResources_ = options.runableResources;
|
this.#runQueue = options.runQueue;
|
||||||
this.runQueue_ = options.runQueue;
|
this.#TreeProcessor = options.TreeProcessor;
|
||||||
this.TreeProcessor_ = options.TreeProcessor;
|
this.#globalErrors = options.globalErrors;
|
||||||
this.globalErrors_ = options.globalErrors;
|
this.#reportDispatcher = options.reportDispatcher;
|
||||||
this.reporter_ = options.reporter;
|
this.#getConfig = options.getConfig;
|
||||||
this.getConfig_ = options.getConfig;
|
this.#reportSpecDone = options.reportSpecDone;
|
||||||
this.reportSpecDone_ = options.reportSpecDone;
|
|
||||||
this.hasFailures = false;
|
this.hasFailures = false;
|
||||||
this.executedBefore_ = false;
|
this.#executedBefore = false;
|
||||||
|
|
||||||
this.currentlyExecutingSuites_ = [];
|
this.currentlyExecutingSuites_ = [];
|
||||||
this.currentSpec = null;
|
this.currentSpec = null;
|
||||||
@@ -30,24 +41,24 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parallelReset() {
|
parallelReset() {
|
||||||
this.executedBefore_ = false;
|
this.#executedBefore = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(runablesToRun) {
|
async execute(runablesToRun) {
|
||||||
if (this.executedBefore_) {
|
if (this.#executedBefore) {
|
||||||
this.topSuite_.reset();
|
this.#topSuite.reset();
|
||||||
}
|
}
|
||||||
this.executedBefore_ = true;
|
this.#executedBefore = true;
|
||||||
|
|
||||||
this.hasFailures = false;
|
this.hasFailures = false;
|
||||||
const focusedRunables = this.focusedRunables_();
|
const focusedRunables = this.#getFocusedRunables();
|
||||||
const config = this.getConfig_();
|
const config = this.#getConfig();
|
||||||
|
|
||||||
if (!runablesToRun) {
|
if (!runablesToRun) {
|
||||||
if (focusedRunables.length) {
|
if (focusedRunables.length) {
|
||||||
runablesToRun = focusedRunables;
|
runablesToRun = focusedRunables;
|
||||||
} else {
|
} else {
|
||||||
runablesToRun = [this.topSuite_.id];
|
runablesToRun = [this.#topSuite.id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,8 +67,8 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
seed: j$.isNumber_(config.seed) ? config.seed + '' : config.seed
|
seed: j$.isNumber_(config.seed) ? config.seed + '' : config.seed
|
||||||
});
|
});
|
||||||
|
|
||||||
const processor = new this.TreeProcessor_({
|
const processor = new this.#TreeProcessor({
|
||||||
tree: this.topSuite_,
|
tree: this.#topSuite,
|
||||||
runnableIds: runablesToRun,
|
runnableIds: runablesToRun,
|
||||||
runQueue: options => {
|
runQueue: options => {
|
||||||
if (options.isLeaf) {
|
if (options.isLeaf) {
|
||||||
@@ -72,15 +83,15 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.runQueue_(options);
|
return this.#runQueue(options);
|
||||||
},
|
},
|
||||||
globalErrors: this.globalErrors_,
|
globalErrors: this.#globalErrors,
|
||||||
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
|
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
|
||||||
detectLateRejectionHandling: config.detectLateRejectionHandling,
|
detectLateRejectionHandling: config.detectLateRejectionHandling,
|
||||||
nodeStart: (suite, next) => {
|
nodeStart: (suite, next) => {
|
||||||
this.currentlyExecutingSuites_.push(suite);
|
this.currentlyExecutingSuites_.push(suite);
|
||||||
this.runableResources_.initForRunable(suite.id, suite.parentSuite.id);
|
this.#runableResources.initForRunable(suite.id, suite.parentSuite.id);
|
||||||
this.reporter_.suiteStarted(suite.result).then(next);
|
this.#reportDispatcher.suiteStarted(suite.result).then(next);
|
||||||
suite.startTimer();
|
suite.startTimer();
|
||||||
},
|
},
|
||||||
nodeComplete: (suite, result, next) => {
|
nodeComplete: (suite, result, next) => {
|
||||||
@@ -88,7 +99,7 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
throw new Error('Tried to complete the wrong suite');
|
throw new Error('Tried to complete the wrong suite');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.runableResources_.clearForRunable(suite.id);
|
this.#runableResources.clearForRunable(suite.id);
|
||||||
this.currentlyExecutingSuites_.pop();
|
this.currentlyExecutingSuites_.pop();
|
||||||
|
|
||||||
if (result.status === 'failed') {
|
if (result.status === 'failed') {
|
||||||
@@ -97,11 +108,11 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
suite.endTimer();
|
suite.endTimer();
|
||||||
|
|
||||||
if (suite.hadBeforeAllFailure) {
|
if (suite.hadBeforeAllFailure) {
|
||||||
this.reportChildrenOfBeforeAllFailure_(suite).then(() => {
|
this.#reportChildrenOfBeforeAllFailure(suite).then(() => {
|
||||||
this.reportSuiteDone_(suite, result, next);
|
this.#reportSuiteDone(suite, result, next);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.reportSuiteDone_(suite, result, next);
|
this.#reportSuiteDone(suite, result, next);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
orderChildren: function(node) {
|
orderChildren: function(node) {
|
||||||
@@ -118,13 +129,13 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.execute2_(runablesToRun, order, processor);
|
return this.#execute2(runablesToRun, order, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute2_(runablesToRun, order, processor) {
|
async #execute2(runablesToRun, order, processor) {
|
||||||
const totalSpecsDefined = this.totalSpecsDefined_();
|
const totalSpecsDefined = this.#getTotalSpecsDefined();
|
||||||
|
|
||||||
this.runableResources_.initForRunable(this.topSuite_.id);
|
this.#runableResources.initForRunable(this.#topSuite.id);
|
||||||
const jasmineTimer = new j$.Timer();
|
const jasmineTimer = new j$.Timer();
|
||||||
jasmineTimer.start();
|
jasmineTimer.start();
|
||||||
|
|
||||||
@@ -136,7 +147,7 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
* @property {Boolean} parallel - Whether Jasmine is being run in parallel mode.
|
* @property {Boolean} parallel - Whether Jasmine is being run in parallel mode.
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
await this.reporter_.jasmineStarted({
|
await this.#reportDispatcher.jasmineStarted({
|
||||||
// In parallel mode, the jasmineStarted event is separately dispatched
|
// In parallel mode, the jasmineStarted event is separately dispatched
|
||||||
// by jasmine-npm. This event only reaches reporters in non-parallel.
|
// by jasmine-npm. This event only reaches reporters in non-parallel.
|
||||||
totalSpecsDefined,
|
totalSpecsDefined,
|
||||||
@@ -144,23 +155,23 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
parallel: false
|
parallel: false
|
||||||
});
|
});
|
||||||
|
|
||||||
this.currentlyExecutingSuites_.push(this.topSuite_);
|
this.currentlyExecutingSuites_.push(this.#topSuite);
|
||||||
await processor.execute();
|
await processor.execute();
|
||||||
|
|
||||||
if (this.topSuite_.hadBeforeAllFailure) {
|
if (this.#topSuite.hadBeforeAllFailure) {
|
||||||
await this.reportChildrenOfBeforeAllFailure_(this.topSuite_);
|
await this.#reportChildrenOfBeforeAllFailure(this.#topSuite);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.runableResources_.clearForRunable(this.topSuite_.id);
|
this.#runableResources.clearForRunable(this.#topSuite.id);
|
||||||
this.currentlyExecutingSuites_.pop();
|
this.currentlyExecutingSuites_.pop();
|
||||||
let overallStatus, incompleteReason, incompleteCode;
|
let overallStatus, incompleteReason, incompleteCode;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.hasFailures ||
|
this.hasFailures ||
|
||||||
this.topSuite_.result.failedExpectations.length > 0
|
this.#topSuite.result.failedExpectations.length > 0
|
||||||
) {
|
) {
|
||||||
overallStatus = 'failed';
|
overallStatus = 'failed';
|
||||||
} else if (this.focusedRunables_().length > 0) {
|
} else if (this.#getFocusedRunables().length > 0) {
|
||||||
overallStatus = 'incomplete';
|
overallStatus = 'incomplete';
|
||||||
incompleteReason = 'fit() or fdescribe() was found';
|
incompleteReason = 'fit() or fdescribe() was found';
|
||||||
incompleteCode = 'focused';
|
incompleteCode = 'focused';
|
||||||
@@ -191,33 +202,33 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
incompleteReason: incompleteReason,
|
incompleteReason: incompleteReason,
|
||||||
incompleteCode: incompleteCode,
|
incompleteCode: incompleteCode,
|
||||||
order: order,
|
order: order,
|
||||||
failedExpectations: this.topSuite_.result.failedExpectations,
|
failedExpectations: this.#topSuite.result.failedExpectations,
|
||||||
deprecationWarnings: this.topSuite_.result.deprecationWarnings
|
deprecationWarnings: this.#topSuite.result.deprecationWarnings
|
||||||
};
|
};
|
||||||
this.topSuite_.reportedDone = true;
|
this.#topSuite.reportedDone = true;
|
||||||
await this.reporter_.jasmineDone(jasmineDoneInfo);
|
await this.#reportDispatcher.jasmineDone(jasmineDoneInfo);
|
||||||
return jasmineDoneInfo;
|
return jasmineDoneInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
reportSuiteDone_(suite, result, next) {
|
#reportSuiteDone(suite, result, next) {
|
||||||
suite.reportedDone = true;
|
suite.reportedDone = true;
|
||||||
this.reporter_.suiteDone(result).then(next);
|
this.#reportDispatcher.suiteDone(result).then(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
async reportChildrenOfBeforeAllFailure_(suite) {
|
async #reportChildrenOfBeforeAllFailure(suite) {
|
||||||
for (const child of suite.children) {
|
for (const child of suite.children) {
|
||||||
if (child instanceof j$.Suite) {
|
if (child instanceof j$.Suite) {
|
||||||
await this.reporter_.suiteStarted(child.result);
|
await this.#reportDispatcher.suiteStarted(child.result);
|
||||||
await this.reportChildrenOfBeforeAllFailure_(child);
|
await this.#reportChildrenOfBeforeAllFailure(child);
|
||||||
|
|
||||||
// Marking the suite passed is consistent with how suites that
|
// Marking the suite passed is consistent with how suites that
|
||||||
// contain failed specs but no suite-level failures are reported.
|
// contain failed specs but no suite-level failures are reported.
|
||||||
child.result.status = 'passed';
|
child.result.status = 'passed';
|
||||||
|
|
||||||
await this.reporter_.suiteDone(child.result);
|
await this.#reportDispatcher.suiteDone(child.result);
|
||||||
} else {
|
} else {
|
||||||
/* a spec */
|
/* a spec */
|
||||||
await this.reporter_.specStarted(child.result);
|
await this.#reportDispatcher.specStarted(child.result);
|
||||||
|
|
||||||
child.addExpectationResult(
|
child.addExpectationResult(
|
||||||
false,
|
false,
|
||||||
@@ -233,7 +244,7 @@ getJasmineRequireObj().Runner = function(j$) {
|
|||||||
child.result.status = 'failed';
|
child.result.status = 'failed';
|
||||||
|
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
this.reportSpecDone_(child, child.result, resolve);
|
this.#reportSpecDone(child, child.result, resolve);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user