-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
new_audit: add js-libraries audit, just listing detected js libs #6081
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @license Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Diagnostic audit that lists all JavaScript libraries detected on the page | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Audit = require('../audit'); | ||
|
||
class JsLibrariesAudit extends Audit { | ||
/** | ||
* @return {LH.Audit.Meta} | ||
*/ | ||
static get meta() { | ||
return { | ||
id: 'js-libraries', | ||
title: 'Detected JavaScript libraries', | ||
description: 'All front-end JavaScript libraries detected on the page.', | ||
exterkamp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requiredArtifacts: ['JSLibraries'], | ||
}; | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts} artifacts | ||
* @return {LH.Audit.Product} | ||
*/ | ||
static audit(artifacts) { | ||
const libDetails = artifacts.JSLibraries.map(lib => ({ | ||
name: lib.name, | ||
version: lib.version, // null if not detected | ||
npm: lib.npmPkgName || null, // ~70% of libs come with this field | ||
})); | ||
|
||
const headings = [ | ||
{key: 'name', itemType: 'text', text: 'Name'}, | ||
{key: 'version', itemType: 'text', text: 'Version'}, | ||
]; | ||
const details = Audit.makeTableDetails(headings, libDetails, {}); | ||
|
||
return { | ||
rawValue: true, // Always pass for now. | ||
details, | ||
}; | ||
} | ||
} | ||
|
||
module.exports = JsLibrariesAudit; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const JsLibrariesAudit = require('../../../audits/dobetterweb/js-libraries.js'); | ||
const assert = require('assert'); | ||
|
||
/* eslint-env jest */ | ||
describe('Returns detected front-end JavaScript libraries', () => { | ||
it('always passes', () => { | ||
// no libraries | ||
const auditResult1 = JsLibrariesAudit.audit({ | ||
JSLibraries: [], | ||
}); | ||
assert.equal(auditResult1.rawValue, true); | ||
|
||
// duplicates. TODO: consider failing in this case | ||
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.
it's not that uncommon to have more than one jquery in one page. And if we merge network stuff from iframes, won't it be even more common? |
||
const auditResult2 = JsLibrariesAudit.audit({ | ||
JSLibraries: [ | ||
{name: 'lib1', version: '3.10.1', npmPkgName: 'lib1'}, | ||
{name: 'lib2', version: null, npmPkgName: 'lib2'}, | ||
], | ||
}); | ||
assert.equal(auditResult2.rawValue, true); | ||
|
||
// LOTS of frontend libs | ||
const auditResult3 = JsLibrariesAudit.audit({ | ||
JSLibraries: [ | ||
{name: 'React', version: null, npmPkgName: 'react'}, | ||
{name: 'Polymer', version: null, npmPkgName: 'polymer-core'}, | ||
{name: 'Preact', version: null, npmPkgName: 'preact'}, | ||
{name: 'Angular', version: null, npmPkgName: 'angular'}, | ||
{name: 'jQuery', version: null, npmPkgName: 'jquery'}, | ||
], | ||
}); | ||
assert.equal(auditResult3.rawValue, true); | ||
}); | ||
|
||
it('generates expected details', () => { | ||
const auditResult = JsLibrariesAudit.audit({ | ||
JSLibraries: [ | ||
{name: 'lib1', version: '3.10.1', npmPkgName: 'lib1'}, | ||
{name: 'lib2', version: null, npmPkgName: 'lib2'}, | ||
], | ||
}); | ||
const expected = [ | ||
{ | ||
name: 'lib1', | ||
npm: 'lib1', | ||
version: '3.10.1', | ||
}, | ||
{ | ||
name: 'lib2', | ||
npm: 'lib2', | ||
version: null, | ||
}, | ||
]; | ||
assert.equal(auditResult.rawValue, true); | ||
assert.deepStrictEqual(auditResult.details.items, expected); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ declare global { | |
|
||
export type DetailsItem = string | number | DetailsRendererNodeDetailsJSON | | ||
DetailsRendererLinkDetailsJSON | DetailsRendererCodeDetailJSON | undefined | | ||
boolean | DetailsRendererUrlDetailsJSON; | ||
boolean | DetailsRendererUrlDetailsJSON | null; | ||
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. details make me sad |
||
|
||
export interface DetailsRendererNodeDetailsJSON { | ||
type: 'node'; | ||
|
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.
2018