-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a node script wrapper for our tests so that we can output a…
… hint when failing (#4745)
- Loading branch information
Showing
2 changed files
with
38 additions
and
5 deletions.
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,33 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
// @flow | ||
|
||
// This file runs before linting commands and intercept errors so that more | ||
// friendly errors can be output. | ||
|
||
const cp = require('child_process'); | ||
|
||
const fixingCommands = { | ||
lint: 'lint-fix', | ||
'lint-js': 'lint-fix-js', | ||
'lint-css': 'lint-fix-css', | ||
'prettier-run': 'prettier-fix', | ||
test: 'test -u', | ||
}; | ||
|
||
const command = process.argv.slice(2); | ||
|
||
const result = cp.spawnSync(command[0], command.slice(1), { stdio: 'inherit' }); | ||
|
||
if (result.status !== 0) { | ||
process.exitCode = result.status; | ||
const currentScriptName = process.env.npm_lifecycle_event; | ||
if (currentScriptName && currentScriptName in fixingCommands) { | ||
console.log( | ||
'💡 You might be able to fix the error by running `yarn ' + | ||
fixingCommands[currentScriptName] + | ||
'`' | ||
); | ||
} | ||
} |
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