-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: support local plugins from global Lighthouse (#11696)
- Loading branch information
Showing
10 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* @license Copyright 2020 The Lighthouse Authors. 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'; | ||
|
||
/* eslint-env jest */ | ||
|
||
const {resolveModule} = require('../../config/config-helpers.js'); | ||
const assert = require('assert').strict; | ||
const path = require('path'); | ||
|
||
jest.mock('process', () => ({ | ||
cwd: () => jest.fn(), | ||
})); | ||
|
||
describe('resolveModule', () => { | ||
const configFixturePath = path.resolve(__dirname, '../fixtures/config'); | ||
|
||
beforeEach(() => { | ||
process.cwd = jest.fn(() => configFixturePath); | ||
}); | ||
|
||
it('lighthouse and plugins are installed in the same path', () => { | ||
const pluginName = 'chrome-launcher'; | ||
const pathToPlugin = resolveModule(pluginName, null, 'plugin'); | ||
assert.equal(pathToPlugin, require.resolve(pluginName)); | ||
}); | ||
|
||
describe('plugin paths to a file', () => { | ||
it('relative to the current working directory', () => { | ||
const pluginName = 'lighthouse-plugin-config-helper'; | ||
const pathToPlugin = resolveModule(pluginName, null, 'plugin'); | ||
assert.equal(pathToPlugin, require.resolve(path.resolve(configFixturePath, pluginName))); | ||
}); | ||
|
||
it('relative to the config path', () => { | ||
process.cwd = jest.fn(() => path.resolve(configFixturePath, '../')); | ||
const pluginName = 'lighthouse-plugin-config-helper'; | ||
const pathToPlugin = resolveModule(pluginName, configFixturePath, 'plugin'); | ||
assert.equal(pathToPlugin, require.resolve(path.resolve(configFixturePath, pluginName))); | ||
}); | ||
}); | ||
|
||
describe('lighthouse and plugins are installed by npm', () => { | ||
const pluginsDirectory = path.resolve(__dirname, '../fixtures/config/'); | ||
|
||
// working directory/ | ||
// |-- node_modules/ | ||
// |-- package.json | ||
it('in current working directory', () => { | ||
const pluginName = 'plugin-in-working-directory'; | ||
const pluginDir = `${pluginsDirectory}/node_modules/plugin-in-working-directory`; | ||
process.cwd = jest.fn(() => pluginsDirectory); | ||
|
||
const pathToPlugin = resolveModule(pluginName, null, 'plugin'); | ||
|
||
assert.equal(pathToPlugin, require.resolve(pluginName, {paths: [pluginDir]})); | ||
}); | ||
|
||
// working directory/ | ||
// |-- config directory/ | ||
// |-- node_modules/ | ||
// |-- config.js | ||
// |-- package.json | ||
it('relative to the config path', () => { | ||
const pluginName = 'plugin-in-config-directory'; | ||
const configDirectory = `${pluginsDirectory}/config`; | ||
process.cwd = jest.fn(() => '/usr/bin/node'); | ||
|
||
const pathToPlugin = resolveModule(pluginName, configDirectory, 'plugin'); | ||
|
||
assert.equal(pathToPlugin, require.resolve(pluginName, {paths: [configDirectory]})); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
extends: 'lighthouse:default', | ||
plugins: ['plugin-in-config-directory'], | ||
}; |
5 changes: 5 additions & 0 deletions
5
...use-core/test/fixtures/config/config/node_modules/plugin-in-config-directory/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
...tures/config/config/node_modules/plugin-in-config-directory/plugin-in-config-directory.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
lighthouse-core/test/fixtures/config/lighthouse-plugin-config-helper/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "lighthouse-plugin-config", | ||
"private": true, | ||
"main": "./plugin-config-helper.js" | ||
} |
25 changes: 25 additions & 0 deletions
25
lighthouse-core/test/fixtures/config/lighthouse-plugin-config-helper/plugin-config-helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @license Copyright 2020 The Lighthouse Authors. 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'; | ||
|
||
/** @type {LH.Config.Plugin} */ | ||
module.exports = { | ||
groups: { | ||
'new-group': { | ||
title: 'New Group', | ||
}, | ||
}, | ||
audits: [ | ||
{path: 'redirects'}, | ||
{path: 'user-timings'}, | ||
], | ||
category: { | ||
title: 'Config', | ||
auditRefs: [ | ||
{id: 'redirects', weight: 1, group: 'new-group'}, | ||
], | ||
}, | ||
}; |
5 changes: 5 additions & 0 deletions
5
lighthouse-core/test/fixtures/config/node_modules/plugin-in-working-directory/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
...t/fixtures/config/node_modules/plugin-in-working-directory/plugin-in-working-directory.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.