angular-docs-cn/modules/examples/e2e_test/sourcemap/sourcemap_spec.es6

52 lines
1.7 KiB
Plaintext
Raw Normal View History

2015-02-11 17:54:59 -05:00
var fs = require('fs');
var sourceMap = require('source-map');
describe('sourcemaps', function () {
var URL = 'examples/src/sourcemap/index.html';
it('should map sources', function() {
browser.get(URL);
$('error-app .errorButton').click();
2015-02-11 17:54:59 -05:00
// TODO(tbosch): Bug in ChromeDriver: Need to execute at least one command
// so that the browser logs can be read out!
browser.executeScript('1+1');
browser.manage().logs().get('browser').then(function(logs) {
var errorLine = null;
var errorColumn = null;
logs.forEach(function(log) {
var match = /\.createError\s+\(.+:(\d+):(\d+)/m.exec(log.message);
2015-02-11 17:54:59 -05:00
if (match) {
errorLine = parseInt(match[1]);
errorColumn = parseInt(match[2]);
}
});
expect(errorLine).not.toBeNull();
expect(errorColumn).not.toBeNull();
2015-02-11 17:54:59 -05:00
var sourceMapData = fs.readFileSync(
'dist/js/prod/es5/examples/src/sourcemap/index.js.map');
var decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));
var originalPosition = decoder.originalPositionFor({
line: errorLine,
column: errorColumn
});
var finalMapData = fs.readFileSync(
'dist/js/prod/es6/examples/src/sourcemap/index.es6.map');
var finalDecoder = new sourceMap.SourceMapConsumer(JSON.parse(finalMapData));
var finalPosition = finalDecoder.originalPositionFor(originalPosition);
var sourceCodeLines = fs.readFileSync('modules/examples/src/sourcemap/index.ts',
2015-02-11 17:54:59 -05:00
{encoding: 'UTF-8'}).split('\n');
expect(sourceCodeLines[finalPosition.line - 1])
2015-02-11 17:54:59 -05:00
.toMatch(/throw new BaseException\(\'Sourcemap test\'\)/);
});
});
});