From db0cb268d0d93e3a1a1548ee6e1c527d6505b1d0 Mon Sep 17 00:00:00 2001 From: felipe Date: Wed, 3 May 2017 22:46:34 +0200 Subject: [PATCH] Add tests for sourcemap support --- .../src/__tests__/Runtime-sourceMaps-test.js | 47 +++++++++++++++++++ .../sourcemaps/out/throwing-mapped-fn.js | 18 +++++++ .../sourcemaps/out/throwing-mapped-fn.js.map | 1 + .../sourcemaps/throwing-mapped-fn.js | 11 +++++ 4 files changed, 77 insertions(+) create mode 100644 packages/jest-runtime/src/__tests__/Runtime-sourceMaps-test.js create mode 100644 packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js create mode 100644 packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js.map create mode 100644 packages/jest-runtime/src/__tests__/test_root/sourcemaps/throwing-mapped-fn.js diff --git a/packages/jest-runtime/src/__tests__/Runtime-sourceMaps-test.js b/packages/jest-runtime/src/__tests__/Runtime-sourceMaps-test.js new file mode 100644 index 000000000000..55148cfc5a7b --- /dev/null +++ b/packages/jest-runtime/src/__tests__/Runtime-sourceMaps-test.js @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @emails oncall+jsinfra + */ +'use strict'; + +let createRuntime; + +describe('Runtime', () => { + beforeEach(() => { + createRuntime = require('createRuntime'); + }); + + describe('requireModule', () => { + it('installs source maps if available', () => + createRuntime(__filename).then(runtime => { + let hasThrown = false; + const sum = runtime.requireModule( + runtime.__mockRootPath, + './sourcemaps/out/throwing-mapped-fn.js', + ).sum; + + try { + sum(); + } catch (err) { + hasThrown = true; + /* eslint-disable max-len */ + if (process.platform === 'win32') { + expect(err.stack).toMatch( + /^Error: throwing fn\s+at sum.+\\__tests__\\test_root\\sourcemaps\\throwing-mapped-fn.js:10:9/, + ); + } else { + expect(err.stack).toMatch( + /^Error: throwing fn\s+at sum.+\/__tests__\/test_root\/sourcemaps\/throwing-mapped-fn.js:10:9/, + ); + } + /* eslint-enable max-len */ + } + expect(hasThrown).toBe(true); + })); + }); +}); diff --git a/packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js b/packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js new file mode 100644 index 000000000000..398191b191e3 --- /dev/null +++ b/packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js @@ -0,0 +1,18 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +exports.sum = sum; +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +function sum() { + throw new Error('throwing fn'); +} +//# sourceMappingURL=throwing-mapped-fn.js.map diff --git a/packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js.map b/packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js.map new file mode 100644 index 000000000000..2caa28803e83 --- /dev/null +++ b/packages/jest-runtime/src/__tests__/test_root/sourcemaps/out/throwing-mapped-fn.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../throwing-mapped-fn.js"],"names":["sum","Error"],"mappings":";;;;;QAQgBA,G,GAAAA,G;AARhB;;;;;;;;AAQO,SAASA,GAAT,GAAe;AACpB,QAAM,IAAIC,KAAJ,CAAU,aAAV,CAAN;AACD","file":"throwing-mapped-fn.js","sourcesContent":["/**\n * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nexport function sum() {\n throw new Error('throwing fn');\n};\n"]} \ No newline at end of file diff --git a/packages/jest-runtime/src/__tests__/test_root/sourcemaps/throwing-mapped-fn.js b/packages/jest-runtime/src/__tests__/test_root/sourcemaps/throwing-mapped-fn.js new file mode 100644 index 000000000000..bceeffafaf2d --- /dev/null +++ b/packages/jest-runtime/src/__tests__/test_root/sourcemaps/throwing-mapped-fn.js @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +export function sum() { + throw new Error('throwing fn'); +}