From ab3d0ba4121ec62357f49a10737e0b4869cb51fa Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 12 Aug 2016 17:46:09 +0200 Subject: [PATCH] Rewrite async-spec-helpers in javascript Signed-off-by: Nathan Sobo --- spec/async-spec-helpers.coffee | 30 ------------------------ spec/async-spec-helpers.js | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 30 deletions(-) delete mode 100644 spec/async-spec-helpers.coffee create mode 100644 spec/async-spec-helpers.js diff --git a/spec/async-spec-helpers.coffee b/spec/async-spec-helpers.coffee deleted file mode 100644 index 6ed8a5a2b..000000000 --- a/spec/async-spec-helpers.coffee +++ /dev/null @@ -1,30 +0,0 @@ -exports.beforeEach = (fn) -> - global.beforeEach -> - result = fn() - if result instanceof Promise - waitsForPromise(-> result) - -exports.afterEach = (fn) -> - global.afterEach -> - result = fn() - if result instanceof Promise - waitsForPromise(-> result) - -['it', 'fit', 'ffit', 'fffit'].forEach (name) -> - exports[name] = (description, fn) -> - global[name] description, -> - result = fn() - if result instanceof Promise - waitsForPromise(-> result) - -waitsForPromise = (fn) -> - promise = fn() - # This timeout is 3 minutes. We need to bump it back down once we fix backgrounding - # of the renderer process on CI. See https://github.com/atom/electron/issues/4317 - waitsFor 'spec promise to resolve', 3 * 60 * 1000, (done) -> - promise.then( - done, - (error) -> - jasmine.getEnv().currentSpec.fail(error) - done() - ) diff --git a/spec/async-spec-helpers.js b/spec/async-spec-helpers.js new file mode 100644 index 000000000..744581143 --- /dev/null +++ b/spec/async-spec-helpers.js @@ -0,0 +1,42 @@ +/** @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) { + global[name](description, function () { + const result = fn() + if (result instanceof Promise) { + waitsForPromise(() => result) + } + }) + } +}) + +function waitsForPromise (fn) { + const promise = fn() + // This timeout is 3 minutes. We need to bump it back down once we fix + // backgrounding of the renderer process on CI. See https://github.com/atom/electron/issues/4317 + global.waitsFor('spec promise to resolve', 3 * 60 * 1000, function (done) { + promise.then(done, function (error) { + jasmine.getEnv().currentSpec.fail(error) + done() + }) + }) +}