-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcemaps #3458
Sourcemaps #3458
Changes from 6 commits
2ab8f14
69df22b
fffc59b
bc671c7
3cdcecd
85f4bcf
35e4743
08e6a0f
c51cf2c
4269625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import type {TestResult} from 'types/TestResult'; | |
import type Runtime from 'jest-runtime'; | ||
|
||
import path from 'path'; | ||
import fs from 'fs'; | ||
import JasmineReporter from './reporter'; | ||
import {install as jasmineAsyncInstall} from './jasmine_async'; | ||
|
||
|
@@ -93,6 +94,25 @@ async function jasmine2( | |
runtime.requireModule(config.setupTestFrameworkScriptFile); | ||
} | ||
|
||
runtime | ||
.requireModule(require.resolve('source-map-support'), 'source-map-support') | ||
.install({ | ||
handleUncaughtExceptions: false, | ||
retrieveSourceMap: source => { | ||
if (runtime._sourceMapRegistry[source]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think accessing a private field of runtime should be done here :) |
||
try { | ||
return { | ||
map: JSON.parse( | ||
fs.readFileSync(runtime._sourceMapRegistry[source]), | ||
), | ||
url: source, | ||
}; | ||
} catch (e) {} | ||
} | ||
return null; | ||
}, | ||
}); | ||
|
||
if (globalConfig.testNamePattern) { | ||
const testNameRegex = new RegExp(globalConfig.testNamePattern, 'i'); | ||
env.specFilter = spec => testNameRegex.test(spec.getFullName()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
})); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this here? Shouldn't it be a dependency of
jest-jasmine2
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I just moved it there