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

feat(testing): add migration for moving test target defaults #19993

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

FrozenPandaz
Copy link
Collaborator

Current Behavior

There is no migration for the changes in #19963. New projects will be created without the settings without a targetDefault set.

Expected Behavior

There is a migration to move the target defaults and options to the target defaults. New projects will still have those settings set. A lot of configuration will be removed from project.json files in the process. 🎉

Related Issue(s)

Fixes #

Copy link

vercel bot commented Nov 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Nov 2, 2023 8:29pm

@FrozenPandaz FrozenPandaz force-pushed the jest-migration branch 2 times, most recently from 59c4ee3 to 452443e Compare November 2, 2023 13:22
@FrozenPandaz FrozenPandaz marked this pull request as ready for review November 2, 2023 14:09
@FrozenPandaz FrozenPandaz requested review from a team as code owners November 2, 2023 14:09
@FrozenPandaz FrozenPandaz requested a review from jaysoo November 2, 2023 14:09
@FrozenPandaz FrozenPandaz force-pushed the jest-migration branch 2 times, most recently from c9757e5 to e47b7c0 Compare November 2, 2023 15:24
@FrozenPandaz FrozenPandaz changed the title feat(testing): add migration for moving test target defautls feat(testing): add migration for moving test target defaults Nov 2, 2023
export default async function update(tree: Tree) {
const nxJson = readNxJson(tree);

// Don't override anything if there are already target defaults for jest
Copy link
Member

Choose a reason for hiding this comment

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

Nit: s/jest/vitest/

)) {
// If every target in every project does not use the target default anymore, it can be removed.
if (
Object.values(projects).every((p) =>
Copy link
Member

@jaysoo jaysoo Nov 2, 2023

Choose a reason for hiding this comment

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

Minor: It's a migration so not too worried about maintenance, but I find the long, nested every hard to grok. Would it better to use nested for-loops?

for (const [targetDefaultKey, targetDefault] of Object.entries(
  nxJson.targetDefaults
)) {
  let isDefaultUsed = false;
  for (const p of Object.values(projects)) {
    for (const targetName of Object.keys(p.data?.targets ?? {})) {
      const defaults = readTargetDefaultsForTarget(
        targetName,
        nxJson.targetDefaults,
        projectMap.get(p.name).targets?.[targetName]?.executor
      );
      if (defaults === targetDefault) {
        isDefaultUsed = true;
        break;
      }
    }
  }
  if (!isDefaultUsed) {
    delete nxJson.targetDefaults[targetDefaultKey];
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I agree.

if (value.passWithNoTests === jestDefaults.options.passWithNoTests) {
delete projConfig.targets[targetName].options.passWithNoTests;
} else {
projConfig.targets[targetName].options.passWithNoTests ??= false;

This comment was marked as resolved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. Now I don't change the value when one was set in target defaults.

@FrozenPandaz FrozenPandaz merged commit b0d1799 into nrwl:master Nov 2, 2023
@FrozenPandaz FrozenPandaz deleted the jest-migration branch November 2, 2023 21:22
Copy link

github-actions bot commented Nov 8, 2023

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants