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(vite): add angular option to vitest generator #29055

Merged

Conversation

yjaaidi
Copy link
Contributor

@yjaaidi yjaaidi commented Nov 25, 2024

Current Behavior

@nx/vite:vitest generator does not provide Angular support in the uiFramework options.

Expected Behavior

angular option should generate the vitest configuration just like @nx/angular:application and @nx/angular/library do.

@yjaaidi yjaaidi requested review from a team as code owners November 25, 2024 10:33
Copy link

vercel bot commented Nov 25, 2024

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

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Dec 11, 2024 10:09am

@yjaaidi
Copy link
Contributor Author

yjaaidi commented Nov 25, 2024

@nx/vite:vitest's uiFramework should be required but that would be a breaking change. Should I add it here or should we keep this for the next major?

@yjaaidi
Copy link
Contributor Author

yjaaidi commented Nov 25, 2024

In order to improve tests maintainability and symmetry to production, I would love to replace fixtures like these: https://github.com/nrwl/nx/blob/8738d10446f17df7f9f30e3c94e509062feb0df2/packages/vite/src/utils/test-utils.ts

with reusable "object mothers" in testing utils:

const workspace = workspaceMother.withInferenceDisabled().build();
const app = angularAppMother.withName('my-app').withJestSetup().withSomeTests().build();
const lib = angularLibMother.withName('my-lib').build(); // no test config & no tests

createWorkspace(workspace);
createProjects([app, lib])

What do you think?

Copy link
Collaborator

@isaacplmann isaacplmann left a comment

Choose a reason for hiding this comment

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

Docs changes approved

Copy link
Contributor

@Coly010 Coly010 left a comment

Choose a reason for hiding this comment

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

Looks good, and testing it out locally worked fine.

One addressable comment, another is more thought-provoking but doesn't need to be solved.

packages/vite/src/generators/vitest/vitest.spec.ts Outdated Show resolved Hide resolved
packages/vite/src/generators/vitest/vitest-generator.ts Outdated Show resolved Hide resolved
project.targets[target].executor = '@nx/vite:test';
delete project.targets[target].options?.jestConfig;
if (hasPlugin) {
delete project.targets[target];
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a new behavior. AFAICT, we currently don't delete a potentially previously existing target. Is this intended?

I don't think the generator should silently delete the target. It should error so the user knows there's an existing target that will override the inferred task and make the appropriate change.

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 think that I've implemented the generator a bit too much like a migration.

I'll turn this into an error.

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 just fixed this.

What should we do when vite plugin is enabled?
Should it error too if an existing target is shadowing vitest's test target?

While it is straightforward to handle this for vite plugin, what should we do for other plugins, like Nuxt?

packages/angular/src/utils/versions.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@Coly010 Coly010 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! LGTM

@Coly010 Coly010 force-pushed the test/add-angular-vitest-config-generator branch 3 times, most recently from 34fd8a9 to a479740 Compare December 9, 2024 10:31
@Coly010 Coly010 force-pushed the test/add-angular-vitest-config-generator branch from eb05588 to 7f95785 Compare December 10, 2024 20:45
test(vitest): reorganize tests

chore(vite): move angular plugin install to vitest generators

chore(vite): move angular vite setup to vitest generator

chore(vite): vite configuration generator does not handle angular

because vitest generator does

feat(vite): add angular option to vitest generator

chore(vite): fix internal typing

chore(vite): do not generate superfluous vite config

chore(vite): tidy up

chore(vite): add test ideas for vitest test target

chore(vite): add tests for vitest test targets

feat(vite): remove previous test target if inference is enabled

chore(vite): refactor test to let the default addPlugin behavor express itself

chore(vite): align tests with default coverage provider

chore(vite): resurrect mistakenly removed option

Revert "chore(vite): refactor test to let the default addPlugin behavor express itself"

This reverts commit 3003325.

chore(angular): remove old mentions of analogVitestAngular version

feat(vite): do not overwrite test target if it already exists

feat(vite): add angular detection to vitest configuration generator

feat(vite): add react detection to vitest configuration generator

feat(vite): improve angular/react framework detection

docs(vite): remove default value for uiFramework in vitest configuration

feat(vite): update analogjs vitest angular in correct location
@Coly010 Coly010 force-pushed the test/add-angular-vitest-config-generator branch from 7f95785 to 578b0b1 Compare December 11, 2024 10:00
@Coly010 Coly010 merged commit 77dc090 into nrwl:master Dec 11, 2024
6 checks passed
Copy link

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 Dec 18, 2024
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.

4 participants