This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unnecessary reimplementations of spec helpers
This is not needed anymore after atom/atom#18917
- Loading branch information
Showing
4 changed files
with
15 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,23 @@ | ||
exports.beforeEach = function (fn) { | ||
global.beforeEach(function () { | ||
const result = fn() | ||
if (result instanceof Promise) { | ||
waitsForPromise(() => result) | ||
} | ||
function timeoutPromise (timeout) { | ||
return new Promise(function (resolve) { | ||
global.setTimeout(resolve, timeout) | ||
}) | ||
} | ||
|
||
exports.afterEach = function (fn) { | ||
global.afterEach(function () { | ||
const result = fn() | ||
if (result instanceof Promise) { | ||
waitsForPromise(() => result) | ||
} | ||
}) | ||
} | ||
module.exports = { | ||
async conditionPromise (condition, description = 'anonymous condition') { | ||
const startTime = Date.now() | ||
|
||
for (const name of ['it', 'fit', 'ffit', 'fffit']) { | ||
module.exports[name] = function (description, fn) { | ||
if (fn === undefined) { | ||
global[name](description) | ||
return | ||
} | ||
while (true) { | ||
await timeoutPromise(100) | ||
|
||
global[name](description, function () { | ||
const result = fn() | ||
if (result instanceof Promise) { | ||
waitsForPromise(() => result) | ||
if (await condition()) { | ||
return | ||
} | ||
}) | ||
} | ||
} | ||
|
||
exports.conditionPromise = async function (condition, description = 'anonymous condition') { | ||
const startTime = Date.now() | ||
|
||
while (true) { | ||
await exports.timeoutPromise(100) | ||
|
||
if (await condition()) { | ||
return | ||
} | ||
|
||
if (Date.now() - startTime > 5000) { | ||
throw new Error('Timed out waiting on ' + description) | ||
if (Date.now() - startTime > 5000) { | ||
throw new Error('Timed out waiting on ' + description) | ||
} | ||
} | ||
} | ||
} | ||
|
||
exports.timeoutPromise = function (timeout) { | ||
return new Promise(function (resolve) { | ||
global.setTimeout(resolve, timeout) | ||
}) | ||
} | ||
|
||
function waitsForPromise (fn) { | ||
const promise = fn() | ||
global.waitsFor('spec promise to resolve', function (done) { | ||
promise.then(done, function (error) { | ||
jasmine.getEnv().currentSpec.fail(error) | ||
done() | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters