Skip to content

Commit

Permalink
Add patchStackTrace export; test that all named exports are detecte…
Browse files Browse the repository at this point in the history
…d by Node (#5411)
  • Loading branch information
GeoffreyBooth authored Apr 19, 2022
1 parent 4f36552 commit 6b4f166
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/v2/annotated-source/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ <h1>index.coffee</h1>
module.<span class="hljs-built_in">exports</span>.<span class="hljs-built_in">eval</span> = CoffeeScript.<span class="hljs-built_in">eval</span>
module.<span class="hljs-built_in">exports</span>.run = CoffeeScript.run
module.<span class="hljs-built_in">exports</span>.transpile = CoffeeScript.transpile
module.<span class="hljs-built_in">exports</span>.patchStackTrace = CoffeeScript.patchStackTrace
module.<span class="hljs-built_in">exports</span>._compileRawFileContent = CoffeeScript._compileRawFileContent
module.<span class="hljs-built_in">exports</span>._compileFile = CoffeeScript._compileFile</pre></div></div>

Expand Down
30 changes: 30 additions & 0 deletions docs/v2/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -31451,6 +31451,36 @@ <h2>Another heading</h2>
].join('\n')
ok new OptionParser(flags).help() is expected

</script>
<script type="text/x-coffeescript" class="test" id="package">
return if window? or testingBrowser?

{EventEmitter} = require 'events'
{join} = require 'path'
{cwd} = require 'process'
{pathToFileURL} = require 'url'


packageEntryPath = join cwd(), 'lib/coffeescript/index.js'
packageEntryUrl = pathToFileURL packageEntryPath


test "the coffeescript package exposes all members as named exports in Node", ->

requiredPackage = require packageEntryPath
requiredKeys = Object.keys requiredPackage

importedPackage = await import(packageEntryUrl)
importedKeys = new Set Object.keys(importedPackage)

# In `command.coffee`, CoffeeScript extends a `new EventEmitter`;
# we want to ignore these additional added keys.
eventEmitterKeys = new Set Object.getOwnPropertyNames(Object.getPrototypeOf(new EventEmitter))

for key in requiredKeys when not eventEmitterKeys.has(key)
# Use `eq` test so that missing keys have their names printed in the error message.
eq (if importedKeys.has(key) then key else undefined), key

</script>
<script type="text/x-coffeescript" class="test" id="parser">
# Parser
Expand Down
2 changes: 2 additions & 0 deletions lib/coffeescript/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,6 @@ module.exports.register = CoffeeScript.register
module.exports.eval = CoffeeScript.eval
module.exports.run = CoffeeScript.run
module.exports.transpile = CoffeeScript.transpile
module.exports.patchStackTrace = CoffeeScript.patchStackTrace
module.exports._compileRawFileContent = CoffeeScript._compileRawFileContent
module.exports._compileFile = CoffeeScript._compileFile
27 changes: 27 additions & 0 deletions test/package.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
return if window? or testingBrowser?

{EventEmitter} = require 'events'
{join} = require 'path'
{cwd} = require 'process'
{pathToFileURL} = require 'url'


packageEntryPath = join cwd(), 'lib/coffeescript/index.js'
packageEntryUrl = pathToFileURL packageEntryPath


test "the coffeescript package exposes all members as named exports in Node", ->

requiredPackage = require packageEntryPath
requiredKeys = Object.keys requiredPackage

importedPackage = await import(packageEntryUrl)
importedKeys = new Set Object.keys(importedPackage)

# In `command.coffee`, CoffeeScript extends a `new EventEmitter`;
# we want to ignore these additional added keys.
eventEmitterKeys = new Set Object.getOwnPropertyNames(Object.getPrototypeOf(new EventEmitter))

for key in requiredKeys when not eventEmitterKeys.has(key)
# Use `eq` test so that missing keys have their names printed in the error message.
eq (if importedKeys.has(key) then key else undefined), key

0 comments on commit 6b4f166

Please sign in to comment.