Skip to content

Commit 234e1ec

Browse files
committed
chore(sourcemaps): add e2e test
1 parent 013e1fa commit 234e1ec

7 files changed

Lines changed: 87 additions & 5 deletions

File tree

modules/angular2/src/facade/lang.es6

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,9 @@ export function assertionsEnabled():boolean {
243243
}
244244

245245
export function print(obj) {
246-
console.log(obj);
246+
if (obj instanceof Error) {
247+
console.log(obj.stack);
248+
} else {
249+
console.log(obj);
250+
}
247251
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var fs = require('fs');
2+
var sourceMap = require('source-map');
3+
4+
describe('sourcemaps', function () {
5+
var URL = 'examples/src/sourcemap/index.html';
6+
7+
it('should map sources', function() {
8+
browser.get(URL);
9+
// TODO(tbosch): Bug in ChromeDriver: Need to execute at least one command
10+
// so that the browser logs can be read out!
11+
browser.executeScript('1+1');
12+
browser.manage().logs().get('browser').then(function(logs) {
13+
var errorLine = null;
14+
var errorColumn = null;
15+
logs.forEach(function(log) {
16+
var match = /Test\.run\s+\(.+:(\d+):(\d+)/m.exec(log.message);
17+
if (match) {
18+
errorLine = parseInt(match[1]);
19+
errorColumn = parseInt(match[2]);
20+
}
21+
});
22+
23+
expect(errorLine).not.toBeNull();
24+
expect(errorColumn).not.toBeNull();
25+
26+
var sourceMapData = fs.readFileSync(
27+
'dist/js/prod/es5/examples/src/sourcemap/index.js.map');
28+
var decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));
29+
30+
var originalPosition = decoder.originalPositionFor({
31+
line: errorLine,
32+
column: errorColumn
33+
});
34+
35+
var sourceCodeLines = fs.readFileSync('modules/examples/src/sourcemap/index.js',
36+
{encoding: 'UTF-8'}).split('\n');
37+
expect(sourceCodeLines[originalPosition.line - 1])
38+
.toMatch(/throw new BaseException\(\'Sourcemap test\'\)/);
39+
});
40+
});
41+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<title>Sourcemaps</title>
4+
<body>
5+
Please look into the console and check whether the stack trace is mapped
6+
via source maps!
7+
$SCRIPTS$
8+
</body>
9+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { BaseException, print, CONST } from 'angular2/src/facade/lang';
2+
3+
class TestAnnotation {
4+
@CONST()
5+
constructor() {}
6+
}
7+
8+
// Use a class with an annotation,
9+
// as this is where we expect the most source code changes
10+
// through compilation.
11+
@TestAnnotation()
12+
class Test {
13+
run() {
14+
try {
15+
throw new BaseException('Sourcemap test');
16+
} catch (e) {
17+
print(e);
18+
}
19+
}
20+
}
21+
22+
export function main() {
23+
new Test().run();
24+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"protractor": "1.6.x",
6565
"q": "^1.0.1",
6666
"run-sequence": "^0.3.6",
67+
"source-map": "^0.3.0",
6768
"sprintf-js": "1.0.*",
6869
"through2": "^0.6.1",
6970
"yargs": "2.3.*"

protractor-e2e-dart2js.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ config.baseUrl = 'http://localhost:8002/';
33
// TODO: remove this line when largetable dart has been added
44
config.exclude = config.exclude || [];
55
config.exclude.push('dist/js/cjs/benchmarks_external/e2e_test/largetable_spec.js');
6-
6+
config.exclude.push('dist/js/cjs/examples/e2e_test/sourcemap/sourcemap_spec.js');

protractor-shared.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ var POSSIBLE_CAPS = {
3535
'args': ['--js-flags=--expose-gc']
3636
},
3737
loggingPrefs: {
38-
performance: 'ALL'
38+
performance: 'ALL',
39+
browser: 'ALL'
3940
}
4041
},
4142
ChromeDesktop: {
@@ -44,7 +45,8 @@ var POSSIBLE_CAPS = {
4445
'args': ['--js-flags=--expose-gc']
4546
},
4647
loggingPrefs: {
47-
performance: 'ALL'
48+
performance: 'ALL',
49+
browser: 'ALL'
4850
}
4951
},
5052
ChromeAndroid: {
@@ -54,7 +56,8 @@ var POSSIBLE_CAPS = {
5456
'args': ['--js-flags=--expose-gc']
5557
},
5658
loggingPrefs: {
57-
performance: 'ALL'
59+
performance: 'ALL',
60+
browser: 'ALL'
5861
}
5962
}
6063
};

0 commit comments

Comments
 (0)