[go: nahoru, domu]

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(font-size): add test for attributing styles to node #9400

Merged
merged 8 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion lighthouse-core/gather/gatherers/seo/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async function fetchSourceRule(driver, node) {

/**
* @param {Driver} driver
* @param {LH.Artifacts.FontSize.DomNodeWithParent} textNode text node
* @param {LH.Artifacts.FontSize.DomNodeWithParent} textNode
* @returns {Promise<?NodeFontData>}
*/
async function fetchComputedFontSize(driver, textNode) {
Expand Down
45 changes: 44 additions & 1 deletion lighthouse-core/test/audits/seo/font-size-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
const FontSizeAudit = require('../../../audits/seo/font-size.js');
const assert = require('assert');

const URL = 'https://example.com';
const URL = {
requestedUrl: 'https://example.com',
finalUrl: 'https://example.com',
};
const validViewport = 'width=device-width';

/* eslint-env jest */
Expand Down Expand Up @@ -234,4 +237,44 @@ describe('SEO: Font size audit', () => {
expect(auditResult.score).toBe(1);
expect(auditResult.notApplicable).toBe(true);
});

it('attributes inline and attributes styles to node', async () => {
const style1 = {
type: 'Inline',
};
const style2 = {
type: 'Attributes',
};
const parentNode = {
attributes: ['id', 'my-parent'],
};
const artifacts = {
URL,
MetaElements: makeMetaElements(validViewport),
FontSize: {
analyzedFailingNodesData: [
{textLength: 12, fontSize: 10, cssRule: style1,
node: {nodeId: 1, parentNode, localName: 'p', attributes: ['class', 'my-p']}},
{textLength: 11, fontSize: 10, cssRule: style2,
node: {nodeId: 2, parentNode, localName: 'font', attributes: ['size', '10px']}},
],
},
TestedAsMobileDevice: true,
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh my gosh wait yeah this file is completely different!

I'm sorry @connorjclark I got confused between two different font-size-test changes and approved this immediately after looking at the other one, too many reviews today my b 😢

Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a separate review ongoing with runFontSizeAuditWithSingleFailingStyle...

Copy link
Collaborator

Choose a reason for hiding this comment

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

you even tried to warn me over chat and it didn't work! 😆

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope, this was it.

Copy link
Member

Choose a reason for hiding this comment

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

nope, this was it.

there was one in #9354, though? #9400 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes... and I moved it here and asked patrick to review over chat :) a flawless system as you see

const auditResult = await FontSizeAudit.audit(artifacts, getFakeContext());
assert.equal(auditResult.details.items.length, 2);
assert.equal(auditResult.details.items[0].source, URL.finalUrl);
Copy link
Collaborator

Choose a reason for hiding this comment

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

expect(auditResult.details.items).toMatchObject

for the new stuff? :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

Also, I grabbed the describe fn I made in #9354 and moved it here. 1) will make the other review smaller 2) doing the same stuff here.

assert.deepEqual(auditResult.details.items[0].selector, {
type: 'node',
selector: '#my-parent',
snippet: '<p class="my-p">',
});
assert.equal(auditResult.details.items[1].source, URL.finalUrl);
assert.deepEqual(auditResult.details.items[1].selector, {
type: 'node',
selector: '#my-parent',
snippet: '<font size="10px">',
});
});
});
1 change: 1 addition & 0 deletions types/artifacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ declare global {
failingTextLength: number;
visitedTextLength: number;
analyzedFailingTextLength: number;
/** Elements with a text node that failed size criteria. */
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
analyzedFailingNodesData: Array<{
fontSize: number;
textLength: number;
Expand Down