mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Add new Jest --compact-console flag for DevTools tests (#22495)
This commit is contained in:
parent
f2c381131f
commit
cadf94df1f
|
|
@ -7,11 +7,31 @@
|
|||
* @flow
|
||||
*/
|
||||
|
||||
import {CustomConsole} from '@jest/console';
|
||||
|
||||
import type {
|
||||
BackendBridge,
|
||||
FrontendBridge,
|
||||
} from 'react-devtools-shared/src/bridge';
|
||||
|
||||
// Argument is serialized when passed from jest-cli script through to setupTests.
|
||||
const compactConsole = process.env.compactConsole === 'true';
|
||||
if (compactConsole) {
|
||||
const formatter = (type, message) => {
|
||||
switch (type) {
|
||||
case 'error':
|
||||
return '\x1b[31m' + message + '\x1b[0m';
|
||||
case 'warn':
|
||||
return '\x1b[33m' + message + '\x1b[0m';
|
||||
case 'log':
|
||||
default:
|
||||
return message;
|
||||
}
|
||||
};
|
||||
|
||||
global.console = new CustomConsole(process.stdout, process.stderr, formatter);
|
||||
}
|
||||
|
||||
const env = jasmine.getEnv();
|
||||
env.beforeEach(() => {
|
||||
global.mockClipboardCopy = jest.fn();
|
||||
|
|
|
|||
|
|
@ -97,6 +97,13 @@ const argv = yargs
|
|||
requiresArg: true,
|
||||
type: 'string',
|
||||
},
|
||||
compactConsole: {
|
||||
alias: 'c',
|
||||
describe: 'Compact console output (hide file locations).',
|
||||
requiresArg: false,
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
}).argv;
|
||||
|
||||
function logError(message) {
|
||||
|
|
@ -159,6 +166,11 @@ function validateOptions() {
|
|||
logError('DevTool tests require --build.');
|
||||
success = false;
|
||||
}
|
||||
} else {
|
||||
if (argv.compactConsole) {
|
||||
logError('Only DevTool tests support compactConsole flag.');
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isWWWConfig()) {
|
||||
|
|
@ -284,6 +296,10 @@ function getEnvars() {
|
|||
RELEASE_CHANNEL: argv.releaseChannel.match(/modern|experimental/)
|
||||
? 'experimental'
|
||||
: 'stable',
|
||||
|
||||
// Pass this flag through to the confit environment
|
||||
// so the base config can conditionally load the console setup file.
|
||||
compactConsole: argv.compactConsole,
|
||||
};
|
||||
|
||||
if (argv.prod) {
|
||||
|
|
@ -306,7 +322,9 @@ function main() {
|
|||
console.log(chalk.red(`\nPlease run: \`${argv.deprecated}\` instead.\n`));
|
||||
return;
|
||||
}
|
||||
|
||||
validateOptions();
|
||||
|
||||
const args = getCommandArgs();
|
||||
const envars = getEnvars();
|
||||
const env = Object.entries(envars).map(([k, v]) => `${k}=${v}`);
|
||||
|
|
@ -334,6 +352,7 @@ function main() {
|
|||
stdio: 'inherit',
|
||||
env: {...envars, ...process.env},
|
||||
});
|
||||
|
||||
// Ensure we close our process when we get a failure case.
|
||||
jest.on('close', code => {
|
||||
// Forward the exit code from the Jest process.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user