-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core(viewport): include meta viewport string in debugDetails #15727
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,44 +20,49 @@ describe('ViewportMeta computed artifact', () => { | |
/* eslint-disable-next-line max-len */ | ||
it('is not mobile optimized when HTML contains a non-mobile friendly viewport meta tag', async () => { | ||
const viewport = 'maximum-scale=1'; | ||
const {hasViewportTag, isMobileOptimized} = | ||
const {hasViewportTag, isMobileOptimized, rawContentString} = | ||
await ViewportMeta.compute_(makeMetaElements(viewport)); | ||
assert.equal(hasViewportTag, true); | ||
assert.equal(isMobileOptimized, false); | ||
assert.equal(rawContentString, viewport); | ||
}); | ||
|
||
it('is not mobile optimized when HTML contains an invalid viewport meta tag key', async () => { | ||
const viewport = 'nonsense=true'; | ||
const {hasViewportTag, isMobileOptimized} = | ||
const {hasViewportTag, isMobileOptimized, rawContentString} = | ||
await ViewportMeta.compute_(makeMetaElements(viewport)); | ||
assert.equal(hasViewportTag, true); | ||
assert.equal(isMobileOptimized, false); | ||
assert.equal(rawContentString, viewport); | ||
}); | ||
|
||
it('is not mobile optimized when HTML contains an invalid viewport meta tag value', async () => { | ||
const viewport = 'initial-scale=microscopic'; | ||
const {isMobileOptimized, parserWarnings} = | ||
const {isMobileOptimized, parserWarnings, rawContentString} = | ||
await ViewportMeta.compute_(makeMetaElements(viewport)); | ||
assert.equal(isMobileOptimized, false); | ||
assert.equal(rawContentString, viewport); | ||
assert.equal(parserWarnings[0], 'Invalid values found: {"initial-scale":"microscopic"}'); | ||
}); | ||
|
||
/* eslint-disable-next-line max-len */ | ||
it('is not mobile optimized when HTML contains an invalid viewport meta tag key and value', async () => { | ||
const viewport = 'nonsense=true, initial-scale=microscopic'; | ||
const {isMobileOptimized, parserWarnings} = | ||
const {isMobileOptimized, parserWarnings, rawContentString} = | ||
await ViewportMeta.compute_(makeMetaElements(viewport)); | ||
assert.equal(isMobileOptimized, false); | ||
assert.equal(rawContentString, viewport); | ||
assert.equal(parserWarnings[0], 'Invalid properties found: {"nonsense":"true"}'); | ||
assert.equal(parserWarnings[1], 'Invalid values found: {"initial-scale":"microscopic"}'); | ||
}); | ||
|
||
// eslint-disable-next-line max-len | ||
it('is not mobile optimized when a viewport contains an initial-scale value lower than 1', async () => { | ||
const viewport = 'width=device-width, initial-scale=0.9'; | ||
const {isMobileOptimized} = | ||
const {isMobileOptimized, rawContentString} = | ||
await ViewportMeta.compute_(makeMetaElements(viewport)); | ||
assert.equal(isMobileOptimized, false); | ||
assert.equal(rawContentString, viewport); | ||
}); | ||
|
||
it('is mobile optimized when a valid viewport is provided', async () => { | ||
|
@@ -69,16 +74,20 @@ describe('ViewportMeta computed artifact', () => { | |
]; | ||
|
||
await Promise.all(viewports.map(async viewport => { | ||
const {isMobileOptimized} = | ||
const {isMobileOptimized, rawContentString} = | ||
await ViewportMeta.compute_(makeMetaElements(viewport)); | ||
assert.equal(isMobileOptimized, true); | ||
assert.equal(rawContentString, viewport); | ||
})); | ||
}); | ||
|
||
it('recognizes interactive-widget property', async () => { | ||
const viewport = 'width=device-width, interactive-widget=resizes-content'; | ||
const {parserWarnings} = await ViewportMeta.compute_(makeMetaElements(viewport)); | ||
assert.equal(parserWarnings[0], undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. driveby change of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I probably just copied it from the place you changed below 🤷 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const {parserWarnings, rawContentString} = | ||
await ViewportMeta.compute_(makeMetaElements(viewport)); | ||
assert.equal(rawContentString, viewport); | ||
assert.equal(parserWarnings.length, 0); | ||
assert.equal(rawContentString, viewport); | ||
}); | ||
|
||
it('doesn\'t throw when viewport contains "invalid" iOS properties', async () => { | ||
|
@@ -87,11 +96,11 @@ describe('ViewportMeta computed artifact', () => { | |
'width=device-width, viewport-fit=cover', | ||
]; | ||
await Promise.all(viewports.map(async viewport => { | ||
const {isMobileOptimized, parserWarnings} = | ||
const {isMobileOptimized, parserWarnings, rawContentString} = | ||
await ViewportMeta.compute_(makeMetaElements(viewport)); | ||
assert.equal(isMobileOptimized, true); | ||
assert.equal(parserWarnings[0], undefined); | ||
assert.equal(parserWarnings.length, 0); | ||
assert.equal(rawContentString, viewport); | ||
})); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's really important that we take the viewport
content
from the element (not parsed from the tag in the html) because site can and do change it.We already do this, but we don't currently have any test coverage for that fact :)
It probably makes sense for the terrible dbw page to have a weird viewport instead of a nice one, but doing so changes test expectations for way too many assertions, so it isn't worth the effort.