-
-
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
[WIP] Remove usage of retainLines
#5594
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2b8e256
Remove usage of `retainLines`
SimenB 0c1dd5c
update changelog
SimenB 8f9e54f
Move callsite to jest-util, add sourcemap support
rickhanlonii ab81892
This is a type
rickhanlonii 1189fe7
Merge remote-tracking branch 'upstream/master' into remove-retainlines
rickhanlonii 8e50d0f
Remove unused function moved to jest-util
rickhanlonii 6ad7202
Fix lint
rickhanlonii 6ec7b74
Minor clean `up
rickhanlonii 11948b8
Feedback updates
rickhanlonii 765f78a
fix flow violations and minimize diff
SimenB f0c6e08
add todo
SimenB d4b0600
Merge branch 'master' into remove-retainlines
SimenB 7ce154d
use sourcemaps in buffered console as well
SimenB 3f2ccb8
fix stupid typo
SimenB e73423d
Add unit tests for get_callsite
rickhanlonii 0a29175
Fix tests
rickhanlonii e7ccbc6
Merge remote-tracking branch 'upstream/master' into remove-retainlines
rickhanlonii 2e0e0a3
Merge branch 'master' into remove-retainlines
SimenB 736eb2b
move changelog entry
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import fs from 'fs'; | ||
import SourceMap from 'source-map'; | ||
import getCallsite from '../get_callsite'; | ||
|
||
jest.mock('fs'); | ||
|
||
describe('getCallsite', () => { | ||
beforeEach(() => { | ||
fs.readFileSync = jest.fn(); | ||
}); | ||
|
||
test('without source map', () => { | ||
const site = getCallsite(0); | ||
|
||
expect(site.getFileName()).toEqual(__filename); | ||
expect(site.getColumnNumber()).toEqual(expect.any(Number)); | ||
expect(site.getLineNumber()).toEqual(expect.any(Number)); | ||
expect(fs.readFileSync).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('ignores errors when fs throws', () => { | ||
fs.readFileSync.mockImplementation(() => { | ||
throw new Error('Mock error'); | ||
}); | ||
|
||
const site = getCallsite(0, {[__filename]: 'mockedSourceMapFile'}); | ||
|
||
expect(site.getFileName()).toEqual(__filename); | ||
expect(site.getColumnNumber()).toEqual(expect.any(Number)); | ||
expect(site.getLineNumber()).toEqual(expect.any(Number)); | ||
expect(fs.readFileSync).toHaveBeenCalledWith('mockedSourceMapFile', 'utf8'); | ||
}); | ||
|
||
test('reads source map file to determine line and column', () => { | ||
const sourceMapColumn = 1; | ||
const sourceMapLine = 2; | ||
SourceMap.SourceMapConsumer = class { | ||
originalPositionFor(params) { | ||
expect(params).toMatchObject({ | ||
column: expect.any(Number), | ||
line: expect.any(Number), | ||
}); | ||
|
||
return { | ||
column: sourceMapColumn, | ||
line: sourceMapLine, | ||
}; | ||
} | ||
}; | ||
|
||
const site = getCallsite(0, {[__filename]: 'mockedSourceMapFile'}); | ||
|
||
expect(site.getFileName()).toEqual(__filename); | ||
expect(site.getColumnNumber()).toEqual(sourceMapColumn); | ||
expect(site.getLineNumber()).toEqual(sourceMapLine); | ||
expect(fs.readFileSync).toHaveBeenCalledWith('mockedSourceMapFile', 'utf8'); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thisbeforeEach
shouldn't be necessaryThere 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 neededThere 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