Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: test/source_map_stack_trace_test.dart

Issue 2168203002: Use the package_resolver package. (Closed) Base URL: git@github.com:dart-lang/source_map_stack_trace.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:source_maps/source_maps.dart'; 6 import 'package:source_maps/source_maps.dart';
6 import 'package:source_span/source_span.dart'; 7 import 'package:source_span/source_span.dart';
7 import 'package:stack_trace/stack_trace.dart'; 8 import 'package:stack_trace/stack_trace.dart';
8 import 'package:source_map_stack_trace/source_map_stack_trace.dart'; 9 import 'package:source_map_stack_trace/source_map_stack_trace.dart';
9 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
10 11
11 /// A simple [Mapping] for tests that don't need anything special. 12 /// A simple [Mapping] for tests that don't need anything special.
12 final _simpleMapping = parseJson( 13 final _simpleMapping = parseJson(
13 (new SourceMapBuilder() 14 (new SourceMapBuilder()
14 ..addSpan( 15 ..addSpan(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 "\n" * 4)); 96 "\n" * 4));
96 97
97 var mapping = parseJson(builder.build("foo.dart.js.map")); 98 var mapping = parseJson(builder.build("foo.dart.js.map"));
98 var frame = _mapTrace(mapping, trace, packageRoot: "packages/") 99 var frame = _mapTrace(mapping, trace, packageRoot: "packages/")
99 .frames.first; 100 .frames.first;
100 expect(frame.uri, equals(Uri.parse("package:foo/foo.dart"))); 101 expect(frame.uri, equals(Uri.parse("package:foo/foo.dart")));
101 expect(frame.line, equals(2)); 102 expect(frame.line, equals(2));
102 expect(frame.column, equals(4)); 103 expect(frame.column, equals(4));
103 }); 104 });
104 105
106 test("uses package: URIs for frames within packageResolver.packageRoot", () {
107 var trace = new Trace.parse("foo.dart.js 10 foo");
108 var builder = new SourceMapBuilder()
109 ..addSpan(
110 new SourceMapSpan.identifier(
111 new SourceLocation(1,
112 line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"),
113 "qux"),
114 new SourceSpan(
115 new SourceLocation(8, line: 5, column: 0),
116 new SourceLocation(12, line: 9, column: 1),
117 "\n" * 4));
118
119 var mapping = parseJson(builder.build("foo.dart.js.map"));
120 var mappedTrace = _mapTrace(mapping, trace,
121 packageResolver: new SyncPackageResolver.root("packages/"));
122 var frame = mappedTrace.frames.first;
123 expect(frame.uri, equals(Uri.parse("package:foo/foo.dart")));
124 expect(frame.line, equals(2));
125 expect(frame.column, equals(4));
126 });
127
128 test("uses package: URIs for frames within a packageResolver.packageMap URL",
129 () {
130 var trace = new Trace.parse("foo.dart.js 10 foo");
131 var builder = new SourceMapBuilder()
132 ..addSpan(
133 new SourceMapSpan.identifier(
134 new SourceLocation(1,
135 line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"),
136 "qux"),
137 new SourceSpan(
138 new SourceLocation(8, line: 5, column: 0),
139 new SourceLocation(12, line: 9, column: 1),
140 "\n" * 4));
141
142 var mapping = parseJson(builder.build("foo.dart.js.map"));
143 var mappedTrace = _mapTrace(mapping, trace,
144 packageResolver: new SyncPackageResolver.config({
145 "foo": Uri.parse("packages/foo")
146 }));
147 var frame = mappedTrace.frames.first;
148 expect(frame.uri, equals(Uri.parse("package:foo/foo.dart")));
149 expect(frame.line, equals(2));
150 expect(frame.column, equals(4));
151 });
152
105 test("uses dart: URIs for frames within sdkRoot", () { 153 test("uses dart: URIs for frames within sdkRoot", () {
106 var trace = new Trace.parse("foo.dart.js 10 foo"); 154 var trace = new Trace.parse("foo.dart.js 10 foo");
107 var builder = new SourceMapBuilder() 155 var builder = new SourceMapBuilder()
108 ..addSpan( 156 ..addSpan(
109 new SourceMapSpan.identifier( 157 new SourceMapSpan.identifier(
110 new SourceLocation(1, 158 new SourceLocation(1,
111 line: 1, column: 3, sourceUrl: "sdk/lib/async/foo.dart"), 159 line: 1, column: 3, sourceUrl: "sdk/lib/async/foo.dart"),
112 "qux"), 160 "qux"),
113 new SourceSpan( 161 new SourceSpan(
114 new SourceLocation(8, line: 5, column: 0), 162 new SourceLocation(8, line: 5, column: 0),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 test("lots of stuff", () { 239 test("lots of stuff", () {
192 expect(_prettify(r"lib$Foo.static.lib$Foo_closure.call$0/<"), 240 expect(_prettify(r"lib$Foo.static.lib$Foo_closure.call$0/<"),
193 equals("Foo.<fn>")); 241 equals("Foo.<fn>"));
194 }); 242 });
195 }); 243 });
196 } 244 }
197 245
198 /// Like [mapStackTrace], but is guaranteed to return a [Trace] so it can be 246 /// Like [mapStackTrace], but is guaranteed to return a [Trace] so it can be
199 /// inspected. 247 /// inspected.
200 Trace _mapTrace(Mapping sourceMap, StackTrace stackTrace, 248 Trace _mapTrace(Mapping sourceMap, StackTrace stackTrace,
201 {bool minified: false, packageRoot, sdkRoot}) { 249 {bool minified: false, SyncPackageResolver packageResolver, sdkRoot,
250 packageRoot}) {
202 return new Trace.from(mapStackTrace(sourceMap, stackTrace, 251 return new Trace.from(mapStackTrace(sourceMap, stackTrace,
203 minified: minified, packageRoot: packageRoot, sdkRoot: sdkRoot)); 252 minified: minified, packageResolver: packageResolver, sdkRoot: sdkRoot,
253 packageRoot: packageRoot));
204 } 254 }
205 255
206 /// Like [mapStackTrace], but is guaranteed to return a [Chain] so it can be 256 /// Like [mapStackTrace], but is guaranteed to return a [Chain] so it can be
207 /// inspected. 257 /// inspected.
208 Chain _mapChain(Mapping sourceMap, StackTrace stackTrace, 258 Chain _mapChain(Mapping sourceMap, StackTrace stackTrace,
209 {bool minified: false, packageRoot, sdkRoot}) { 259 {bool minified: false, SyncPackageResolver packageResolver, sdkRoot,
260 packageRoot}) {
210 return new Chain.forTrace(mapStackTrace(sourceMap, stackTrace, 261 return new Chain.forTrace(mapStackTrace(sourceMap, stackTrace,
211 minified: minified, packageRoot: packageRoot, sdkRoot: sdkRoot)); 262 minified: minified, packageResolver: packageResolver, sdkRoot: sdkRoot,
263 packageRoot: packageRoot));
212 } 264 }
213 265
214 /// Runs the mapper's prettification logic on [member] and returns the result. 266 /// Runs the mapper's prettification logic on [member] and returns the result.
215 String _prettify(String member) { 267 String _prettify(String member) {
216 var trace = new Trace([new Frame(Uri.parse("foo.dart.js"), 10, 11, member)]); 268 var trace = new Trace([new Frame(Uri.parse("foo.dart.js"), 10, 11, member)]);
217 return _mapTrace(_simpleMapping, trace).frames.first.member; 269 return _mapTrace(_simpleMapping, trace).frames.first.member;
218 } 270 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698