Skip to content

Commit

Permalink
Spiced up the feature detection
Browse files Browse the repository at this point in the history
  • Loading branch information
STRd6 committed Apr 1, 2022
1 parent 97106e6 commit 92470ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ runTests = (CoffeeScript) ->
# current Node runtime.
testFilesToSkip = []
skipUnless = (featureDetect, filenames) ->
unless (try new Function featureDetect)
try
await (new Function featureDetect)()
catch
testFilesToSkip = testFilesToSkip.concat filenames
skipUnless 'async () => {}', ['async.coffee', 'async_iterators.coffee']
skipUnless 'async function* generator() { yield 42; }', ['async_iterators.coffee']
Expand All @@ -476,7 +478,7 @@ runTests = (CoffeeScript) ->
skipUnless '/foo.bar/s.test("foo\tbar")', ['regex_dotall.coffee']
skipUnless '1_2_3', ['numeric_literal_separators.coffee']
skipUnless '1n', ['numbers_bigint.coffee']
skipUnless 'async () => { await import(\'data:application/json,{"foo":"bar"}\', { assert: { type: "json" } }) }', ['import_assertions.coffee']
await skipUnless 'return import(\'data:application/json,{"foo":"bar"}\', { assert: { type: "json" } })', ['import_assertions.coffee']
files = fs.readdirSync('test').filter (filename) ->
filename not in testFilesToSkip

Expand Down
22 changes: 10 additions & 12 deletions test/import_assertions.coffee
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# This file is running in CommonJS (in Node) or as a classic Script (in the browser tests) so it can use import() within an async function, but not at the top level; and we can’t use static import.
test "dynamic import assertion", ->
if typeof process is "undefined" or process.version?.startsWith("v17")
{ default: secret } = await import('data:application/json,{"ofLife":42}', { assert: { type: 'json' } })
eq secret.ofLife, 42
{ default: secret } = await import('data:application/json,{"ofLife":42}', { assert: { type: 'json' } })
eq secret.ofLife, 42

test "assert keyword", ->
if typeof process is "undefined" or process.version?.startsWith("v17")
assert = 1
assert = 1

{ default: assert } = await import('data:application/json,{"thatIAm":42}', { assert: { type: 'json' } })
eq assert.thatIAm, 42
{ default: assert } = await import('data:application/json,{"thatIAm":42}', { assert: { type: 'json' } })
eq assert.thatIAm, 42

eqJS """
import assert from 'regression-test'
""", """
import assert from 'regression-test';
"""
eqJS """
import assert from 'regression-test'
""", """
import assert from 'regression-test';
"""

test "static import assertion", ->
eqJS """
Expand Down

0 comments on commit 92470ce

Please sign in to comment.