naxodev / oss

Open Source Software (OSS) projects by naxodev
https://naxo.dev
MIT License
19 stars 1 forks source link

[nx-cloudflare] suggestion: test executor/command from NX #39

Closed mnlbox closed 5 months ago

mnlbox commented 5 months ago

Current Behavior

Currently we need to move to the project directory and run the test command manually and as it's normal vitest commands it means there is no NX caching applied to the test command.

Expected Behavior

I think it can be a nice improvement to add a "test" executor to the project. In this case we don't need the code below in the package.json file:

"scripts": {
    "test": "vitest run"
  }

And we can use something like this:

nx test <my-app>

GitHub Repo

No response

Steps to Reproduce

1.

Nx Report

-

Failure Logs

No response

Operating System

Additional Information

No response

NachoVazquez commented 5 months ago

Nx will combine any executor from the project.json with scripts on package.json. In this case, you should be able to run nx test <project-name>, which should work.

However, if you have the @nx/vite plugin installed (using Crystal), you can remove the script, which should also work.

I remember adding it because it was not working with the official Nx executor, but I believe that might have changed with Crystal.

NachoVazquez commented 5 months ago

Hi @mnlbox, I swapped the tests to use the Vitest Crystal plugin. It should work a lot better now.

Everything is released in version 2.1.0 including the previous fixes.

NachoVazquez commented 5 months ago

Hey @mnlbox, if you have some time, could you please confirm if this and the other fixes are working for you? Thank you!

mnlbox commented 5 months ago

Hi @NachoVazquez ,

Sorry for the late reply. Sure I'll check everything in the new version today and update you here 😉

mnlbox commented 5 months ago

Hi @NachoVazquez ,

I tried to use the new test command but I'm getting this error:

pnpm nx run service-test:test

 NX   The externalDependency 'vitest' for 'service-test:test' could not be found

Pass --verbose to see the stacktrace.

service-test is the name of my project. I also have the vitest package installed as a devDependency. "vitest": "~1.4.0", should I install anything else?

NachoVazquez commented 5 months ago

Interesting. I will take a look at this. Did you use the flag --unitTestRunner=vitest when creating the application?

NachoVazquez commented 5 months ago

I could generate and run a new project correctly; this fix works only for newly generated projects. If you want to apply these changes to an existing project, use the Nx vite plugin.

mnlbox commented 5 months ago

No it wasn't an old project. I just updated my plugin and then created a totally new project called service-testwith the command below, and ran the test command:

pnpm nx generate @naxodev/nx-cloudflare:application --name service-test --template hono --directory services/test --port 4001 --projectNameAndRootFormat=as-provided

And this is the result of pnpm nx show project service-test --web command:

image

I can retry with --unitTestRunner=vitest flag but as far as I undrestand it's the default value.

NachoVazquez commented 5 months ago

Awesome! Yes I think it is lol