Skip to content

Commit

Permalink
Implement a node script wrapper for our tests so that we can output a…
Browse files Browse the repository at this point in the history
… hint when failing (#4745)
  • Loading branch information
julienw authored Mar 1, 2024
1 parent 73c428b commit d5545b1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
33 changes: 33 additions & 0 deletions bin/output-fixing-commands.js
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] +
'`'
);
}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"build-l10n-prod:quiet": "yarn build:clean && yarn build-photon && cross-env NODE_ENV=production L10N=1 webpack",
"build-l10n-prod": "yarn build-l10n-prod:quiet --progress",
"build-photon": "webpack --config res/photon/webpack.config.js",
"lint": "run-p lint-js lint-css prettier-run",
"lint": "node bin/output-fixing-commands.js run-p lint-js lint-css prettier-run",
"lint-fix": "run-p lint-fix-js lint-fix-css prettier-fix",
"lint-js": "eslint *.js bin src --report-unused-disable-directives --cache --cache-strategy content",
"lint-js": "node bin/output-fixing-commands.js eslint *.js bin src --report-unused-disable-directives --cache --cache-strategy content",
"lint-fix-js": "yarn lint-js --fix",
"lint-css": "stylelint \"src/**/*.css\" \"res/**/*.css\"",
"lint-css": "node bin/output-fixing-commands.js stylelint \"src/**/*.css\" \"res/**/*.css\"",
"lint-fix-css": "yarn lint-css --fix",
"prettier-run": "prettier --check . --cache --cache-strategy content --cache-location .prettiercache",
"prettier-run": "node bin/output-fixing-commands.js prettier --check . --cache --cache-strategy content --cache-location .prettiercache",
"prettier-fix": "prettier --write . --cache --cache-strategy content --cache-location .prettiercache",
"flow": "flow --max-warnings 0",
"flow:ci": "flow check --max-warnings 0",
Expand All @@ -37,7 +37,7 @@
"start-examples": "ws -d examples/ -s index.html -p 4242",
"start-docs": "ws -d docs-user/ -p 3000",
"start-photon": "node res/photon/server",
"test": "cross-env LC_ALL=C TZ=UTC NODE_ENV=test jest",
"test": "node bin/output-fixing-commands.js cross-env LC_ALL=C TZ=UTC NODE_ENV=test jest",
"test-all": "run-p --max-parallel 4 flow license-check lint test test-alex test-lockfile",
"test-all:ci": "run-p --max-parallel 4 flow:ci license-check lint test test-alex test-lockfile",
"test-build-coverage": "jest --coverage --coverageReporters=html",
Expand Down

0 comments on commit d5545b1

Please sign in to comment.