Index: test/source_map_stack_trace_test.dart |
diff --git a/test/source_map_stack_trace_test.dart b/test/source_map_stack_trace_test.dart |
index 64145a63de1b5dc310b60a294fc9b88f4a7e7866..029abc216d8eb508f9ab16bf954087823e7f9287 100644 |
--- a/test/source_map_stack_trace_test.dart |
+++ b/test/source_map_stack_trace_test.dart |
@@ -3,6 +3,7 @@ |
// BSD-style license that can be found in the LICENSE file. |
import 'package:package_resolver/package_resolver.dart'; |
+import 'package:path/path.dart' as path; |
nweiz
2016/12/08 23:34:31
as p
Jacob
2016/12/09 02:18:28
Done.
|
import 'package:source_maps/source_maps.dart'; |
import 'package:source_span/source_span.dart'; |
import 'package:stack_trace/stack_trace.dart'; |
@@ -10,18 +11,14 @@ import 'package:source_map_stack_trace/source_map_stack_trace.dart'; |
import 'package:test/test.dart'; |
/// A simple [Mapping] for tests that don't need anything special. |
-final _simpleMapping = parseJson( |
- (new SourceMapBuilder() |
- ..addSpan( |
- new SourceMapSpan.identifier( |
- new SourceLocation(1, |
- line: 1, column: 3, sourceUrl: "foo.dart"), |
- "qux"), |
- new SourceSpan( |
- new SourceLocation(8, line: 5, column: 0), |
- new SourceLocation(18, line: 15, column: 0), |
- "\n" * 10))) |
- .build("foo.dart.js.map")); |
+final _simpleMapping = parseJson((new SourceMapBuilder() |
+ ..addSpan( |
+ new SourceMapSpan.identifier( |
+ new SourceLocation(1, line: 1, column: 3, sourceUrl: "foo.dart"), |
+ "qux"), |
+ new SourceSpan(new SourceLocation(8, line: 5, column: 0), |
+ new SourceLocation(18, line: 15, column: 0), "\n" * 10))) |
+ .build("foo.dart.js.map")); |
void main() { |
test("maps a JS line and column to a Dart line and span", () { |
@@ -62,18 +59,64 @@ foo.dart.js 10:11 baz |
expect(frames.last.member, equals("baz")); |
}); |
+ test("shows JS frames without corresponding spans", () { |
nweiz
2016/12/08 23:34:31
Put these in a "with includeUnmappedFrames" group.
Jacob
2016/12/09 02:18:28
obsolete as all but one test doesn't matter given
|
+ var trace = new Trace.parse(""" |
+foo.dart.js 10:11 foo |
+foo.dart.js 1:1 bar |
+foo.dart.js 10:11 baz |
+"""); |
+ |
+ var frames = |
+ _mapTrace(_simpleMapping, trace, includeUnmappedFrames: true).frames; |
+ |
+ expect(frames.length, equals(3)); |
+ expect(frames.first.member, equals("foo")); |
+ expect(frames[1].member, equals("bar")); |
+ expect(frames.last.member, equals("baz")); |
+ |
+ expect(path.basename(frames.first.uri.toString()), equals("foo.dart")); |
+ expect(path.basename(frames[1].uri.toString()), equals("foo.dart.js")); |
+ }); |
+ |
+ test("ignore frames that do not match files in source map bundle", () { |
+ var trace = new Trace.parse(""" |
+foo.dart.js 10 foo |
+wrong_file.dart.js 10 foo |
+"""); |
+ var builder = new SourceMapBuilder() |
+ ..addSpan( |
+ new SourceMapSpan.identifier( |
+ new SourceLocation(1, |
+ line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"), |
+ "qux"), |
+ new SourceSpan(new SourceLocation(8, line: 5, column: 0), |
+ new SourceLocation(12, line: 9, column: 1), "\n" * 4)); |
+ var sourceMapJson = builder.build("foo.dart.js.map"); |
+ sourceMapJson['file'] = "foo.dart.js"; |
+ var bundle = [sourceMapJson]; |
+ var mapping = parseJsonExtended(bundle); |
+ var frames = _mapTrace(mapping, trace, |
+ packageRoot: "packages/", includeUnmappedFrames: true) |
nweiz
2016/12/08 23:34:31
packageRoot is deprecated; use packageResolver ins
Jacob
2016/12/09 02:18:28
Done.
|
+ .frames; |
+ expect(frames.length, equals(2)); |
+ var frame = frames.first; |
+ expect(frame.uri, equals(Uri.parse("package:foo/foo.dart"))); |
+ expect(frame.line, equals(2)); |
+ expect(frame.column, equals(4)); |
+ frame = frames.last; |
+ expect(path.basename(frame.uri.toString()), equals("wrong_file.dart.js")); |
+ expect(frame.line, equals(10)); |
nweiz
2016/12/08 23:34:31
Add some empty lines here, this is difficult to re
Jacob
2016/12/09 02:18:28
Done.
|
+ }); |
+ |
test("falls back to column 0 for unlisted column", () { |
var trace = new Trace.parse("foo.dart.js 10 foo"); |
var builder = new SourceMapBuilder() |
- ..addSpan( |
- new SourceMapSpan.identifier( |
- new SourceLocation(1, |
- line: 1, column: 3, sourceUrl: "foo.dart"), |
- "qux"), |
- new SourceSpan( |
- new SourceLocation(8, line: 5, column: 0), |
- new SourceLocation(12, line: 9, column: 1), |
- "\n" * 4)); |
+ ..addSpan( |
+ new SourceMapSpan.identifier( |
+ new SourceLocation(1, line: 1, column: 3, sourceUrl: "foo.dart"), |
+ "qux"), |
+ new SourceSpan(new SourceLocation(8, line: 5, column: 0), |
+ new SourceLocation(12, line: 9, column: 1), "\n" * 4)); |
var mapping = parseJson(builder.build("foo.dart.js.map")); |
var frame = _mapTrace(mapping, trace).frames.first; |
@@ -85,19 +128,17 @@ foo.dart.js 10:11 baz |
test("uses package: URIs for frames within packageRoot", () { |
var trace = new Trace.parse("foo.dart.js 10 foo"); |
var builder = new SourceMapBuilder() |
- ..addSpan( |
- new SourceMapSpan.identifier( |
- new SourceLocation(1, |
- line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"), |
- "qux"), |
- new SourceSpan( |
- new SourceLocation(8, line: 5, column: 0), |
- new SourceLocation(12, line: 9, column: 1), |
- "\n" * 4)); |
+ ..addSpan( |
+ new SourceMapSpan.identifier( |
+ new SourceLocation(1, |
+ line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"), |
+ "qux"), |
+ new SourceSpan(new SourceLocation(8, line: 5, column: 0), |
+ new SourceLocation(12, line: 9, column: 1), "\n" * 4)); |
var mapping = parseJson(builder.build("foo.dart.js.map")); |
- var frame = _mapTrace(mapping, trace, packageRoot: "packages/") |
- .frames.first; |
+ var frame = |
+ _mapTrace(mapping, trace, packageRoot: "packages/").frames.first; |
expect(frame.uri, equals(Uri.parse("package:foo/foo.dart"))); |
expect(frame.line, equals(2)); |
expect(frame.column, equals(4)); |
@@ -106,15 +147,13 @@ foo.dart.js 10:11 baz |
test("uses package: URIs for frames within packageResolver.packageRoot", () { |
var trace = new Trace.parse("foo.dart.js 10 foo"); |
var builder = new SourceMapBuilder() |
- ..addSpan( |
- new SourceMapSpan.identifier( |
- new SourceLocation(1, |
- line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"), |
- "qux"), |
- new SourceSpan( |
- new SourceLocation(8, line: 5, column: 0), |
- new SourceLocation(12, line: 9, column: 1), |
- "\n" * 4)); |
+ ..addSpan( |
+ new SourceMapSpan.identifier( |
+ new SourceLocation(1, |
+ line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"), |
+ "qux"), |
+ new SourceSpan(new SourceLocation(8, line: 5, column: 0), |
+ new SourceLocation(12, line: 9, column: 1), "\n" * 4)); |
var mapping = parseJson(builder.build("foo.dart.js.map")); |
var mappedTrace = _mapTrace(mapping, trace, |
@@ -129,21 +168,18 @@ foo.dart.js 10:11 baz |
() { |
var trace = new Trace.parse("foo.dart.js 10 foo"); |
var builder = new SourceMapBuilder() |
- ..addSpan( |
- new SourceMapSpan.identifier( |
- new SourceLocation(1, |
- line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"), |
- "qux"), |
- new SourceSpan( |
- new SourceLocation(8, line: 5, column: 0), |
- new SourceLocation(12, line: 9, column: 1), |
- "\n" * 4)); |
+ ..addSpan( |
+ new SourceMapSpan.identifier( |
+ new SourceLocation(1, |
+ line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"), |
+ "qux"), |
+ new SourceSpan(new SourceLocation(8, line: 5, column: 0), |
+ new SourceLocation(12, line: 9, column: 1), "\n" * 4)); |
var mapping = parseJson(builder.build("foo.dart.js.map")); |
var mappedTrace = _mapTrace(mapping, trace, |
- packageResolver: new SyncPackageResolver.config({ |
- "foo": Uri.parse("packages/foo") |
- })); |
+ packageResolver: |
+ new SyncPackageResolver.config({"foo": Uri.parse("packages/foo")})); |
var frame = mappedTrace.frames.first; |
expect(frame.uri, equals(Uri.parse("package:foo/foo.dart"))); |
expect(frame.line, equals(2)); |
@@ -153,15 +189,13 @@ foo.dart.js 10:11 baz |
test("uses dart: URIs for frames within sdkRoot", () { |
var trace = new Trace.parse("foo.dart.js 10 foo"); |
var builder = new SourceMapBuilder() |
- ..addSpan( |
- new SourceMapSpan.identifier( |
- new SourceLocation(1, |
- line: 1, column: 3, sourceUrl: "sdk/lib/async/foo.dart"), |
- "qux"), |
- new SourceSpan( |
- new SourceLocation(8, line: 5, column: 0), |
- new SourceLocation(12, line: 9, column: 1), |
- "\n" * 4)); |
+ ..addSpan( |
+ new SourceMapSpan.identifier( |
+ new SourceLocation(1, |
+ line: 1, column: 3, sourceUrl: "sdk/lib/async/foo.dart"), |
+ "qux"), |
+ new SourceSpan(new SourceLocation(8, line: 5, column: 0), |
+ new SourceLocation(12, line: 9, column: 1), "\n" * 4)); |
var mapping = parseJson(builder.build("foo.dart.js.map")); |
var frame = _mapTrace(mapping, trace, sdkRoot: "sdk/").frames.first; |
@@ -212,8 +246,8 @@ foo.dart.js 10:11 baz |
test("nested closures", () { |
expect(_prettify("foo__closure.call"), equals("foo.<fn>.<fn>")); |
- expect(_prettify("foo____closure.call"), |
- equals("foo.<fn>.<fn>.<fn>.<fn>")); |
+ expect( |
+ _prettify("foo____closure.call"), equals("foo.<fn>.<fn>.<fn>.<fn>")); |
}); |
test(".call", () { |
@@ -246,21 +280,33 @@ foo.dart.js 10:11 baz |
/// Like [mapStackTrace], but is guaranteed to return a [Trace] so it can be |
/// inspected. |
Trace _mapTrace(Mapping sourceMap, StackTrace stackTrace, |
- {bool minified: false, SyncPackageResolver packageResolver, sdkRoot, |
- packageRoot}) { |
+ {bool minified: false, |
+ SyncPackageResolver packageResolver, |
+ sdkRoot, |
+ packageRoot, |
+ bool includeUnmappedFrames: false}) { |
return new Trace.from(mapStackTrace(sourceMap, stackTrace, |
- minified: minified, packageResolver: packageResolver, sdkRoot: sdkRoot, |
- packageRoot: packageRoot)); |
+ minified: minified, |
+ packageResolver: packageResolver, |
+ sdkRoot: sdkRoot, |
+ packageRoot: packageRoot, |
+ includeUnmappedFrames: includeUnmappedFrames)); |
} |
/// Like [mapStackTrace], but is guaranteed to return a [Chain] so it can be |
/// inspected. |
Chain _mapChain(Mapping sourceMap, StackTrace stackTrace, |
- {bool minified: false, SyncPackageResolver packageResolver, sdkRoot, |
- packageRoot}) { |
+ {bool minified: false, |
+ SyncPackageResolver packageResolver, |
+ sdkRoot, |
+ packageRoot, |
+ bool includeUnmappedFrames: false}) { |
return new Chain.forTrace(mapStackTrace(sourceMap, stackTrace, |
- minified: minified, packageResolver: packageResolver, sdkRoot: sdkRoot, |
- packageRoot: packageRoot)); |
+ minified: minified, |
+ packageResolver: packageResolver, |
+ sdkRoot: sdkRoot, |
+ packageRoot: packageRoot, |
+ includeUnmappedFrames: includeUnmappedFrames)); |
} |
/// Runs the mapper's prettification logic on [member] and returns the result. |