Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(smokehouse): assert on expected array length #9292

Merged
merged 5 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ module.exports = [
transferSize: 53181,
resourceSize: 52997,
},
{
url: 'http://localhost:10200/favicon.ico',
},
],
},
},
Expand Down
14 changes: 10 additions & 4 deletions lighthouse-cli/test/smokehouse/error-expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*/
'use strict';

// Just using `[]` actually asserts for an empty array.
// Use this expectation object to assert an array with at least one element.
const NONEMPTY_ARRAY = {
length: '>0',
};

/**
* Expected Lighthouse audit values for sites with various errors.
*/
Expand All @@ -24,10 +30,10 @@ module.exports = [
artifacts: {
PageLoadError: {code: 'PAGE_HUNG'},
devtoolsLogs: {
'pageLoadError-defaultPass': [/* ... */],
'pageLoadError-defaultPass': NONEMPTY_ARRAY,
},
traces: {
'pageLoadError-defaultPass': {traceEvents: [/* ... */]},
'pageLoadError-defaultPass': {traceEvents: NONEMPTY_ARRAY},
},
},
},
Expand All @@ -46,10 +52,10 @@ module.exports = [
artifacts: {
PageLoadError: {code: 'INSECURE_DOCUMENT_REQUEST'},
devtoolsLogs: {
'pageLoadError-defaultPass': [/* ... */],
'pageLoadError-defaultPass': NONEMPTY_ARRAY,
},
traces: {
'pageLoadError-defaultPass': {traceEvents: [/* ... */]},
'pageLoadError-defaultPass': {traceEvents: NONEMPTY_ARRAY},
},
},
},
Expand Down
12 changes: 12 additions & 0 deletions lighthouse-cli/test/smokehouse/smokehouse-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ function findDifference(path, actual, expected) {
}
}

// 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].
if (Array.isArray(expected) && actual.length !== expected.length) {
return {
path: `${path}.length`,
actual,
expected,
};
}

return null;
}

Expand Down