Skip to content

Commit 5a43b2d

Browse files
rdeforestGeoffreyBooth
authored andcommitted
simplified test file skipping (#4996) (#5003)
simplified test file skipping (#4996)
1 parent 820942c commit 5a43b2d

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

Cakefile

+12-10
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,6 @@ runTests = (CoffeeScript) ->
425425
catch err
426426
onFail description, fn, err
427427

428-
global.supportsAsync = try
429-
new Function('async () => {}')()
430-
yes
431-
catch
432-
no
433-
434428
helpers.extend global, require './test/support/helpers'
435429

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

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

456458
startTime = Date.now()
457459
for file in files when helpers.isCoffee file

test/async.coffee

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Functions that contain the `await` keyword will compile into async functions,
22
# supported by Node 7.6+, Chrome 55+, Firefox 52+, Safari 10.1+ and Edge.
3-
# But runtimes that don’t support the `await` keyword will throw an error,
4-
# even if we put `return unless global.supportsAsync` at the top of this file.
5-
# Therefore we need to prevent runtimes which will choke on such code from even
3+
# But runtimes that don’t support the `await` keyword will throw an error just
4+
# from parsing this file, even without executing it, even if we put
5+
# `return unless try new Function 'async () => {}'` at the top of this file.
6+
# Therefore we need to prevent runtimes which will choke on such code from
67
# parsing it, which is handled in `Cakefile`.
78

89

test/repl.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ testRepl "keeps running after runtime error", (input, output) ->
124124
eq 'undefined', output.lastWrite()
125125

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

0 commit comments

Comments
 (0)