-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
[WIP] Remove usage of retainLines
#5594
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
Conversation
packages/jest-jasmine2/src/index.js
Outdated
|
|
||
| const JASMINE = require.resolve('./jasmine/jasmine_light.js'); | ||
|
|
||
| // Copied from https://github.com/rexxars/sourcemap-decorate-callsites/blob/5b9735a156964973a75dc62fd2c7f0c1975458e8/lib/index.js#L113-L158 |
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.
@rexxars thoughts on exporting extendCallsite from sourcemap-decorate-callsites?
I wanted to use your module directly, but I don't want the searching for sourcemaps - I have it already. I also need this to be sync
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.
Or just expose an API where I can pass ina callsite and a sourcemap, that would be even better (as long as it's sync) 🙂
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.
I'd welcome the change, but I'm absolutely swamped with work - be happy if anyone would submit a PR, though.
packages/jest-jasmine2/package.json
Outdated
| "jest-matcher-utils": "^22.2.0", | ||
| "jest-message-util": "^22.2.0", | ||
| "jest-snapshot": "^22.2.0", | ||
| "source-map": "^0.6.0", |
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.
newest is 0.7.1, but they changed their API to be asynchronous, so we can't use it
| message: LogMessage, | ||
| level: ?number, | ||
| ) { | ||
| // TODO: This callsite needs to read sourcemaps |
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.
The issue is here: https://github.com/facebook/jest/blob/430aebe49e9f144d29f144f5a29482315e269e4a/packages/jest-runner/src/run_test.js#L86-L108
I need to pass in runtime to the console, but environment requires testConsole and the runtime requires environment
packages/jest-runtime/src/index.js
Outdated
| const sourceMap = this._sourceMapRegistry[filename]; | ||
|
|
||
| if (sourceMap && fs.existsSync(sourceMap)) { | ||
| return fs.readFileSync(sourceMap, 'utf8'); |
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.
I wonder if we should cache these instead of hitting the disk every time
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.
can try-catch instead of 2 fs operations, at least
| } | ||
| at ../../packages/expect/build/index.js:145:57 | ||
| at ../../packages/expect/build/index.js:104:76 |
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.
we should probably remove this line entirely
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.
Feel free to remove the lilne:column mapping in a followup
Codecov Report
@@ Coverage Diff @@
## master #5594 +/- ##
==========================================
+ Coverage 60.94% 62.28% +1.34%
==========================================
Files 215 216 +1
Lines 7335 7898 +563
Branches 3 4 +1
==========================================
+ Hits 4470 4919 +449
- Misses 2864 2978 +114
Partials 1 1
Continue to review full report at Codecov.
|
|
|
||
| // Copied from https://github.com/rexxars/sourcemap-decorate-callsites/blob/5b9735a156964973a75dc62fd2c7f0c1975458e8/lib/index.js#L113-L158 | ||
| const addSourceMapConsumer = (callsite, consumer) => { | ||
| try { |
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.
this try can be removed, it's within another try
|
|
||
| return stack; | ||
| } catch (e) { | ||
| return null; |
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.
it should return stack at the end either way
| export default (level: number, sourceMaps: SourceMapRegistry) => { | ||
| const levelAfterThisCall = level + 1; | ||
| const stack = callsites()[levelAfterThisCall]; | ||
| const sourceMapFileName = sourceMaps && sourceMaps[stack.getFileName()]; |
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.
Either add a ? to the type declaration, or drop the sourceMaps && part
| !!globalConfig.verbose, | ||
| // 4 = the console call is buried 4 stack frames deep | ||
| BufferedConsole.write([], type, message, 4), | ||
| BufferedConsole.write( |
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.
oh, I didn't know this was the way it's hooked up. practical!
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.
We should probably pass it to the BufferedConsole as well
packages/jest-jasmine2/src/index.js
Outdated
| handleUncaughtExceptions: false, | ||
| retrieveSourceMap: source => { | ||
| if (runtime._sourceMapRegistry[source]) { | ||
| const sourceMap = runtime.getSourceMapForFile(source); |
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.
should probably use runtime.getSourceMaps() here as well and remove getSourceMapForFile
| try { | ||
| if (sourceMapFileName) { | ||
| const sourceMap = fs.readFileSync(sourceMapFileName, 'utf8'); | ||
| if (sourceMap) { |
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.
is this needed? readFileSync will just throw
packages/jest-runner/src/run_test.js
Outdated
| } else if (globalConfig.verbose) { | ||
| testConsole = new Console(consoleOut, process.stderr, consoleFormatter); | ||
| } else { | ||
| // TODO: Should `BufferedConsole` receive `consoleFormatter` as well? |
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.
@rickhanlonii I think so - the internal _log call in BufferedConsole is without sourcemaps now
| } | ||
| at ../../packages/expect/build/index.js:145:57 | ||
| at ../../packages/expect/build/index.js:104:76 |
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.
Feel free to remove the lilne:column mapping in a followup
CHANGELOG.md
Outdated
| ([#5560](https://github.com/facebook/jest/pull/5560)) | ||
| * `[jest-config]` Make it possible to merge `transform` option with preset | ||
| ([#5505](https://github.com/facebook/jest/pull/5505)) | ||
| * `[babel-jest]` Remove `retainLines` argument to babel. |
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.
"...from babel", or just "Remove usage of retainLines"
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.
My thinking was that people would go "what's retainLines, I've never passed that to jest before"
| testConsole = new Console(consoleOut, process.stderr, consoleFormatter); | ||
| } else { | ||
| testConsole = new BufferedConsole(); | ||
| testConsole = new BufferedConsole(() => runtime && runtime.getSourceMaps()); |
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.
went with a getter as consoleFormatter seemed like it did too much
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.
looks great
fwiw i don't think there's an integration test for this path
| @@ -0,0 +1,64 @@ | |||
| /** | |||
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.
@rickhanlonii would you mind adding a couple of unit tests to this?
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.
Yeah, will do
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.
Done
|
|
||
| describe('getCallsite', () => { | ||
| beforeEach(() => { | ||
| fs.readFileSync = jest.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.
When you do jest.mock without a factory, all exports are mocks by default. So this beforeEach shouldn't be necessary
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 can do jest.clearMocks if needed
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.
The test also fails CI?
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.
Fixed, not sure what I was thinking
# Conflicts: # packages/jest-jasmine2/package.json # packages/jest-util/package.json
8347bb5 to
736eb2b
Compare
|
@cpojer This is ready except for the comments here: https://github.com/facebook/jest/pull/5594/files#r168943134 Thoughts? |
|
This is really good work. I like how it actually simplifies things in Jest and makes it more correct. The one offset that's wrong is fine for now, let's just make sure this is properly reported in the right repo and eventually fixed upstream :) |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Pushing up what I've got for now. Tests are failing becausecallsitesdoes not look up sourcemaps. I've added aTODOin the code where the cause of the failing tests are.Only outstanding issue is with columns after looking up a sourcemap. See #5594 (comment). Help appreciated!
Fixes #5326.
Test plan
Old tests should pass, even with no
retainLines