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
getConsoleOutput receives global noStackTrace #10081
Changes from 8 commits
91165d3
ce2ae46
26b1aef
67d62f7
102e7fb
ccc2e4c
ed13e4d
e5783a3
01a89c3
28b8337
5caa72e
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {formatStackTrace} from 'jest-message-util'; | ||
import getConsoleOutput from '../getConsoleOutput'; | ||
import BufferedConsole from '../BufferedConsole'; | ||
import {LogType} from '../types'; | ||
|
||
jest.mock('jest-message-util', () => ({ | ||
formatStackTrace: jest.fn(), | ||
})); | ||
|
||
describe('getConsoleOutput', () => { | ||
formatStackTrace.mockImplementation(() => 'throw new Error("Whoops!");'); | ||
const cases = [ | ||
'assert', | ||
'count', | ||
'debug', | ||
'dir', | ||
'dirxml', | ||
'error', | ||
'group', | ||
'groupCollapsed', | ||
'info', | ||
'log', | ||
'time', | ||
'warn', | ||
]; | ||
|
||
cases.forEach(logType => { | ||
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.
|
||
it(`takes noStackTrace and pass it on for ${logType}`, () => { | ||
getConsoleOutput( | ||
'someRootPath', | ||
true, | ||
BufferedConsole.write([], logType as LogType, 'message', 4), | ||
{ | ||
rootDir: 'root', | ||
testMatch: [], | ||
}, | ||
true, | ||
); | ||
expect(formatStackTrace).toHaveBeenCalled(); | ||
expect(formatStackTrace).toHaveBeenCalledWith( | ||
expect.anything(), | ||
expect.anything(), | ||
expect.objectContaining({ | ||
noCodeFrame: expect.anything(), | ||
noStackTrace: true, | ||
}), | ||
); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,21 @@ import { | |
StackTraceOptions, | ||
formatStackTrace, | ||
} from 'jest-message-util'; | ||
import type {Config} from '@jest/types'; | ||
import type {ConsoleBuffer} from './types'; | ||
|
||
export default ( | ||
// TODO: remove in 26 | ||
// TODO: remove in 27 | ||
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. Missed 26, I can follow closer and create PR when 27 is near. |
||
root: string, | ||
// TODO: this is covered by GlobalConfig, switch over in 27 | ||
verbose: boolean, | ||
buffer: ConsoleBuffer, | ||
// TODO: make mandatory and take Config.ProjectConfig in 26 | ||
// TODO: make mandatory and take Config.ProjectConfig in 27 | ||
config: StackTraceConfig = { | ||
rootDir: root, | ||
testMatch: [], | ||
}, | ||
globalConfig: Config.GlobalConfig, | ||
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. Needs to be optional until next major 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 created this one and can create a PR for it, please let me know if anything is missing. 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. Perfect 👍 |
||
): string => { | ||
const TITLE_INDENT = verbose ? ' ' : ' '; | ||
const CONSOLE_INDENT = TITLE_INDENT + ' '; | ||
|
@@ -40,12 +43,12 @@ export default ( | |
if (type === 'warn') { | ||
message = chalk.yellow(message); | ||
typeMessage = chalk.yellow(typeMessage); | ||
noStackTrace = false; | ||
noStackTrace = false || globalConfig.noStackTrace; | ||
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.
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. Thanks for catching! updated in a following commit. |
||
noCodeFrame = false; | ||
} else if (type === 'error') { | ||
message = chalk.red(message); | ||
typeMessage = chalk.red(typeMessage); | ||
noStackTrace = false; | ||
noStackTrace = false || globalConfig.noStackTrace; | ||
noCodeFrame = false; | ||
} | ||
|
||
|
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.