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 2 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
10 changes: 6 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,8 @@
*/
'use strict';

const IS_ARRAY = {};

/**
* Expected Lighthouse audit values for sites with various errors.
*/
Expand All @@ -24,10 +26,10 @@ module.exports = [
artifacts: {
PageLoadError: {code: 'PAGE_HUNG'},
devtoolsLogs: {
'pageLoadError-defaultPass': [/* ... */],
'pageLoadError-defaultPass': IS_ARRAY,
Copy link
Collaborator Author

@connorjclark connorjclark Jun 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit this is not perfect.

But "I expect an array with these exact values, and no more" is more common than "I expect an array", so I'd rather [a, b, c] mean the former and not "expected array is a prefix of actual array"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed the array use case is more important

definitely weird that IS_ARRAY is an object instead of an array though :)

maybe we can comment this one-time usage that we can't use an array and at least assert {length: '>0'} or something?

},
traces: {
'pageLoadError-defaultPass': {traceEvents: [/* ... */]},
'pageLoadError-defaultPass': {traceEvents: IS_ARRAY},
},
},
},
Expand All @@ -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},
},
},
},
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 on the length.
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
// 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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we do

path: `${path}.length`,

?

agreed that printing the full array value is best though

actual,
expected,
};
}

return null;
}

Expand Down