diff --git a/Cakefile b/Cakefile index 599520f6..243b140d 100644 --- a/Cakefile +++ b/Cakefile @@ -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. @@ -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 diff --git a/test/async.coffee b/test/async.coffee index be1994c5..eb72972a 100644 --- a/test/async.coffee +++ b/test/async.coffee @@ -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`. diff --git a/test/repl.coffee b/test/repl.coffee index 537631e1..fb79e7f1 100644 --- a/test/repl.coffee +++ b/test/repl.coffee @@ -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()