|
| 1 | +import { expect } from 'chai'; |
| 2 | + |
| 3 | +import { _computeStackTrace } from '../src/tracekit'; |
| 4 | + |
| 5 | +const CHROME73_NATIVE_CODE_EXCEPTION = { |
| 6 | + stack: `Error: test |
| 7 | + at fooIterator (http://192.168.20.143:5000/test:20:17) |
| 8 | + at Array.map (<anonymous>) |
| 9 | + at foo (http://192.168.20.143:5000/test:19:19) |
| 10 | + at http://192.168.20.143:5000/test:24:7`, |
| 11 | +}; |
| 12 | + |
| 13 | +const FIREFOX66_NATIVE_CODE_EXCEPTION = { |
| 14 | + stack: `fooIterator@http://192.168.20.143:5000/test:20:17 |
| 15 | + foo@http://192.168.20.143:5000/test:19:19 |
| 16 | + @http://192.168.20.143:5000/test:24:7`, |
| 17 | +}; |
| 18 | + |
| 19 | +const SAFARI12_NATIVE_CODE_EXCEPTION = { |
| 20 | + stack: `fooIterator@http://192.168.20.143:5000/test:20:26 |
| 21 | + map@[native code] |
| 22 | + foo@http://192.168.20.143:5000/test:19:22 |
| 23 | + global code@http://192.168.20.143:5000/test:24:10`, |
| 24 | +}; |
| 25 | + |
| 26 | +const EDGE44_NATIVE_CODE_EXCEPTION = { |
| 27 | + stack: `Error: test |
| 28 | + at fooIterator (http://192.168.20.143:5000/test:20:11) |
| 29 | + at Array.prototype.map (native code) |
| 30 | + at foo (http://192.168.20.143:5000/test:19:9) |
| 31 | + at Global code (http://192.168.20.143:5000/test:24:7)`, |
| 32 | +}; |
| 33 | + |
| 34 | +describe('Tracekit', () => { |
| 35 | + describe('computeStackTrace', () => { |
| 36 | + it('no exception', () => { |
| 37 | + const stacktrace = _computeStackTrace._computeStackTraceFromStackProp(undefined); |
| 38 | + expect(stacktrace).equal(null); |
| 39 | + }); |
| 40 | + |
| 41 | + it('no stack', () => { |
| 42 | + const stacktrace = _computeStackTrace._computeStackTraceFromStackProp({}); |
| 43 | + expect(stacktrace).equal(null); |
| 44 | + }); |
| 45 | + |
| 46 | + it('chrome73', () => { |
| 47 | + const stacktrace = _computeStackTrace._computeStackTraceFromStackProp(CHROME73_NATIVE_CODE_EXCEPTION); |
| 48 | + |
| 49 | + expect(stacktrace.stack).deep.equal([ |
| 50 | + { |
| 51 | + args: [], |
| 52 | + column: 17, |
| 53 | + context: null, |
| 54 | + func: 'fooIterator', |
| 55 | + line: 20, |
| 56 | + url: 'http://192.168.20.143:5000/test', |
| 57 | + }, |
| 58 | + { |
| 59 | + args: [], |
| 60 | + column: null, |
| 61 | + context: null, |
| 62 | + func: 'Array.map', |
| 63 | + line: null, |
| 64 | + url: '<anonymous>', |
| 65 | + }, |
| 66 | + { |
| 67 | + args: [], |
| 68 | + column: 19, |
| 69 | + context: null, |
| 70 | + func: 'foo', |
| 71 | + line: 19, |
| 72 | + url: 'http://192.168.20.143:5000/test', |
| 73 | + }, |
| 74 | + { |
| 75 | + args: [], |
| 76 | + column: 7, |
| 77 | + context: null, |
| 78 | + func: '?', |
| 79 | + line: 24, |
| 80 | + url: 'http://192.168.20.143:5000/test', |
| 81 | + }, |
| 82 | + ]); |
| 83 | + }); |
| 84 | + |
| 85 | + it('firefox66', () => { |
| 86 | + const stacktrace = _computeStackTrace._computeStackTraceFromStackProp(FIREFOX66_NATIVE_CODE_EXCEPTION); |
| 87 | + |
| 88 | + expect(stacktrace.stack).deep.equal([ |
| 89 | + { |
| 90 | + args: [], |
| 91 | + column: 17, |
| 92 | + context: null, |
| 93 | + func: 'fooIterator', |
| 94 | + line: 20, |
| 95 | + url: 'http://192.168.20.143:5000/test', |
| 96 | + }, |
| 97 | + { |
| 98 | + args: [], |
| 99 | + column: 19, |
| 100 | + context: null, |
| 101 | + func: 'foo', |
| 102 | + line: 19, |
| 103 | + url: 'http://192.168.20.143:5000/test', |
| 104 | + }, |
| 105 | + { |
| 106 | + args: [], |
| 107 | + column: 7, |
| 108 | + context: null, |
| 109 | + func: '?', |
| 110 | + line: 24, |
| 111 | + url: 'http://192.168.20.143:5000/test', |
| 112 | + }, |
| 113 | + ]); |
| 114 | + }); |
| 115 | + |
| 116 | + it('safari12', () => { |
| 117 | + const stacktrace = _computeStackTrace._computeStackTraceFromStackProp(SAFARI12_NATIVE_CODE_EXCEPTION); |
| 118 | + |
| 119 | + expect(stacktrace.stack).deep.equal([ |
| 120 | + { |
| 121 | + args: [], |
| 122 | + column: 26, |
| 123 | + context: null, |
| 124 | + func: 'fooIterator', |
| 125 | + line: 20, |
| 126 | + url: 'http://192.168.20.143:5000/test', |
| 127 | + }, |
| 128 | + { |
| 129 | + args: [], |
| 130 | + column: null, |
| 131 | + context: null, |
| 132 | + func: 'map', |
| 133 | + line: null, |
| 134 | + url: '[native code]', |
| 135 | + }, |
| 136 | + { |
| 137 | + args: [], |
| 138 | + column: 22, |
| 139 | + context: null, |
| 140 | + func: 'foo', |
| 141 | + line: 19, |
| 142 | + url: 'http://192.168.20.143:5000/test', |
| 143 | + }, |
| 144 | + { |
| 145 | + args: [], |
| 146 | + column: 10, |
| 147 | + context: null, |
| 148 | + func: 'global code', |
| 149 | + line: 24, |
| 150 | + url: 'http://192.168.20.143:5000/test', |
| 151 | + }, |
| 152 | + ]); |
| 153 | + }); |
| 154 | + |
| 155 | + it('edge44', () => { |
| 156 | + const stacktrace = _computeStackTrace._computeStackTraceFromStackProp(EDGE44_NATIVE_CODE_EXCEPTION); |
| 157 | + |
| 158 | + expect(stacktrace.stack).deep.equal([ |
| 159 | + { |
| 160 | + args: [], |
| 161 | + column: 11, |
| 162 | + context: null, |
| 163 | + func: 'fooIterator', |
| 164 | + line: 20, |
| 165 | + url: 'http://192.168.20.143:5000/test', |
| 166 | + }, |
| 167 | + { |
| 168 | + args: [], |
| 169 | + column: null, |
| 170 | + context: null, |
| 171 | + func: 'Array.prototype.map', |
| 172 | + line: null, |
| 173 | + url: 'native code', |
| 174 | + }, |
| 175 | + { |
| 176 | + args: [], |
| 177 | + column: 9, |
| 178 | + context: null, |
| 179 | + func: 'foo', |
| 180 | + line: 19, |
| 181 | + url: 'http://192.168.20.143:5000/test', |
| 182 | + }, |
| 183 | + { |
| 184 | + args: [], |
| 185 | + column: 7, |
| 186 | + context: null, |
| 187 | + func: 'Global code', |
| 188 | + line: 24, |
| 189 | + url: 'http://192.168.20.143:5000/test', |
| 190 | + }, |
| 191 | + ]); |
| 192 | + }); |
| 193 | + }); |
| 194 | +}); |
0 commit comments