Skip to content

Conversation

@muffinresearch
Copy link
Contributor

Fixes #1450
Fixes #1391 (it made testing easier)

It found a couple of real issues:

  • There was a broken regex which would match browser/components/extensions/schemas/lkfjghdsfhskdjhfjson and not just browser/components/extensions/schemas/lkfjghdsfhskdjhf.json
  • There's a test that had a bad loop I've commented out the data that doesn't validate - it's a schema test and I will call it out in the diff where possible. This one will need a bug filed to fix up in due course.

A lot of the noise is spaces around { etc.
The bigger changes were changes to a lot of the loops to move away from for..in and for..of.

There's a lot of changes here so it'll be worth trying to be diligent with review incase something got broken in the process.

@muffinresearch muffinresearch requested a review from EnTeQuAk August 8, 2017 17:00
'https://foo.com',
'ftp://do.people.still.use.this',
'app://wat',
// FIXME: the loop in this test was previously broken.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the bad loop that needs a bug filing to fix. The matchPattern seen in the test was always the last value in the list.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 9785d4a on muffinresearch:configure-amo-eslint-config into e50c28c on mozilla:master.

Copy link
Contributor

@EnTeQuAk EnTeQuAk left a comment

Choose a reason for hiding this comment

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

r+wc

"test": "jest tests/ --runInBand --coverage",
"test-no-coverage": "jest tests/ --runInBand",
"test-ci": "npm run test && cat ./coverage/lcov.info | coveralls",
"test": "jest tests/ --runInBand --watch",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm honestly not a fan of a default watch, can we maybe not do that? At least on my machine it's a constant memory leak

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be good to get to the bottom of why that is. Not using watch defeats one of the best features of Jest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose one of the other goals I was aiming for was to try and make the test command setup more consistent between addons-frontend and addons-linter since that's another difference we can eliminate.

If I added the test-once command would that provide what you need? See https://github.com/mozilla/addons-frontend/#development-commands for more details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added yarn test-once and test-coverage-once.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect, thanks a lot! I think that works for me.


checkPath(path) {
if (!this.files.hasOwnProperty(path)) {
if (!Object.prototype.hasOwnProperty.call(this.files, path)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for (let v in values) {
const valuesKeys = Object.keys(values);
for (let i = 0; i < valuesKeys.length; i++) {
const v = valuesKeys[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

why no forEach here?

Copy link
Contributor Author

@muffinresearch muffinresearch Aug 10, 2017

Choose a reason for hiding this comment

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

Because there's no way to break out of a forEach without throwing.

Thinking about it this is probably something where we could be using https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some

It could probably be re-written as:

if (Object.keys(values).some((v) => values[v] !== buffer[v])) {
  return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to switch this to use Array.prototype.some. It's purpose built for this use-case.

new RegExp('browser/components/extensions/schemas/.*\.json'),
new RegExp('toolkit/components/extensions/schemas/.*\.json'),
new RegExp('browser/components/extensions/schemas/.*\\.json'),
new RegExp('toolkit/components/extensions/schemas/.*\\.json'),
Copy link
Contributor

Choose a reason for hiding this comment

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

great catch!

for (var part of parts) {

for (let i = 0; i < parts.length; i++) {
let part = parts[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

also no forEach here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same reason as before.


describe('Xpi.getFilesByExt()', function() {

describe('Xpi.getFilesByExt()', function getFilesByExtCallback() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are they named now? Can't we just use lambdas here as well, afair we do that quite often in other tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the lint rules prevents unnamed functions. In our tests we have a few places where we rely on this, and the semantics of a fat arrow breaks that code from working . We should probably look at refactoring those tests and set consts instead of relying on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, you could just create a nested ./tests/.eslintrc which disables that one unnamed function rule, and all the other rules from the root .eslintrc file would still be inherited.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pdehaan If we end up concluding we don't need the rule I'd rather disable it centrally in the shared config since we're trying to make our config more consistent across repos. Of course there might be some cases where we do need overrides but we'd probably want to keep that to an absolute minimum.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling ba4dcbc on muffinresearch:configure-amo-eslint-config into e50c28c on mozilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 1a809b5 on muffinresearch:configure-amo-eslint-config into e50c28c on mozilla:master.

@muffinresearch
Copy link
Contributor Author

@EnTeQuAk if you're happy with this and want to land it feel free to go ahead and squash/merge it. Otherwise we can fix up any additional bits next week.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 3056883 on muffinresearch:configure-amo-eslint-config into 80e68d9 on mozilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 6c379cf on muffinresearch:configure-amo-eslint-config into 91a89f5 on mozilla:master.

@EnTeQuAk EnTeQuAk merged commit 6109428 into mozilla:master Aug 11, 2017
@EnTeQuAk
Copy link
Contributor

Thank you so much for the explanations and work that went into this! This is looking great :)

So I just merged this, if there's anything else that needs to be done I'm sure we can easily do it in a separate PR.

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.

Use the amo eslint config yarn test should run watch and not coverage by default

4 participants