mirror of
https://github.com/atom/atom.git
synced 2026-01-25 23:08:18 -05:00
Override global jasmine spec functions
Currently, if a spec uses the global `it` function on an async test, that test will always pass (since the jasmine version checked in Atom does not natively support tests that return promises). This can be confusing since the test behaviour is different between the async-test-helpers methods and the global ones. By overriding the global functions, we'll also be able to remove all the imports from async-test-helpers since they won't be needed anymore. More info: https://github.com/atom/atom/pull/18896#discussion_r260396102
This commit is contained in:
@@ -10,6 +10,16 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) ->
|
||||
window[key] = value for key, value of require '../vendor/jasmine'
|
||||
require 'jasmine-tagged'
|
||||
|
||||
# Rewrite global jasmine functions to have support for async tests.
|
||||
# This way packages can create async specs without having to import these from the
|
||||
# async-spec-helpers file.
|
||||
global.it = asyncifyJasmineFn global.it, 1
|
||||
global.fit = asyncifyJasmineFn global.fit, 1
|
||||
global.ffit = asyncifyJasmineFn global.ffit, 1
|
||||
global.fffit = asyncifyJasmineFn global.fffit, 1
|
||||
global.beforeEach = asyncifyJasmineFn global.beforeEach, 0
|
||||
global.afterEach = asyncifyJasmineFn global.afterEach, 0
|
||||
|
||||
# Allow document.title to be assigned in specs without screwing up spec window title
|
||||
documentTitle = null
|
||||
Object.defineProperty document, 'title',
|
||||
@@ -59,6 +69,28 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) ->
|
||||
jasmineEnv.execute()
|
||||
promise
|
||||
|
||||
asyncifyJasmineFn = (fn, callbackPosition) ->
|
||||
(args...) ->
|
||||
if typeof args[callbackPosition] is 'function'
|
||||
callback = args[callbackPosition]
|
||||
|
||||
args[callbackPosition] = (args...) ->
|
||||
result = callback.apply this, args
|
||||
if result instanceof Promise
|
||||
waitsForPromise(-> result)
|
||||
|
||||
fn.apply this, args
|
||||
|
||||
waitsForPromise = (fn) ->
|
||||
promise = fn()
|
||||
|
||||
global.waitsFor('spec promise to resolve', (done) ->
|
||||
promise.then(done, (error) ->
|
||||
jasmine.getEnv().currentSpec.fail error
|
||||
done()
|
||||
)
|
||||
)
|
||||
|
||||
disableFocusMethods = ->
|
||||
['fdescribe', 'ffdescribe', 'fffdescribe', 'fit', 'ffit', 'fffit'].forEach (methodName) ->
|
||||
focusMethod = window[methodName]
|
||||
@@ -124,4 +156,4 @@ buildTerminalReporter = (logFile, resolveWithExitCode) ->
|
||||
new JasmineListReporter(options)
|
||||
else
|
||||
{TerminalReporter} = require 'jasmine-tagged'
|
||||
new TerminalReporter(options)
|
||||
new TerminalReporter(options)
|
||||
Reference in New Issue
Block a user