Skip to content

Commit

Permalink
test(terser): sourcemap test
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Sep 25, 2019
1 parent a438a1e commit 4592fbe
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/terser/test/sourcemap/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test")
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified")

terser_minified(
name = "case1",
src = "src1.js",
)

jasmine_node_test(
name = "test",
srcs = [
"terser_spec.js",
],
data = ["@npm//source-map"],
deps = [
":case1",
],
)
10 changes: 10 additions & 0 deletions packages/terser/test/sourcemap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The src1.js{,.map} files were generated from running `tsc` on src1.ts containing:

```
export class MyClass {
constructor(s: string) {
console.log(s);
}
field: string|undefined;
}
```
10 changes: 10 additions & 0 deletions packages/terser/test/sourcemap/src1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/terser/test/sourcemap/src1.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions packages/terser/test/sourcemap/terser_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs');
const sm = require('source-map');
const DIR = 'build_bazel_rules_nodejs/packages/terser/test/sourcemap';

describe('terser sourcemap handling', () => {
it('should produce a sourcemap output', async () => {
const file = require.resolve(DIR + '/case1.js.map');
const rawSourceMap = JSON.parse(fs.readFileSync(file, 'utf-8'));
await sm.SourceMapConsumer.with(rawSourceMap, null, consumer => {
const pos = consumer.originalPositionFor({
// FIXME: this data doesn't seem right. src1.js doesn't have this on line 1
line: 1,
column: 17
});
expect(pos.name).toBe('MyClass');
});
});
});

0 comments on commit 4592fbe

Please sign in to comment.