| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:package_resolver/package_resolver.dart'; | 5 import 'package:package_resolver/package_resolver.dart'; |
| 6 import 'package:path/path.dart' as p; |
| 6 import 'package:source_maps/source_maps.dart'; | 7 import 'package:source_maps/source_maps.dart'; |
| 7 import 'package:source_span/source_span.dart'; | 8 import 'package:source_span/source_span.dart'; |
| 8 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 9 import 'package:source_map_stack_trace/source_map_stack_trace.dart'; | 10 import 'package:source_map_stack_trace/source_map_stack_trace.dart'; |
| 10 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
| 11 | 12 |
| 12 /// A simple [Mapping] for tests that don't need anything special. | 13 /// A simple [Mapping] for tests that don't need anything special. |
| 13 final _simpleMapping = parseJson( | 14 final _simpleMapping = parseJson( |
| 14 (new SourceMapBuilder() | 15 (new SourceMapBuilder() |
| 15 ..addSpan( | 16 ..addSpan( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 foo.dart.js 10:11 baz | 56 foo.dart.js 10:11 baz |
| 56 """); | 57 """); |
| 57 | 58 |
| 58 var frames = _mapTrace(_simpleMapping, trace).frames; | 59 var frames = _mapTrace(_simpleMapping, trace).frames; |
| 59 | 60 |
| 60 expect(frames.length, equals(2)); | 61 expect(frames.length, equals(2)); |
| 61 expect(frames.first.member, equals("foo")); | 62 expect(frames.first.member, equals("foo")); |
| 62 expect(frames.last.member, equals("baz")); | 63 expect(frames.last.member, equals("baz")); |
| 63 }); | 64 }); |
| 64 | 65 |
| 66 test("include frames from JS files not covered by the source map bundle", |
| 67 () { |
| 68 var trace = new Trace.parse(""" |
| 69 foo.dart.js 10:11 foo |
| 70 jquery.js 10:1 foo |
| 71 bar.dart.js 10:11 foo |
| 72 """); |
| 73 var builder = new SourceMapBuilder() |
| 74 ..addSpan( |
| 75 new SourceMapSpan.identifier( |
| 76 new SourceLocation(1, |
| 77 line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"), |
| 78 "qux"), |
| 79 new SourceSpan(new SourceLocation(8, line: 5, column: 0), |
| 80 new SourceLocation(12, line: 9, column: 1), "\n" * 4)); |
| 81 var sourceMapJson1 = builder.build("foo.dart.js.map"); |
| 82 sourceMapJson1['file'] = "foo.dart.js"; |
| 83 |
| 84 builder = new SourceMapBuilder() |
| 85 ..addSpan( |
| 86 new SourceMapSpan.identifier( |
| 87 new SourceLocation(1, |
| 88 line: 1, column: 3, sourceUrl: "packages/bar/bar.dart"), |
| 89 "qux"), |
| 90 new SourceSpan(new SourceLocation(8, line: 5, column: 0), |
| 91 new SourceLocation(12, line: 9, column: 1), "\n" * 4)); |
| 92 var sourceMapJson2 = builder.build("bar.dart.js.map"); |
| 93 sourceMapJson2['file'] = "bar.dart.js"; |
| 94 |
| 95 var bundle = [sourceMapJson1, sourceMapJson2]; |
| 96 var mapping = parseJsonExtended(bundle); |
| 97 var frames = _mapTrace(mapping, trace, |
| 98 packageResolver: new SyncPackageResolver.root("packages/")) |
| 99 .frames; |
| 100 |
| 101 expect(frames.length, equals(3)); |
| 102 |
| 103 var frame = frames[0]; |
| 104 expect(frame.uri, equals(Uri.parse("package:foo/foo.dart"))); |
| 105 expect(frame.line, equals(2)); |
| 106 expect(frame.column, equals(4)); |
| 107 |
| 108 frame = frames[1]; |
| 109 expect(p.basename(frame.uri.toString()), equals("jquery.js")); |
| 110 expect(frame.line, equals(10)); |
| 111 |
| 112 frame = frames[2]; |
| 113 expect(frame.uri, equals(Uri.parse("package:bar/bar.dart"))); |
| 114 expect(frame.line, equals(2)); |
| 115 expect(frame.column, equals(4)); |
| 116 }); |
| 117 |
| 65 test("falls back to column 0 for unlisted column", () { | 118 test("falls back to column 0 for unlisted column", () { |
| 66 var trace = new Trace.parse("foo.dart.js 10 foo"); | 119 var trace = new Trace.parse("foo.dart.js 10 foo"); |
| 67 var builder = new SourceMapBuilder() | 120 var builder = new SourceMapBuilder() |
| 68 ..addSpan( | 121 ..addSpan( |
| 69 new SourceMapSpan.identifier( | 122 new SourceMapSpan.identifier( |
| 70 new SourceLocation(1, | 123 new SourceLocation(1, |
| 71 line: 1, column: 3, sourceUrl: "foo.dart"), | 124 line: 1, column: 3, sourceUrl: "foo.dart"), |
| 72 "qux"), | 125 "qux"), |
| 73 new SourceSpan( | 126 new SourceSpan( |
| 74 new SourceLocation(8, line: 5, column: 0), | 127 new SourceLocation(8, line: 5, column: 0), |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 return new Chain.forTrace(mapStackTrace(sourceMap, stackTrace, | 314 return new Chain.forTrace(mapStackTrace(sourceMap, stackTrace, |
| 262 minified: minified, packageResolver: packageResolver, sdkRoot: sdkRoot, | 315 minified: minified, packageResolver: packageResolver, sdkRoot: sdkRoot, |
| 263 packageRoot: packageRoot)); | 316 packageRoot: packageRoot)); |
| 264 } | 317 } |
| 265 | 318 |
| 266 /// Runs the mapper's prettification logic on [member] and returns the result. | 319 /// Runs the mapper's prettification logic on [member] and returns the result. |
| 267 String _prettify(String member) { | 320 String _prettify(String member) { |
| 268 var trace = new Trace([new Frame(Uri.parse("foo.dart.js"), 10, 11, member)]); | 321 var trace = new Trace([new Frame(Uri.parse("foo.dart.js"), 10, 11, member)]); |
| 269 return _mapTrace(_simpleMapping, trace).frames.first.member; | 322 return _mapTrace(_simpleMapping, trace).frames.first.member; |
| 270 } | 323 } |
| OLD | NEW |