| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -192,6 +192,13 @@ class Test extends AsyncResource { | |||
| 192 | 192 | this.testNumber = 0; | |
| 193 | 193 | this.timeout = kDefaultTimeout; | |
| 194 | 194 | this.root = this; | |
| 195 | + this.hooks = { | ||
| 196 | + __proto__: null, | ||
| 197 | + before: [], | ||
| 198 | + after: [], | ||
| 199 | + beforeEach: [], | ||
| 200 | + afterEach: [], | ||
| 201 | + }; | ||
| 195 | 202 | } else { | |
| 196 | 203 | const nesting = parent.parent === null ? parent.nesting : | |
| 197 | 204 | parent.nesting + 1; | |
@@ -204,6 +211,13 @@ class Test extends AsyncResource { | |||
| 204 | 211 | this.testNumber = parent.subtests.length + 1; | |
| 205 | 212 | this.timeout = parent.timeout; | |
| 206 | 213 | this.root = parent.root; | |
| 214 | + this.hooks = { | ||
| 215 | + __proto__: null, | ||
| 216 | + before: [], | ||
| 217 | + after: [], | ||
| 218 | + beforeEach: ArrayPrototypeSlice(parent.hooks.beforeEach), | ||
| 219 | + afterEach: ArrayPrototypeSlice(parent.hooks.afterEach), | ||
| 220 | + }; | ||
| 207 | 221 | } | |
| 208 | 222 | ||
| 209 | 223 | switch (typeof concurrency) { | |
@@ -277,12 +291,6 @@ class Test extends AsyncResource { | |||
| 277 | 291 | this.pendingSubtests = []; | |
| 278 | 292 | this.readySubtests = new SafeMap(); | |
| 279 | 293 | this.subtests = []; | |
| 280 | - this.hooks = { | ||
| 281 | - before: [], | ||
| 282 | - after: [], | ||
| 283 | - beforeEach: [], | ||
| 284 | - afterEach: [], | ||
| 285 | - }; | ||
| 286 | 294 | this.waitingOn = 0; | |
| 287 | 295 | this.finished = false; | |
| 288 | 296 | ||
@@ -772,11 +780,6 @@ class Suite extends Test { | |||
| 772 | 780 | ||
| 773 | 781 | async run() { | |
| 774 | 782 | const hookArgs = this.getRunArgs(); | |
| 775 | - const afterEach = runOnce(async () => { | ||
| 776 | - if (this.parent?.hooks.afterEach.length > 0) { | ||
| 777 | - await this.parent.runHook('afterEach', hookArgs); | ||
| 778 | - } | ||
| 779 | - }); | ||
| 780 | 783 | ||
| 781 | 784 | try { | |
| 782 | 785 | this.parent.activeSubtests++; | |
@@ -789,10 +792,6 @@ class Suite extends Test { | |||
| 789 | 792 | return; | |
| 790 | 793 | } | |
| 791 | 794 | ||
| 792 | - if (this.parent?.hooks.beforeEach.length > 0) { | ||
| 793 | - await this.parent.runHook('beforeEach', hookArgs); | ||
| 794 | - } | ||
| 795 | - | ||
| 796 | 795 | await this.runHook('before', hookArgs); | |
| 797 | 796 | ||
| 798 | 797 | const stopPromise = stopTest(this.timeout, this.signal); | |
@@ -801,11 +800,9 @@ class Suite extends Test { | |||
| 801 | 800 | ||
| 802 | 801 | await SafePromiseRace([promise, stopPromise]); | |
| 803 | 802 | await this.runHook('after', hookArgs); | |
| 804 | - await afterEach(); | ||
| 805 | 803 | ||
| 806 | 804 | this.pass(); | |
| 807 | 805 | } catch (err) { | |
| 808 | - try { await afterEach(); } catch { /* test is already failing, let's ignore the error */ } | ||
| 809 | 806 | if (isTestFailureError(err)) { | |
| 810 | 807 | this.fail(err); | |
| 811 | 808 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,12 +17,10 @@ describe('describe hooks', () => { | |||
| 17 | 17 | 'before describe hooks', | |
| 18 | 18 | 'beforeEach 1', '1', 'afterEach 1', | |
| 19 | 19 | 'beforeEach 2', '2', 'afterEach 2', | |
| 20 | - 'beforeEach nested', | ||
| 21 | 20 | 'before nested', | |
| 22 | - 'beforeEach nested 1', 'nested 1', 'afterEach nested 1', | ||
| 23 | - 'beforeEach nested 2', 'nested 2', 'afterEach nested 2', | ||
| 21 | + 'beforeEach nested 1', '+beforeEach nested 1', 'nested 1', 'afterEach nested 1', '+afterEach nested 1', | ||
| 22 | + 'beforeEach nested 2', '+beforeEach nested 2', 'nested 2', 'afterEach nested 2', '+afterEach nested 2', | ||
| 24 | 23 | 'after nested', | |
| 25 | - 'afterEach nested', | ||
| 26 | 24 | 'after describe hooks', | |
| 27 | 25 | ]); | |
| 28 | 26 | }); | |
@@ -44,10 +42,10 @@ describe('describe hooks', () => { | |||
| 44 | 42 | testArr.push('after ' + this.name); | |
| 45 | 43 | }); | |
| 46 | 44 | beforeEach(function() { | |
| 47 | - testArr.push('beforeEach ' + this.name); | ||
| 45 | + testArr.push('+beforeEach ' + this.name); | ||
| 48 | 46 | }); | |
| 49 | 47 | afterEach(function() { | |
| 50 | - testArr.push('afterEach ' + this.name); | ||
| 48 | + testArr.push('+afterEach ' + this.name); | ||
| 51 | 49 | }); | |
| 52 | 50 | it('nested 1', () => testArr.push('nested 1')); | |
| 53 | 51 | test('nested 2', () => testArr.push('nested 2')); | |
@@ -111,8 +109,8 @@ test('test hooks', async (t) => { | |||
| 111 | 109 | 'beforeEach 1', 'before test hooks', '1', 'afterEach 1', | |
| 112 | 110 | 'beforeEach 2', '2', 'afterEach 2', | |
| 113 | 111 | 'beforeEach nested', | |
| 114 | - 'nested beforeEach nested 1', 'nested1', 'nested afterEach nested 1', | ||
| 115 | - 'nested beforeEach nested 2', 'nested 2', 'nested afterEach nested 2', | ||
| 112 | + 'beforeEach nested 1', 'nested beforeEach nested 1', 'nested1', 'afterEach nested 1', 'nested afterEach nested 1', | ||
| 113 | + 'beforeEach nested 2', 'nested beforeEach nested 2', 'nested 2', 'afterEach nested 2', 'nested afterEach nested 2', | ||
| 116 | 114 | 'afterEach nested', | |
| 117 | 115 | ]); | |
| 118 | 116 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,8 +34,8 @@ test('top level test enabled', common.mustCall(async (t) => { | |||
| 34 | 34 | ||
| 35 | 35 | describe('top level describe enabled', () => { | |
| 36 | 36 | before(common.mustCall()); | |
| 37 | - beforeEach(common.mustCall(4)); | ||
| 38 | - afterEach(common.mustCall(4)); | ||
| 37 | + beforeEach(common.mustCall(3)); | ||
| 38 | + afterEach(common.mustCall(3)); | ||
| 39 | 39 | after(common.mustCall()); | |
| 40 | 40 | ||
| 41 | 41 | it('nested it disabled', common.mustNotCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments