| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dde0cff commit 7c02486
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ const { | |||
| 6 | 6 | ArrayPrototypeShift, | |
| 7 | 7 | ArrayPrototypeSlice, | |
| 8 | 8 | ArrayPrototypeSome, | |
| 9 | + ArrayPrototypeSplice, | ||
| 9 | 10 | ArrayPrototypeUnshift, | |
| 10 | 11 | FunctionPrototype, | |
| 11 | 12 | MathMax, | |
@@ -275,6 +276,7 @@ class Test extends AsyncResource { | |||
| 275 | 276 | after: [], | |
| 276 | 277 | beforeEach: [], | |
| 277 | 278 | afterEach: [], | |
| 279 | + ownAfterEachCount: 0, | ||
| 278 | 280 | }; | |
| 279 | 281 | } else { | |
| 280 | 282 | const nesting = parent.parent === null ? parent.nesting : | |
@@ -294,6 +296,7 @@ class Test extends AsyncResource { | |||
| 294 | 296 | after: [], | |
| 295 | 297 | beforeEach: ArrayPrototypeSlice(parent.hooks.beforeEach), | |
| 296 | 298 | afterEach: ArrayPrototypeSlice(parent.hooks.afterEach), | |
| 299 | + ownAfterEachCount: 0, | ||
| 297 | 300 | }; | |
| 298 | 301 | ||
| 299 | 302 | if ((testNamePatterns !== null && !this.matchesTestNamePatterns()) || | |
@@ -559,7 +562,15 @@ class Test extends AsyncResource { | |||
| 559 | 562 | } | |
| 560 | 563 | }); | |
| 561 | 564 | } | |
| 562 | - ArrayPrototypePush(this.hooks[name], hook); | ||
| 565 | + if (name === 'afterEach') { | ||
| 566 | + // afterEach hooks for the current test should run in the order that they | ||
| 567 | + // are created. However, the current test's afterEach hooks should run | ||
| 568 | + // prior to any ancestor afterEach hooks. | ||
| 569 | + ArrayPrototypeSplice(this.hooks[name], this.hooks.ownAfterEachCount, 0, hook); | ||
| 570 | + this.hooks.ownAfterEachCount++; | ||
| 571 | + } else { | ||
| 572 | + ArrayPrototypePush(this.hooks[name], hook); | ||
| 573 | + } | ||
| 563 | 574 | return hook; | |
| 564 | 575 | } | |
| 565 | 576 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,14 +26,14 @@ after(() => { | |||
| 26 | 26 | 'describe beforeEach', | |
| 27 | 27 | 'describe nested beforeEach', | |
| 28 | 28 | 'describe nested it 1', | |
| 29 | - 'describe afterEach', | ||
| 30 | 29 | 'describe nested afterEach', | |
| 30 | + 'describe afterEach', | ||
| 31 | 31 | ||
| 32 | 32 | 'describe beforeEach', | |
| 33 | 33 | 'describe nested beforeEach', | |
| 34 | 34 | 'describe nested test 2', | |
| 35 | - 'describe afterEach', | ||
| 36 | 35 | 'describe nested afterEach', | |
| 36 | + 'describe afterEach', | ||
| 37 | 37 | ||
| 38 | 38 | 'describe nested after', | |
| 39 | 39 | 'describe after', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,8 @@ describe('describe hooks', () => { | |||
| 18 | 18 | 'beforeEach 1', '1', 'afterEach 1', | |
| 19 | 19 | 'beforeEach 2', '2', 'afterEach 2', | |
| 20 | 20 | 'before nested', | |
| 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', | ||
| 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', | ||
| 23 | 23 | 'after nested', | |
| 24 | 24 | 'after describe hooks', | |
| 25 | 25 | ]); | |
@@ -139,8 +139,8 @@ test('test hooks', async (t) => { | |||
| 139 | 139 | 'beforeEach 2', '2', 'afterEach 2', | |
| 140 | 140 | 'beforeEach nested', | |
| 141 | 141 | 'nested before nested', | |
| 142 | - 'beforeEach nested 1', 'nested beforeEach nested 1', 'nested1', 'afterEach nested 1', 'nested afterEach nested 1', | ||
| 143 | - 'beforeEach nested 2', 'nested beforeEach nested 2', 'nested 2', 'afterEach nested 2', 'nested afterEach nested 2', | ||
| 142 | + 'beforeEach nested 1', 'nested beforeEach nested 1', 'nested1', 'nested afterEach nested 1', 'afterEach nested 1', | ||
| 143 | + 'beforeEach nested 2', 'nested beforeEach nested 2', 'nested 2', 'nested afterEach nested 2', 'afterEach nested 2', | ||
| 144 | 144 | 'afterEach nested', | |
| 145 | 145 | 'nested after nested', | |
| 146 | 146 | 'after test hooks', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments