@@ -32712,6 +32712,7 @@ <h2>Another heading</h2>
32712
32712
<script type="text/x-coffeescript" class="test" id="sourcemap">
32713
32713
return if global.testingBrowser
32714
32714
32715
+ {spawn, fork} = require('child_process')
32715
32716
SourceMap = require '../src/sourcemap'
32716
32717
32717
32718
vlqEncodedValues = [
@@ -32776,6 +32777,125 @@ <h2>Another heading</h2>
32776
32777
arrayEq v3SourceMap.sources, ['tempus_fugit.coffee']
32777
32778
eq v3SourceMap.sourceRoot, './www_root/coffee/'
32778
32779
32780
+ test "node --enable-source-map built in stack trace mapping", ->
32781
+ new Promise (resolve, reject) ->
32782
+ proc = fork './test/importing/error.coffee', [
32783
+ '--enable-source-maps'
32784
+ ], stdio: 'pipe'
32785
+
32786
+ err = ''
32787
+ proc.stderr.setEncoding 'utf8'
32788
+ proc.stderr.on 'data', (str) -> err += str
32789
+ proc.on 'close', ->
32790
+ try
32791
+ match = err.match /error\.coffee:(\d+):(\d+)/
32792
+ throw new Error err unless match
32793
+
32794
+ [_, line, column] = match
32795
+ equal line, 3 # Mapped source line
32796
+ equal column, 9 # Mapped source column
32797
+
32798
+ resolve()
32799
+ catch exception
32800
+ reject exception
32801
+
32802
+ if Number(process.versions.node.split('.')[0]) >= 14
32803
+ test "NODE_OPTIONS=--enable-source-maps environment variable stack trace mapping", ->
32804
+ new Promise (resolve, reject) ->
32805
+ proc = fork './test/importing/error.coffee', [],
32806
+ env:
32807
+ NODE_OPTIONS: '--enable-source-maps'
32808
+ stdio: 'pipe'
32809
+
32810
+ err = ''
32811
+ proc.stderr.setEncoding 'utf8'
32812
+ proc.stderr.on 'data', (str) -> err += str
32813
+ proc.on 'close', ->
32814
+ try
32815
+ match = err.match /error\.coffee:(\d+):(\d+)/
32816
+ throw new Error err unless match
32817
+
32818
+ [_, line, column] = match
32819
+ equal line, 3 # Mapped source line
32820
+ equal column, 9 # Mapped source column
32821
+
32822
+ resolve()
32823
+ catch exception
32824
+ reject exception
32825
+
32826
+ test "generate correct stack traces with --enable-source-maps from bin/coffee", ->
32827
+ new Promise (resolve, reject) ->
32828
+ proc = fork 'test/importing/error.coffee',
32829
+ ['--enable-source-maps'],
32830
+ stdio: 'pipe'
32831
+
32832
+ err = ""
32833
+ proc.stderr.setEncoding 'utf8'
32834
+ proc.stderr.on 'data', (str) -> err += str
32835
+ proc.on 'close', ->
32836
+ try
32837
+ match = err.match /error\.coffee:(\d+):(\d+)/
32838
+ throw new Error err unless match
32839
+
32840
+ [_, line, column] = match
32841
+ equal line, 3 # Mapped source line
32842
+ equal column, 9 # Mapped source column
32843
+
32844
+ resolve()
32845
+ catch exception
32846
+ reject exception
32847
+
32848
+ test "don't change stack traces if another library has patched `Error.prepareStackTrace`", ->
32849
+ new Promise (resolve, reject) ->
32850
+ # This uses `spawn` rather than the preferred `fork` because `fork` requires
32851
+ # loading code in a separate file. The `--eval` here shows exactly what is
32852
+ # executing without indirection.
32853
+ proc = spawn 'node', [
32854
+ '--eval', """
32855
+ const patchedPrepareStackTrace = Error.prepareStackTrace = function() {};
32856
+ require('./register.js');
32857
+ process.stdout.write(Error.prepareStackTrace === patchedPrepareStackTrace ? 'preserved' : 'overwritten');
32858
+ """
32859
+ ]
32860
+
32861
+ out = ''
32862
+ proc.stdout.setEncoding 'utf8'
32863
+ proc.stdout.on 'data', (str) -> out += str
32864
+
32865
+ proc.on 'close', (status) ->
32866
+ try
32867
+ equal status, 0
32868
+ equal out, 'preserved'
32869
+
32870
+ resolve()
32871
+ catch exception
32872
+ reject exception
32873
+
32874
+ test "requiring 'CoffeeScript' doesn't change `Error.prepareStackTrace`", ->
32875
+ new Promise (resolve, reject) ->
32876
+ # This uses `spawn` rather than the preferred `fork` because `fork` requires
32877
+ # loading code in a separate file. The `--eval` here shows exactly what is
32878
+ # executing without indirection.
32879
+ proc = spawn 'node', [
32880
+ '--eval', """
32881
+ require('./lib/coffeescript/coffeescript.js');
32882
+ process.stdout.write(Error.prepareStackTrace === undefined ? 'unused' : 'defined');
32883
+ """
32884
+ ]
32885
+
32886
+ out = ''
32887
+ proc.stdout.setEncoding 'utf8'
32888
+ proc.stdout.on 'data', (str) -> out += str
32889
+
32890
+ proc.on 'close', (status) ->
32891
+ try
32892
+ equal status, 0
32893
+ equal out, 'unused'
32894
+
32895
+ resolve()
32896
+ catch exception
32897
+ reject exception
32898
+
32779
32899
</script>
32780
32900
<script type="text/x-coffeescript" class="test" id="strict">
32781
32901
# Strict Early Errors
0 commit comments