Skip to content

Commit ee757f9

Browse files
committed
Add tests for sourcemap support
1 parent 494b252 commit ee757f9

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*
8+
* @emails oncall+jsinfra
9+
*/
10+
'use strict';
11+
12+
let createRuntime;
13+
14+
describe('Runtime', () => {
15+
beforeEach(() => {
16+
createRuntime = require('createRuntime');
17+
});
18+
19+
describe('requireModule', () => {
20+
it('installs source maps if available', () =>
21+
createRuntime(__filename).then(runtime => {
22+
let hasThrown = false;
23+
const sum = runtime.requireModule(
24+
runtime.__mockRootPath,
25+
'./sourcemaps/out/throwing-mapped-fn.js',
26+
).sum;
27+
28+
try {
29+
sum();
30+
} catch (err) {
31+
hasThrown = true;
32+
/* eslint-disable max-len */
33+
if (process.platform === 'win32') {
34+
expect(err.stack).toMatch(
35+
/^Error: throwing fn\s+at sum.+\\__tests__\\test_root\\sourcemaps\\throwing-mapped-fn.js:10:9/,
36+
);
37+
} else {
38+
expect(err.stack).toMatch(
39+
/^Error: throwing fn\s+at sum.+\/__tests__\/test_root\/sourcemaps\/throwing-mapped-fn.js:10:9/,
40+
);
41+
}
42+
/* eslint-enable max-len */
43+
}
44+
expect(hasThrown).toBe(true);
45+
}));
46+
});
47+
});

packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*/
8+
9+
export function sum() {
10+
throw new Error('throwing fn');
11+
}

0 commit comments

Comments
 (0)