Skip to content

Commit

Permalink
Remove uneeded methods from async-spec-helpers modules
Browse files Browse the repository at this point in the history
  • Loading branch information
rafeca committed Mar 1, 2019
1 parent 67afbe6 commit ec70539
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 338 deletions.
39 changes: 0 additions & 39 deletions packages/about/spec/helpers/async-spec-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,6 @@
const { now } = Date
const { setTimeout } = global

export function beforeEach (fn) {
global.beforeEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}

export function afterEach (fn) {
global.afterEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}

;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) {
module.exports[name] = function (description, fn) {
global[name](description, function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
})

export async function conditionPromise (condition) {
const startTime = now()

Expand All @@ -53,13 +24,3 @@ export function timeoutPromise (timeout) {
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()
})
})
}
80 changes: 0 additions & 80 deletions packages/dev-live-reload/spec/async-spec-helpers.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
/** @babel */

export function beforeEach (fn) {
global.beforeEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}

export function afterEach (fn) {
global.afterEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}

;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) {
module.exports[name] = function (description, fn) {
if (fn === undefined) {
global[name](description)
return
}

global[name](description, function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
})

export async function conditionPromise (
condition,
description = 'anonymous condition'
Expand All @@ -58,49 +24,3 @@ export function timeoutPromise (timeout) {
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()
})
})
}

export function emitterEventPromise (emitter, event, timeout = 15000) {
return new Promise((resolve, reject) => {
const timeoutHandle = setTimeout(() => {
reject(new Error(`Timed out waiting for '${event}' event`))
}, timeout)
emitter.once(event, () => {
clearTimeout(timeoutHandle)
resolve()
})
})
}

export function promisify (original) {
return function (...args) {
return new Promise((resolve, reject) => {
args.push((err, ...results) => {
if (err) {
reject(err)
} else {
resolve(...results)
}
})

return original(...args)
})
}
}

export function promisifySome (obj, fnNames) {
const result = {}
for (const fnName of fnNames) {
result[fnName] = promisify(obj[fnName])
}
return result
}
41 changes: 0 additions & 41 deletions packages/grammar-selector/spec/async-spec-helpers.js

This file was deleted.

106 changes: 0 additions & 106 deletions packages/link/spec/async-spec-helpers.js

This file was deleted.

72 changes: 0 additions & 72 deletions spec/async-spec-helpers.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
function beforeEach (fn) {
global.beforeEach(() => {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}

function afterEach (fn) {
global.afterEach(() => {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}

;['it', 'fit', 'ffit', 'fffit'].forEach(name => {
exports[name] = (description, fn) => {
if (fn === undefined) {
global[name](description)
return
}

global[name](description, () => {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
})

async function conditionPromise (
condition,
description = 'anonymous condition'
Expand All @@ -57,16 +23,6 @@ function timeoutPromise (timeout) {
})
}

function waitsForPromise (fn) {
const promise = fn()
global.waitsFor('spec promise to resolve', done => {
promise.then(done, error => {
jasmine.getEnv().currentSpec.fail(error)
done()
})
})
}

function emitterEventPromise (emitter, event, timeout = 15000) {
return new Promise((resolve, reject) => {
const timeoutHandle = setTimeout(() => {
Expand All @@ -79,34 +35,6 @@ function emitterEventPromise (emitter, event, timeout = 15000) {
})
}

function promisify (original) {
return function (...args) {
return new Promise((resolve, reject) => {
args.push((err, ...results) => {
if (err) {
reject(err)
} else {
resolve(...results)
}
})

return original(...args)
})
}
}

function promisifySome (obj, fnNames) {
const result = {}
for (const fnName of fnNames) {
result[fnName] = promisify(obj[fnName])
}
return result
}

exports.afterEach = afterEach
exports.beforeEach = beforeEach
exports.conditionPromise = conditionPromise
exports.emitterEventPromise = emitterEventPromise
exports.promisify = promisify
exports.promisifySome = promisifySome
exports.timeoutPromise = timeoutPromise

0 comments on commit ec70539

Please sign in to comment.