Skip to content

Commit 7de67f4

Browse files
authored
feat: Allow plugin to run onSuccess with toml setting or env var LIGHTHOUSE_RUN_ON_SUCCESS (#570)
1 parent 3bb2cc3 commit 7de67f4

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "src/index.js",
66
"scripts": {
77
"local": "node -e 'import(\"./src/index.js\").then(index => index.default()).then(events => events.onPostBuild());'",
8-
"local-onsuccess": "RUN_ON_SUCCESS=true node -e 'import(\"./src/index.js\").then(index => index.default()).then(events => events.onSuccess());'",
8+
"local-onsuccess": "LIGHTHOUSE_RUN_ON_SUCCESS=true node -e 'import(\"./src/index.js\").then(index => index.default()).then(events => events.onSuccess());'",
99
"lint": "eslint 'src/**/*.js'",
1010
"format": "prettier --write 'src/**/*.js'",
1111
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --collect-coverage",

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import getUtils from './lib/get-utils/index.js';
66
dotenv.config();
77

88
export default function lighthousePlugin(inputs) {
9-
// Run onPostBuild by default, unless RUN_ON_SUCCESS is set to true
9+
// Run onPostBuild by default, unless LIGHTHOUSE_RUN_ON_SUCCESS env var is set to true, or run_on_success is specified in plugin inputs
1010
const defaultEvent =
11-
inputs?.run_on_success === 'true' || process.env.RUN_ON_SUCCESS === 'true'
11+
inputs?.run_on_success === 'true' ||
12+
process.env.LIGHTHOUSE_RUN_ON_SUCCESS === 'true'
1213
? 'onSuccess'
1314
: 'onPostBuild';
1415

src/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ describe('lighthousePlugin plugin events', () => {
1212

1313
describe('onSuccess', () => {
1414
beforeEach(() => {
15-
process.env.RUN_ON_SUCCESS = 'true';
15+
process.env.LIGHTHOUSE_RUN_ON_SUCCESS = 'true';
1616
});
1717
afterEach(() => {
18-
delete process.env.RUN_ON_SUCCESS;
18+
delete process.env.LIGHTHOUSE_RUN_ON_SUCCESS;
1919
});
2020
it('should return only the expected event function', async () => {
2121
const events = lighthousePlugin();

0 commit comments

Comments
 (0)