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

fix: add check for keepRemoved in failOnUpdate #907

Closed
wants to merge 4 commits into from

Conversation

cravend
Copy link

@cravend cravend commented Sep 12, 2023

Why am I submitting this PR

This issue adds a check for keepRemoved in the calculation of the files changed for failOnUpdate.

Does it fix an existing ticket?

Yes #666

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • tests are included and pass: yarn test (see details here)
  • documentation is changed or added

@karellm
Copy link
Member

karellm commented Sep 13, 2023

@cravend Thanks a lot for the PR. The fix looks good but can you please add a test to document the change?

@codecov-commenter
Copy link

Codecov Report

Patch has no changes to coverable lines.

Files Changed Coverage
src/transform.js 0.00%

📢 Thoughts on this report? Let us know!.

@cravend
Copy link
Author

cravend commented Sep 15, 2023

@karellm sure, but I don't see anywhere that any of the transform is tested. Where should I add the test?

@karellm
Copy link
Member

karellm commented Sep 15, 2023

@RobHannay
Copy link
Contributor

Just encountered this issue myself! Thanks @cravend. Shout if you want a hand finishing this PR

src/transform.js Outdated
Comment on lines 281 to 282
const unreferencedCount = this.options.keepRemoved ? oldCount : 0;
if (addCount + restoreCount + oldCount - unreferencedCount !== 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't account for when keepRemoved is not a boolean. We use a regex to match 'common' namespace translations, so that parsing any package in our repo doesn't remove old common: translations.

  keepRemoved: [/^common:/],

Copy link
Member

Choose a reason for hiding this comment

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

@RobHannay Feel free to open a new PR with proper testing.

@cravend
Copy link
Author

cravend commented Oct 25, 2023

Hi all, sorry for my delayed response. I've just reworked the logic to handle when keepRemoved is a regex. I tested locally (yarn link, running it inside/outside of a regex match, as well as with/without a "changed" translation), and the behavior seemed correct to me.

However, I had trouble writing tests for it, because it exits with code 1 and mocha interprets that as a failure and exits itself. I don't know enough about this testing framework to know how to ignore the exit code and continue the tests, but I wanted to push up a WIP to see if @RobHannay or @karellm either of you knew how to fix this. The tests aren't great (I created all test cases but didn't elaborate on them once I realized the issue with process.exit()).

@karellm
Copy link
Member

karellm commented Oct 29, 2023

@cravend You can get some inspiration here: https://github.com/i18next/i18next-parser/pull/932/files

@karellm
Copy link
Member

karellm commented Dec 24, 2023

Closing in favour of #948

@karellm karellm closed this Dec 24, 2023
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.

4 participants