Skip to content

Add ability to define repo lists in a file outside of settings#1402

Merged
charisk merged 5 commits intomainfrom
charisk/external-repo-list
Jun 24, 2022
Merged

Add ability to define repo lists in a file outside of settings#1402
charisk merged 5 commits intomainfrom
charisk/external-repo-list

Conversation

@charisk
Copy link
Contributor

@charisk charisk commented Jun 23, 2022

Adds a new repositoryListsPath setting that allows users to define repository lists for MRVA outside of their settings.json file.

Checklist

N/A:

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@charisk charisk requested review from a team as code owners June 23, 2022 12:36
@charisk
Copy link
Contributor Author

charisk commented Jun 23, 2022

🤔 I have some tests that work fine if I have .only on the file but that cause failures when running with the rest of the suite. Something going on with the before/after hooks I think.

const repoListsFromSetings = readRepoListsFromSettings();
const repoListsFromExternalFile = await readExternalRepoLists();

return [...repoListsFromSetings, ...repoListsFromExternalFile];
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if a repo list from settings and a repo list from a file have the same name? Currently, they will both show indistinguishably. We probably don't want to merge them. It also probably shouldn't be an error.

So, if there's a duplicate, can you label them differently (eg- foo (from file) and foo (from settings)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The agreement with Product is that we'd do nothing for now in the case of duplicates and see how the feature is used (specially considering re-design work).

Comment on lines 182 to 184
let pathExistsStub: sinon.SinonStub;
let fsStatStub: sinon.SinonStub;
let fsReadFileStub: sinon.SinonStub;
Copy link
Contributor

Choose a reason for hiding this comment

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

The problem is that these stubs are not being used in the file where you expect them to.

The actual fs and path functions are being called. This is why when you run these tests separately they pass, but when you run as a whole, they fail.

To fix this, you need to pass the stubs in through the call to proxyquire. The default behaviour of proxyquire is to call through stubbed out modules so that the original function is called. What you would do is something like this:

  1. create mock fs and path instances (just empty objects initially)
  2. pass these into the call to proxyquire on line 23
  3. in the beforeEach block on line 187, add the stubs directly to the empty objects

I think this should work.

All this stuff is much easier to do using jest, but it's a big change to move from mocha to jest, so I think we're stuck.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for the write up! My eyes somehow completely glazed over the proxyrequire stuff 😬

The explanation makes sense (and works! 🎉) - only thing I don't get is why it'd work if I ran the tests on their own. I'll go away and do some reading around it. Thanks again!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it passed because somehow the tests were set up in a way that they would pass in a clean environment, but not one where other tests have already created state. I haven't looked at the details though.

@charisk charisk merged commit e6a68b3 into main Jun 24, 2022
@charisk charisk deleted the charisk/external-repo-list branch June 24, 2022 15:48
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.

3 participants