|
3 | 3 | // BSD-style license that can be found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | import 'package:package_resolver/package_resolver.dart';
|
| 6 | +import 'package:path/path.dart' as p; |
6 | 7 | import 'package:source_maps/source_maps.dart';
|
7 | 8 | import 'package:source_span/source_span.dart';
|
8 | 9 | import 'package:stack_trace/stack_trace.dart';
|
@@ -62,6 +63,58 @@ foo.dart.js 10:11 baz
|
62 | 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 | 118 | test("falls back to column 0 for unlisted column", () {
|
66 | 119 | var trace = new Trace.parse("foo.dart.js 10 foo");
|
67 | 120 | var builder = new SourceMapBuilder()
|
|
0 commit comments