Skip to content

Commit 5742024

Browse files
misterbyrnetrentmwillis
authored andcommitted
Core: Defer getting the test source until we need it
1 parent cc1fdb6 commit 5742024

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export default function Test( settings ) {
3434
this.assertions = [];
3535
this.semaphore = 0;
3636
this.module = config.currentModule;
37-
this.stack = sourceFromStacktrace( 3 );
3837
this.steps = [];
3938
this.timeout = undefined;
39+
this.errorForStack = new Error();
4040

4141
// If a module is skipped, all its tests and the tests of the child suites
4242
// should be treated as skipped even if they are defined as `only` or `todo`.
@@ -112,6 +112,12 @@ function getNotStartedModules( startModule ) {
112112
}
113113

114114
Test.prototype = {
115+
116+
// generating a stack trace can be expensive, so using a getter defers this until we need it
117+
get stack() {
118+
return extractStacktrace( this.errorForStack, 2 );
119+
},
120+
115121
before: function() {
116122
var module = this.module,
117123
notStartedModules = getNotStartedModules( module );
@@ -318,6 +324,7 @@ Test.prototype = {
318324
// avoid leaking it. It is not used by the legacy testDone callbacks.
319325
emit( "testEnd", this.testReport.end( true ) );
320326
this.testReport.slimAssertions();
327+
const test = this;
321328

322329
return runLoggingCallbacks( "testDone", {
323330
name: testName,
@@ -334,7 +341,8 @@ Test.prototype = {
334341
testId: this.testId,
335342

336343
// Source of Test
337-
source: this.stack
344+
// generating stack trace is expensive, so using a getter will help defer this until we need it
345+
get source() { return test.stack; }
338346
} ).then( function() {
339347
if ( module.testsRun === numberOfTests( module ) ) {
340348
const completedModules = [ module ];

0 commit comments

Comments
 (0)