UNPKG

3.83 kBJavaScriptView Raw
1
2'use strict';
3/*jshint asi: true */
4
5var test = require('tape')
6 , stackMapper = require('../../')
7 , relevant = require('../util/relevant')
8
9var origStack = [
10 'Error: shouldn\'t have called foobar ;)',
11 ' at foobar (/full/path/to/bundle.js:14:9)',
12 ' at module.exports (/full/path/to/bundle.js:7:10)',
13 ' at bar (/full/path/to/bundle.js:25:12)',
14 ' at Object.main (/full/path/to/bundle.js:27:10)',
15 ' at /Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw.js:20:11',
16 ' at /Users/thlorenz/dev/js/projects/stack-mapper/test/util/bundle-n-map.js:19:7',
17 ' at /Users/thlorenz/dev/js/projects/stack-mapper/node_modules/browserify/index.js:232:22',
18 ' at /Users/thlorenz/dev/js/projects/stack-mapper/node_modules/browserify/index.js:232:22',
19 ' at ConcatStream.cb (/Users/thlorenz/dev/js/projects/stack-mapper/node_modules/browserify/index.js:268:46)',
20 ' at ConcatStream.end (/Users/thlorenz/dev/js/projects/stack-mapper/node_modules/browserify/node_modules/concat-stream/index.js:42:21)' ]
21 .join('\n')
22
23var map = { version: 3,
24 file: 'generated.js',
25 sources:
26 [ '/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/barbar.js',
27 '/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/foobar.js',
28 '/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/main.js' ],
29 names: [],
30 mappings: ';AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACPA;AACA;AACA;AACA;AACA;AACA;;ACLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA',
31 sourcesContent:
32 [ '\'use strict\';\n\nvar foobar = require(\'./foobar\');\n\nvar go = module.exports = function () {\n return foobar(); \n};\n',
33 '\'use strict\';\n\nvar go = module.exports = function foobar() {\n throw new Error(\'shouldn\\\'t have called foobar ;)\'); \n};\n',
34 '\'use strict\';\n\nvar barbar = require(\'./barbar\');\n\nmodule.exports = function main() {\n var a = 1;\n function bar() {\n return barbar();\n }\n return bar();\n}\n' ] }
35
36test('\nthree files returning, one throwing an error no source', function (t) {
37 var sm = stackMapper(map);
38 var info = sm.map(origStack);
39 var stack = relevant(info, 6);
40
41 t.deepEqual(
42 stack
43 , [ 'Error: shouldn\'t have called foobar ;)',
44 ' at foobar (/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/foobar.js:4:9)',
45 ' at module.exports (/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/barbar.js:6:10)',
46 ' at bar (/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/main.js:8:12)',
47 ' at Object.main (/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/main.js:10:10)',
48 ' at /Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw.js' ]
49 , 'returns stack with all trace information mapped'
50 )
51
52 t.end()
53})
54
55test('\nthree files returning, one throwing an error including source', function (t) {
56 var sm = stackMapper(map);
57 var info = sm.map(origStack, true);
58 var stack = relevant(info, 7);
59
60 t.deepEqual(
61 stack
62 , [ 'Error: shouldn\'t have called foobar ;)',
63 ' at foobar (/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/foobar.js:4:9)',
64 '\t" throw new Error(\'shouldn\\\'t have called foobar ;)\'); "',
65 ' at module.exports (/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/barbar.js:6:10)',
66 ' at bar (/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/main.js:8:12)',
67 ' at Object.main (/Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw/main.js:10:10)',
68 ' at /Users/thlorenz/dev/js/projects/stack-mapper/test/threefiles-throw.js' ]
69 , 'returns stack with all trace information mapped'
70 )
71
72 t.end()
73})