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: add computed/metrics/interactive-test.js to tsconfig #13071

Merged
merged 8 commits into from
Dec 13, 2022

Conversation

connorjclark
Copy link
Collaborator

Started by seeing if the tests/computed/metrics folder could be make type checked, but saw it was a lot of red. Decided to try just one file. Initially I was using the makeParamsOptional method, but then I saw that it may be more straightforward to coerce types as needed.

Adds loadTraceFixture function:

const {trace, devtoolsLog} = loadTraceFixture('progressive-app-m60');

pretty nice. should be useful.

@connorjclark connorjclark requested a review from a team as a code owner September 15, 2021 22:41
@connorjclark connorjclark requested review from adamraine and removed request for a team September 15, 2021 22:41
@google-cla google-cla bot added the cla: yes label Sep 15, 2021
const dir = `${LH_ROOT}/lighthouse-core/test/fixtures/traces`;
return {
devtoolsLog: JSON.parse(fs.readFileSync(`${dir}/${name}.devtools.log.json`, 'utf-8')),
trace: JSON.parse(fs.readFileSync(`${dir}/${name}.json`, 'utf-8')),
Copy link
Member

Choose a reason for hiding this comment

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

Not every trace follows this naming scheme. Maybe make loadTraceFixture and loadDevtoolsLogFixture and use the entire filename?

Copy link
Collaborator Author

@connorjclark connorjclark Sep 20, 2021

Choose a reason for hiding this comment

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

Deferring on this, but I think we can just rename the other files. Splitting makes sense if only one of these two exists, but will wait for when other tests use this file (which isn't necessary unless they are in the tsconfig) and it comes up.

@connorjclark
Copy link
Collaborator Author

segfault in unit tests, re-running ...

const Interactive = require('../../../computed/metrics/interactive.js');
const {getURLArtifactFromDevtoolsLog, loadTraceFixture} = require('../../test-utils.js');

const {trace, devtoolsLog} = loadTraceFixture('progressive-app-m60');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the idea here was to get automatic type coercion to LH.Trace, LH.DevtoolsLog

@connorjclark
Copy link
Collaborator Author

@adamraine updated

@connorjclark connorjclark merged commit e154f3d into main Dec 13, 2022
@connorjclark connorjclark deleted the minor-ts-test-metric branch December 13, 2022 22:33
Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

A lot of this coercing could be avoided by replacing the old minimal test inputs with "real" (at least according to tsc) test inputs. Otherwise type checking isn't bringing many benefits (still opaque to many refactors, hides type errors, etc)

@@ -26,16 +40,20 @@ function generateNetworkRecords(records, timeOrigin) {
startTime: (item.start + timeOriginInMs) / 1000,
endTime: item.end === -1 ? -1 : (item.end + timeOriginInMs) / 1000,
};
return /** @type {LH.Artifacts.NetworkRequest} */ (record);
Copy link
Member

Choose a reason for hiding this comment

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

seems like it would be better to move to network-records-to-devtools-log to get a real network request rather than coercing a fake?

const gatherContext = {gatherMode: 'navigation'};

it('should compute a simulated value', async () => {
const settings = {throttlingMethod: 'simulate'};
const settings = /** @type {LH.Config.Settings} */ (
Copy link
Member

Choose a reason for hiding this comment

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

a test refactor/util I'd love to see is moving tests like this to real config settings. If we don't want to use the full initializeConfig (e.g. this var would be initializeConfig('navigation', undefined, {throttlingMethod: 'simulate'}), which is kind of awkward), we could switch to an options object

const processedTrace = {timestamps: {timeOrigin, firstContentfulPaint, traceEnd}};

const cpu = [];
const processedTrace = /** @type {LH.Artifacts.ProcessedNavigation} */ (
Copy link
Member

Choose a reason for hiding this comment

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

we have create-test-trace to have real traces for tests, as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants