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: use smokehouse runner for test-bundle #9943

Merged
merged 4 commits into from
Dec 14, 2019
Merged

Conversation

brendankenny
Copy link
Member

follow up to #9791 and #9843

Moves the bundled lighthouse test to the new smokehouse format. Uses the devtools bundle in this PR, though we can change that easily (to lr, to dt & lr, or to a standalone bundle).

Lower priority right now, but it's really handy for being able to test the devtools bundle locally (at least without a Chromium dev setup) while we try to get the plugin bundled in.

@@ -38,7 +38,8 @@ const isDevtools = file => path.basename(file).includes('devtools');
/** @param {string} file */
const isLightrider = file => path.basename(file).includes('lightrider');

const BANNER = `// lighthouse, browserified. ${VERSION} (${COMMIT_HASH})\n`;
const BANNER = `// lighthouse, browserified. ${VERSION} (${COMMIT_HASH})\n` +
'// @ts-nocheck\n'; // To prevent tsc stepping into any required bundles.
Copy link
Member Author

Choose a reason for hiding this comment

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

since dist/lighthouse-dt-bundle.js is required in smokehouse and smokehouse is type checked, tsc automatically starts checking the bundle code too. This is the only reliable way I could think of to stop it, but happy for alternatives :)

// Instead, since this file is only ever run in node for testing, expose a
// bundle entry point as global.
// @ts-ignore
global.runBundledLighthouse = lighthouse;
Copy link
Member Author

Choose a reason for hiding this comment

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

originally was going to make runLighthouseInWorker global, but we need to substitute in a connection and config (instead of port and categoryIds). Rather than making the function unreadable with a bunch of options or requiring devtools to call the module differently (which we could still do in the future), exposing the inner lighthouse call seemed like the simplest fix.

I am slightly concerned about drift between how devtools calls runLighthouseInWorker and what happens inside that function and the default interface, but for now it's a really simple correspondence.

Copy link
Collaborator

@connorjclark connorjclark Nov 7, 2019

Choose a reason for hiding this comment

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

This drift sounds fine to me. When I have the smoke tests run against the Audits panel, it will be at a higher level than this bundle, so the drift between runBundledLighthouse and runLighthouseInWorker is irrelevant (won't even used the former). I will need to add a config, but that's simple.

So while runBundledLighthouse happens to live here, it's got nothing to do with devtools. That is a little confusing - what about making a new client for this, bundle-entry.js?

Copy link
Member Author

Choose a reason for hiding this comment

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

When I have the smoke tests run against the Audits panel, it will be at a higher level than this bundle

ah, good to know, I didn't realize that, though it makes sense.

So while runBundledLighthouse happens to live here, it's got nothing to do with devtools. That is a little confusing - what about making a new client for this, bundle-entry.js?

Agree it's kind of confusing, but the benefit is it's getting all the bundle customizations--all the isDevTools tweaks, for instance--so it's making sure the real bundles are working. I was thinking we could add a smoke test just for the pubAds integration, for instance.

Originally I had it something like

function runLighthouseInWorker() {
  // ...
  runLighthouse(...args);
}

/**
 * Intermediate function to expose for testing.
 */
function runLighthouse() {
  lighthouse(...args)
}

global.runBundledLighthouse = runLighthouse;

that spelled it out a little more clearly but also seemed a bit silly.

We could change the runLighthouseInWorker interface to make it more flexible, too (like make it take a config and devtools code could call getDefaultConfigForCategories with the categoryIds itself and then pass the config back in), but I figured now's probably not the time for such changes :)

Other ways we could make things more explicit and clearer?

@@ -0,0 +1,54 @@
/**
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe this should be launch-chrome-and-bundle.js or something to differentiate from the pure bundle runner needed by #9873. We could bikeshed now or later

return {
lhr: runnerResult.lhr,
artifacts: runnerResult.artifacts,
log: '', // TODO: if want to run in parallel, need to capture lighthouse-logger output.
Copy link
Member Author

Choose a reason for hiding this comment

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

there is a way to control where debug output goes, but I'm skipping looking into the complications of that (singletons! :shakes_fist:) for now since I don't think we're going to want to run the bundled version multiple times in the same process. If it's only ever run with -j=1, the output will always be properly ordered.

Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

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

good changes. sad to see my magic bundled cli go, but for the best.

@@ -76,7 +79,7 @@ async function begin() {
.alias({
'jobs': 'j',
})
.choices('runner', ['cli'])
.choices('runner', ['cli', 'bundle'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

should there be a --runner-path, so others could make use a custom runner w/o changing this file?

makes sense to just wait for someone to request this feature, but it's easy enough to do perhaps we should just do it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I will be one such user in the near future :)

Copy link
Member Author

Choose a reason for hiding this comment

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

should there be a --runner-path, so others could make use a custom runner w/o changing this file?

Could we just add it when you need it? Agreed it fits in easily, these are more or less just shorthand forms of that, but I'd like to avoid messing with yargs more right now :)

Copy link
Member Author

Choose a reason for hiding this comment

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

should there be a --runner-path, so others could make use a custom runner w/o changing this file?

though smokehouse.js can already take any custom runner without changes. I kind of figured that when we needed a really custom runner, we would also need firehouse's test filtering and so could just make a new frontend (smoke-mask :D). Like 80% of this file is parsing argv anyways.

@@ -38,7 +38,8 @@ const isDevtools = file => path.basename(file).includes('devtools');
/** @param {string} file */
const isLightrider = file => path.basename(file).includes('lightrider');

const BANNER = `// lighthouse, browserified. ${VERSION} (${COMMIT_HASH})\n`;
const BANNER = `// lighthouse, browserified. ${VERSION} (${COMMIT_HASH})\n` +
'// @ts-nocheck\n'; // To prevent tsc stepping into any required bundles.
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we just exclude the bundle in tsconfig?

Copy link
Member Author

Choose a reason for hiding this comment

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

can we just exclude the bundle in tsconfig?

from my experience this isn't possible (include and exclude are just including and excluding root files that tsc starts walking from), but I would be happy if I was missing something :)

See https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#details ("Any files that are referenced by files included...")

lookupLocale,
};
// Ideally this could be exposed via browserify's `standalone`, but it doesn't
// work for LH because of https://github.com/browserify/browserify/issues/968.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// work for LH because of https://github.com/browserify/browserify/issues/968.
// work for LH because of https://github.com/browserify/browserify/issues/968

(period broke link)

@connorjclark connorjclark changed the title tests: move test-bundle to a smokehouse runner tests: use smokehouse runner for test-bundle Dec 14, 2019
@connorjclark connorjclark merged commit 8f75443 into master Dec 14, 2019
@connorjclark connorjclark deleted the smokebundle branch December 14, 2019 01:46
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.

3 participants