Skip to content

Commit 0ed3426

Browse files
authored
feat(cli): add failureLabels to healthcheck (#99)
1 parent 36cb689 commit 0ed3426

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

packages/cli/src/healthcheck/healthcheck.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ function buildCommand(yargs) {
3434
});
3535
}
3636

37-
/** @type {Array<{id?: string, label: string, test: (opts: LHCI.YargsOptions) => Promise<boolean>|boolean, shouldTest: (opts: LHCI.YargsOptions) => boolean}>} */
37+
/** @type {Array<{id?: string, label: string, failureLabel: string, test: (opts: LHCI.YargsOptions) => Promise<boolean>|boolean, shouldTest: (opts: LHCI.YargsOptions) => boolean}>} */
3838
const checks = [
3939
{
4040
label: '.lighthouseci/ directory writable',
41+
failureLabel: '.lighthouseci/ directory not writable',
4142
shouldTest: () => true,
4243
test: () => loadSavedLHRs().length >= 0,
4344
},
4445
{
4546
id: 'rcFile',
4647
label: 'Configuration file found',
48+
failureLabel: 'Configuration file not found',
4749
shouldTest: () => true,
4850
test: opts => {
4951
const rcFile = resolveRcFilePath(opts.config);
@@ -54,20 +56,23 @@ const checks = [
5456
{
5557
id: 'githubToken',
5658
label: 'GitHub token set',
59+
failureLabel: 'GitHub token not set',
5760
// the test only makes sense if they've configured an upload target of some sort
5861
shouldTest: opts => !!opts.target || !!opts.serverBaseUrl,
5962
test: opts => Boolean(opts.githubToken || opts.githubAppToken),
6063
},
6164
{
6265
id: 'lhciServer',
6366
label: 'Ancestor hash determinable',
67+
failureLabel: 'Ancestor hash not determinable',
6468
// the test only makes sense if they've configured an LHCI server
6569
shouldTest: opts => Boolean(opts.serverBaseUrl && opts.token),
6670
test: () => getAncestorHash().length > 0,
6771
},
6872
{
6973
id: 'lhciServer',
7074
label: 'LHCI server reachable',
75+
failureLabel: 'LHCI server not reachable',
7176
// the test only makes sense if they've configured an LHCI server
7277
shouldTest: opts => Boolean(opts.serverBaseUrl && opts.token),
7378
test: async ({serverBaseUrl = ''}) =>
@@ -76,6 +81,7 @@ const checks = [
7681
{
7782
id: 'lhciServer',
7883
label: 'LHCI server token valid',
84+
failureLabel: 'LHCI server token invalid',
7985
// the test only makes sense if they've configured an LHCI server
8086
shouldTest: opts => Boolean(opts.serverBaseUrl && opts.token),
8187
test: async ({serverBaseUrl = '', token = ''}) => {
@@ -87,6 +93,7 @@ const checks = [
8793
{
8894
id: 'lhciServer',
8995
label: 'LHCI server unique build for this hash',
96+
failureLabel: 'LHCI server non-unique build for this hash',
9097
// the test only makes sense if they've configured an LHCI server
9198
shouldTest: opts => Boolean(opts.serverBaseUrl && opts.token),
9299
test: async ({serverBaseUrl = '', token = ''}) => {
@@ -124,8 +131,9 @@ async function runCommand(options) {
124131

125132
const isWarn = !!check.id && !checkIdsToRun.includes(check.id);
126133
const icon = result ? PASS_ICON : isWarn ? WARN_ICON : FAIL_ICON;
134+
const label = result ? check.label : check.failureLabel;
127135
allPassed = allPassed && (isWarn || result);
128-
process.stdout.write(`${icon} ${check.label}${message}\n`);
136+
process.stdout.write(`${icon} ${label}${message}\n`);
129137
}
130138

131139
if (allPassed) {

packages/cli/test/autorun-start-server.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Lighthouse CI autorun CLI with startServerCommand', () => {
2828

2929
expect(stdout).toMatchInlineSnapshot(`
3030
"✅ .lighthouseci/ directory writable
31-
⚠️ Configuration file found
31+
⚠️ Configuration file not found
3232
Healthcheck passed!
3333
3434
Started a web server with \\"node autorun-server.js\\"...

packages/cli/test/autorun-static-dir.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Lighthouse CI autorun CLI', () => {
2525
expect(stdoutClean).toMatchInlineSnapshot(`
2626
"✅ .lighthouseci/ directory writable
2727
✅ Configuration file found
28-
⚠️ GitHub token set
28+
⚠️ GitHub token not set
2929
Healthcheck passed!
3030
3131
Automatically determined ./build as \`staticDistDir\`.

packages/cli/test/cli.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ describe('Lighthouse CI CLI', () => {
109109

110110
expect(stdout).toMatchInlineSnapshot(`
111111
"✅ .lighthouseci/ directory writable
112-
⚠️ Configuration file found
113-
⚠️ GitHub token set
112+
⚠️ Configuration file not found
113+
⚠️ GitHub token not set
114114
✅ Ancestor hash determinable
115115
✅ LHCI server reachable
116116
✅ LHCI server token valid
@@ -133,7 +133,7 @@ describe('Lighthouse CI CLI', () => {
133133
expect(stdout).toMatchInlineSnapshot(`
134134
"✅ .lighthouseci/ directory writable
135135
✅ Configuration file found
136-
❌ GitHub token set
136+
❌ GitHub token not set
137137
✅ Ancestor hash determinable
138138
✅ LHCI server reachable
139139
✅ LHCI server token valid

packages/cli/test/healthcheck.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Lighthouse CI healthcheck CLI', () => {
2121
expect(stdout).toMatchInlineSnapshot(`
2222
"✅ .lighthouseci/ directory writable
2323
✅ Configuration file found
24-
⚠️ GitHub token set
24+
⚠️ GitHub token not set
2525
Healthcheck passed!
2626
"
2727
`);
@@ -38,7 +38,7 @@ describe('Lighthouse CI healthcheck CLI', () => {
3838
expect(stdout).toMatchInlineSnapshot(`
3939
"✅ .lighthouseci/ directory writable
4040
✅ Configuration file found
41-
⚠️ GitHub token set
41+
⚠️ GitHub token not set
4242
Healthcheck passed!
4343
"
4444
`);
@@ -54,7 +54,7 @@ describe('Lighthouse CI healthcheck CLI', () => {
5454
expect(status).toEqual(0);
5555
expect(stdout).toMatchInlineSnapshot(`
5656
"✅ .lighthouseci/ directory writable
57-
⚠️ Configuration file found
57+
⚠️ Configuration file not found
5858
Healthcheck passed!
5959
"
6060
`);
@@ -70,7 +70,7 @@ describe('Lighthouse CI healthcheck CLI', () => {
7070
expect(status).toEqual(0);
7171
expect(stdout).toMatchInlineSnapshot(`
7272
"✅ .lighthouseci/ directory writable
73-
⚠️ Configuration file found
73+
⚠️ Configuration file not found
7474
Healthcheck passed!
7575
"
7676
`);
@@ -86,7 +86,7 @@ describe('Lighthouse CI healthcheck CLI', () => {
8686
expect(status).toEqual(0);
8787
expect(stdout).toMatchInlineSnapshot(`
8888
"✅ .lighthouseci/ directory writable
89-
⚠️ Configuration file found
89+
⚠️ Configuration file not found
9090
Healthcheck passed!
9191
"
9292
`);

0 commit comments

Comments
 (0)