Skip to content

simplified test file skipping (#4996) #5003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 13, 2018
22 changes: 12 additions & 10 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,6 @@ runTests = (CoffeeScript) ->
catch err
onFail description, fn, err

global.supportsAsync = try
new Function('async () => {}')()
yes
catch
no

helpers.extend global, require './test/support/helpers'

# When all the tests have run, collect and print errors.
Expand All @@ -448,10 +442,18 @@ runTests = (CoffeeScript) ->
console.log " #{source}" if source
return

# Run every test in the `test` folder, recording failures.
files = fs.readdirSync 'test'
unless global.supportsAsync # Except for async tests, if async isn’t supported.
files = files.filter (filename) -> filename isnt 'async.coffee'
# Run every test in the `test` folder, recording failures, except for files
# we’re skipping because the features to be tested are unsupported in the
# current Node runtime.
testFilesToSkip = []
skipUnless = (featureDetect, filenames) ->
unless (try new Function featureDetect)
testFilesToSkip = testFilesToSkip.concat filenames
skipUnless 'async () => {}', ['async.coffee', 'async_iterators.coffee']
skipUnless 'async function* generator() { yield 42; }', ['async_iterators.coffee']
skipUnless 'var a = 2 ** 2; a **= 3', ['exponentiation.coffee']
files = fs.readdirSync('test').filter (filename) ->
filename not in testFilesToSkip

startTime = Date.now()
for file in files when helpers.isCoffee file
Expand Down
7 changes: 4 additions & 3 deletions test/async.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Functions that contain the `await` keyword will compile into async functions,
# supported by Node 7.6+, Chrome 55+, Firefox 52+, Safari 10.1+ and Edge.
# But runtimes that don’t support the `await` keyword will throw an error,
# even if we put `return unless global.supportsAsync` at the top of this file.
# Therefore we need to prevent runtimes which will choke on such code from even
# But runtimes that don’t support the `await` keyword will throw an error just
# from parsing this file, even without executing it, even if we put
# `return unless try new Function 'async () => {}'` at the top of this file.
# Therefore we need to prevent runtimes which will choke on such code from
# parsing it, which is handled in `Cakefile`.


Expand Down
2 changes: 1 addition & 1 deletion test/repl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ testRepl "keeps running after runtime error", (input, output) ->
eq 'undefined', output.lastWrite()

testRepl "#4604: wraps an async function", (input, output) ->
return unless global.supportsAsync
return unless try new Function 'async () => {}' # Feature detect support for async functions.
input.emitLine 'await new Promise (resolve) -> setTimeout (-> resolve 33), 10'
setTimeout ->
eq '33', output.lastWrite()
Expand Down