From 3b8076e8ae6abfaba30d48438c70b8a9f91cadf0 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Wed, 26 Jun 2019 21:03:17 -0700 Subject: [PATCH 1/5] tests(smokehouse): assert on expected array length --- .../test/smokehouse/byte-efficiency/expectations.js | 3 +++ lighthouse-cli/test/smokehouse/error-expectations.js | 10 ++++++---- lighthouse-cli/test/smokehouse/smokehouse-report.js | 12 ++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js b/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js index 649b674e44ae..ee0590a65810 100644 --- a/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js +++ b/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js @@ -140,6 +140,9 @@ module.exports = [ transferSize: 53181, resourceSize: 52997, }, + { + url: "http://localhost:10200/favicon.ico", + }, ], }, }, diff --git a/lighthouse-cli/test/smokehouse/error-expectations.js b/lighthouse-cli/test/smokehouse/error-expectations.js index 57c3e60cb073..127630307aa0 100644 --- a/lighthouse-cli/test/smokehouse/error-expectations.js +++ b/lighthouse-cli/test/smokehouse/error-expectations.js @@ -5,6 +5,8 @@ */ 'use strict'; +const IS_ARRAY = {}; + /** * Expected Lighthouse audit values for sites with various errors. */ @@ -24,10 +26,10 @@ module.exports = [ artifacts: { PageLoadError: {code: 'PAGE_HUNG'}, devtoolsLogs: { - 'pageLoadError-defaultPass': [/* ... */], + 'pageLoadError-defaultPass': IS_ARRAY, }, traces: { - 'pageLoadError-defaultPass': {traceEvents: [/* ... */]}, + 'pageLoadError-defaultPass': {traceEvents: IS_ARRAY}, }, }, }, @@ -46,10 +48,10 @@ module.exports = [ artifacts: { PageLoadError: {code: 'INSECURE_DOCUMENT_REQUEST'}, devtoolsLogs: { - 'pageLoadError-defaultPass': [/* ... */], + 'pageLoadError-defaultPass': IS_ARRAY, }, traces: { - 'pageLoadError-defaultPass': {traceEvents: [/* ... */]}, + 'pageLoadError-defaultPass': {traceEvents: IS_ARRAY}, }, }, }, diff --git a/lighthouse-cli/test/smokehouse/smokehouse-report.js b/lighthouse-cli/test/smokehouse/smokehouse-report.js index 5f670a38a394..9286e19c0475 100644 --- a/lighthouse-cli/test/smokehouse/smokehouse-report.js +++ b/lighthouse-cli/test/smokehouse/smokehouse-report.js @@ -98,6 +98,18 @@ function findDifference(path, actual, expected) { } } + // If the expected value is an array, assert on the length. + // This still allows for asserting that the first n elements of an array are specified elements, + // but requires using an object literal (ex: {0: x, 1: y, 2: z} matches [x, y, z, q, w, e] and + // {0: x, 1: y, 2: z, length: 5} does not match [x, y, z]. + if (Array.isArray(expected) && actual.length !== expected.length) { + return { + path, + actual, + expected, + }; + } + return null; } From c3041117205f2887edfd867025fc87c3ec519fc0 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Wed, 26 Jun 2019 22:25:48 -0700 Subject: [PATCH 2/5] lint --- lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js b/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js index ee0590a65810..7b69fdae3841 100644 --- a/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js +++ b/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js @@ -141,7 +141,7 @@ module.exports = [ resourceSize: 52997, }, { - url: "http://localhost:10200/favicon.ico", + url: 'http://localhost:10200/favicon.ico', }, ], }, From 886a1093f30d3720ebbce309c72675e25dda684c Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 8 Jul 2019 15:45:50 -0700 Subject: [PATCH 3/5] pr --- .../test/smokehouse/error-expectations.js | 14 +++++++++----- .../test/smokehouse/smokehouse-report.js | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lighthouse-cli/test/smokehouse/error-expectations.js b/lighthouse-cli/test/smokehouse/error-expectations.js index 127630307aa0..9150b531e6fe 100644 --- a/lighthouse-cli/test/smokehouse/error-expectations.js +++ b/lighthouse-cli/test/smokehouse/error-expectations.js @@ -5,7 +5,11 @@ */ 'use strict'; -const IS_ARRAY = {}; +// Just using `[]` actually asserts for an empty array. +// Use this expectation object to assert an array with at least one element. +const IS_NONEMPTY_ARRAY = { + length: '>0', +}; /** * Expected Lighthouse audit values for sites with various errors. @@ -26,10 +30,10 @@ module.exports = [ artifacts: { PageLoadError: {code: 'PAGE_HUNG'}, devtoolsLogs: { - 'pageLoadError-defaultPass': IS_ARRAY, + 'pageLoadError-defaultPass': IS_NONEMPTY_ARRAY, }, traces: { - 'pageLoadError-defaultPass': {traceEvents: IS_ARRAY}, + 'pageLoadError-defaultPass': {traceEvents: IS_NONEMPTY_ARRAY}, }, }, }, @@ -48,10 +52,10 @@ module.exports = [ artifacts: { PageLoadError: {code: 'INSECURE_DOCUMENT_REQUEST'}, devtoolsLogs: { - 'pageLoadError-defaultPass': IS_ARRAY, + 'pageLoadError-defaultPass': IS_NONEMPTY_ARRAY, }, traces: { - 'pageLoadError-defaultPass': {traceEvents: IS_ARRAY}, + 'pageLoadError-defaultPass': {traceEvents: IS_NONEMPTY_ARRAY}, }, }, }, diff --git a/lighthouse-cli/test/smokehouse/smokehouse-report.js b/lighthouse-cli/test/smokehouse/smokehouse-report.js index 9286e19c0475..3472937218bd 100644 --- a/lighthouse-cli/test/smokehouse/smokehouse-report.js +++ b/lighthouse-cli/test/smokehouse/smokehouse-report.js @@ -104,7 +104,7 @@ function findDifference(path, actual, expected) { // {0: x, 1: y, 2: z, length: 5} does not match [x, y, z]. if (Array.isArray(expected) && actual.length !== expected.length) { return { - path, + path: `${path}.length`, actual, expected, }; From 4132e0780b3bb15bbd2daec59363620cd9beb539 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 8 Jul 2019 16:03:35 -0700 Subject: [PATCH 4/5] Update lighthouse-cli/test/smokehouse/smokehouse-report.js Co-Authored-By: Brendan Kenny --- lighthouse-cli/test/smokehouse/smokehouse-report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lighthouse-cli/test/smokehouse/smokehouse-report.js b/lighthouse-cli/test/smokehouse/smokehouse-report.js index 3472937218bd..37fe6d26a357 100644 --- a/lighthouse-cli/test/smokehouse/smokehouse-report.js +++ b/lighthouse-cli/test/smokehouse/smokehouse-report.js @@ -98,7 +98,7 @@ function findDifference(path, actual, expected) { } } - // If the expected value is an array, assert on the length. + // If the expected value is an array, assert the length as well. // This still allows for asserting that the first n elements of an array are specified elements, // but requires using an object literal (ex: {0: x, 1: y, 2: z} matches [x, y, z, q, w, e] and // {0: x, 1: y, 2: z, length: 5} does not match [x, y, z]. From 25469435557acbc8cc4ea37fb590f21cc182a38b Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 8 Jul 2019 16:04:30 -0700 Subject: [PATCH 5/5] drop the 'is'. it's cleaner. --- lighthouse-cli/test/smokehouse/error-expectations.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lighthouse-cli/test/smokehouse/error-expectations.js b/lighthouse-cli/test/smokehouse/error-expectations.js index 9150b531e6fe..7030f03f02a2 100644 --- a/lighthouse-cli/test/smokehouse/error-expectations.js +++ b/lighthouse-cli/test/smokehouse/error-expectations.js @@ -7,7 +7,7 @@ // Just using `[]` actually asserts for an empty array. // Use this expectation object to assert an array with at least one element. -const IS_NONEMPTY_ARRAY = { +const NONEMPTY_ARRAY = { length: '>0', }; @@ -30,10 +30,10 @@ module.exports = [ artifacts: { PageLoadError: {code: 'PAGE_HUNG'}, devtoolsLogs: { - 'pageLoadError-defaultPass': IS_NONEMPTY_ARRAY, + 'pageLoadError-defaultPass': NONEMPTY_ARRAY, }, traces: { - 'pageLoadError-defaultPass': {traceEvents: IS_NONEMPTY_ARRAY}, + 'pageLoadError-defaultPass': {traceEvents: NONEMPTY_ARRAY}, }, }, }, @@ -52,10 +52,10 @@ module.exports = [ artifacts: { PageLoadError: {code: 'INSECURE_DOCUMENT_REQUEST'}, devtoolsLogs: { - 'pageLoadError-defaultPass': IS_NONEMPTY_ARRAY, + 'pageLoadError-defaultPass': NONEMPTY_ARRAY, }, traces: { - 'pageLoadError-defaultPass': {traceEvents: IS_NONEMPTY_ARRAY}, + 'pageLoadError-defaultPass': {traceEvents: NONEMPTY_ARRAY}, }, }, },