Skip to content

Commit

Permalink
Merge pull request #12 from mrloop/reset-env
Browse files Browse the repository at this point in the history
feat: reset test environment on each retry
  • Loading branch information
mrloop authored Oct 23, 2024
2 parents 61e438e + 3085a29 commit 69a8eb1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.env
node_modules
node_modules
.vscode
13 changes: 13 additions & 0 deletions src/extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function extend (a, b, undefOnly, allProperties) {
for (const prop in b) {
if (Object.hasOwn.call(b, prop) || allProperties) {
if (b[prop] === undefined) {
delete a[prop]
} else if (!(undefOnly && typeof a[prop] !== 'undefined')) {
a[prop] = b[prop]
}
}
}

return a
}
2 changes: 2 additions & 0 deletions src/retry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AssertResultHandler from './assert-result-handler.js'
import extend from './extend.js'

export default class Retry {
constructor (name, callback, maxRuns = 2, testFn) {
Expand Down Expand Up @@ -58,6 +59,7 @@ export default class Retry {

async runTest () {
if (this.notFirstRun) {
this.test.testEnvironment = extend({}, this.test.module.testEnvironment, false, true)
await this.runHooks(this.beforeEachHooks)
}
await this.tryTest()
Expand Down
6 changes: 6 additions & 0 deletions test/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ QUnit.module('hook context', function (hooks) {
assert.equal(this.sharedValue, 'myContext')
assert.equal(currentRun, 2)
})

retry('environment it reset on each retry', function (assert, currentRun) {
assert.equal(this.localValue, undefined)
this.localValue = 'local'
assert.equal(currentRun, 2)
})
})

QUnit.module('currentRun count', function () {
Expand Down

0 comments on commit 69a8eb1

Please sign in to comment.