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(smoke): check for passing robots-txt #13007

Merged
merged 4 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions lighthouse-cli/test/fixtures/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow:
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ const passing = {
score: 1,
},
'robots-txt': {
score: null,
scoreDisplayMode: 'notApplicable',
score: 1,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/gather/gatherers/seo/robots-txt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
const FRGatherer = require('../../../fraggle-rock/gather/base-gatherer.js');
const {getBrowserVersion} = require('../../driver/environment.js');

/* global fetch, location */
/* global fetch, location, window */

/** @return {Promise<LH.Artifacts['RobotsTxt']>} */
/* c8 ignore start */
async function getRobotsTxtContent() {
try {
const response = await fetch(new URL('/robots.txt', location.href).href);
const response = await fetch(new window.__nativeURL('/robots.txt', location.href).href);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

took awhile to figure out why the smoke test wasn't passing, it's because seo tester html overrides URL! so, luckily we get a driveby fix here for naughty pages overriding globals.

Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, _cachedNativesPreamble should be solving this, is something broken there? that's more concerning than the smoke itself :/

/**
* Prefix every script evaluation with a shadowing of common globals that tend to be ponyfilled
* incorrectly by many sites. This allows functions to still refer to `Promise` instead of
* Lighthouse-specific backups like `__nativePromise` (injected by `cacheNativesOnNewDocument` above).
*/
static _cachedNativesPreamble = [
'const Promise = globalThis.__nativePromise || globalThis.Promise',
'const URL = globalThis.__nativeURL || globalThis.URL',
'const performance = globalThis.__nativePerformance || globalThis.performance',
].join(';\n');

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok so this seems fine and i can't get it to fail again, weird

if (!response.ok) {
return {status: response.status, content: null};
}
Expand Down