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

core: look up custom gatherer relative to the config file path #4751

Merged
merged 2 commits into from
Mar 15, 2018
Merged

Conversation

echopi
Copy link
Contributor

@echopi echopi commented Mar 14, 2018

No description provided.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
  • Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
  • The email used to register you as an authorized contributor must also be attached to your GitHub account.

@echopi echopi changed the title core: look up custom gatherer relative to the config file path as loo… look up custom gatherer relative to the config file path as looking up audit file Mar 14, 2018
@echopi
Copy link
Contributor Author

echopi commented Mar 14, 2018

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@echopi echopi changed the title look up custom gatherer relative to the config file path as looking up audit file look up custom gatherer relative to the config file path Mar 14, 2018
@paulirish
Copy link
Member

Thanks very much for the contribution! Appreciate it.
It's 7pm so we'll take a look tomorrow.

@echopi echopi changed the title look up custom gatherer relative to the config file path core: look up custom gatherer relative to the config file path Mar 14, 2018
@patrickhulce
Copy link
Collaborator

patrickhulce commented Mar 14, 2018

awesome thanks for the addition @echopi! would you mind adding a test for your use case? ours are covered by the existing ones but we want to make sure not to break you in the future without a heads up :)

it('loads a core gatherer', () => {
const gatherer = loadGatherer('viewport-dimensions');
assert.equal(gatherer.instance.name, 'ViewportDimensions');
assert.equal(typeof gatherer.instance.beforePass, 'function');
});
it('loads gatherers from custom paths', () => {
const customPath = path.resolve(__dirname, '../fixtures/valid-custom-gatherer');
const gatherer = loadGatherer(customPath);
assert.equal(gatherer.instance.name, 'CustomGatherer');
assert.equal(typeof gatherer.instance.beforePass, 'function');
});
it('returns gatherer when gatherer class, not package-name string, is provided', () => {
class TestGatherer extends Gatherer {}
const gatherer = loadGatherer(TestGatherer);
assert.equal(gatherer.instance.name, 'TestGatherer');
assert.equal(typeof gatherer.instance.beforePass, 'function');
});
it('throws when a gatherer is not found', () => {
assert.throws(_ => loadGatherer('/fake-non-existent-gatherer'), /locate gatherer/);
});
it('loads a gatherer from node_modules/', () => {
// Use a lighthouse dep as a stand in for a module.
assert.throws(_ => loadGatherer('mocha'), function(err) {
// Should throw a gatherer validation error, but *not* a gatherer not found error.
return !/locate gatherer/.test(err) && /beforePass\(\) method/.test(err);
});
});
it('loads a gatherer relative to the working directory', () => {
// Construct a gatherer URL relative to current working directory,
// regardless of where test was started from.
const absoluteGathererPath = path.resolve(__dirname, '../fixtures/valid-custom-gatherer');
assert.doesNotThrow(_ => require.resolve(absoluteGathererPath));
const relativeGathererPath = path.relative(process.cwd(), absoluteGathererPath);
const gatherer = loadGatherer(relativeGathererPath);
assert.equal(gatherer.instance.name, 'CustomGatherer');
assert.equal(typeof gatherer.instance.beforePass, 'function');
});

@echopi
Copy link
Contributor Author

echopi commented Mar 15, 2018

Done

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

thanks @echopi! 👍 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants