Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Remove unnecessary reimplementations of spec helpers
Browse files Browse the repository at this point in the history
This is not needed anymore after atom/atom#18917
  • Loading branch information
rafeca committed Mar 14, 2019
1 parent ee5179e commit 6f177e9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 58 deletions.
68 changes: 13 additions & 55 deletions spec/async-spec-helpers.js
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()
})
})
}
1 change: 0 additions & 1 deletion spec/buffer-view-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const {it, fit, ffit, fffit, beforeEach, afterEach} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars
const path = require('path')
const temp = require('temp').track()
const BufferView = require('../lib/buffer-view')
Expand Down
2 changes: 1 addition & 1 deletion spec/fuzzy-finder-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const DefaultFileIcons = require('../lib/default-file-icons')
const getIconServices = require('../lib/get-icon-services')
const {Disposable} = require('atom')

const {it, fit, ffit, afterEach, beforeEach, conditionPromise} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars
const {conditionPromise} = require('./async-spec-helpers')

function rmrf (_path) {
if (fs.statSync(_path).isDirectory()) {
Expand Down
2 changes: 1 addition & 1 deletion spec/project-view-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {it, fit, ffit, fffit, beforeEach, afterEach, conditionPromise} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars
const {conditionPromise} = require('./async-spec-helpers')
const fs = require('fs')
const path = require('path')
const temp = require('temp').track()
Expand Down

0 comments on commit 6f177e9

Please sign in to comment.