Runtime dir miss-calculated
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch @nuxt/[email protected] for the project I'm working on.
When starting nuxt test from a fresh install of test-utils I would get the following error:
ERROR Error: Failed to load url /Users/bahulneel/Projects/Hybr/app/packages/vetting/app/node_modules/@nuxt/test-utils/dist/shared/runtime/global-setup (resolved id: /Users/bahulneel/Projects/Hybr/app/packages/vetting/app/node_modules/@nuxt/test-utils/dist/shared/runtime/global-setup). Does the file exist?
I couldn't find any reference here, so I tracked down the cause. Here is the diff that solved my problem:
diff --git a/node_modules/@nuxt/test-utils/dist/config.d.mts b/node_modules/@nuxt/test-utils/dist/config.d.mts
index 385ec4b..5200673 100644
--- a/node_modules/@nuxt/test-utils/dist/config.d.mts
+++ b/node_modules/@nuxt/test-utils/dist/config.d.mts
@@ -1,4 +1,3 @@
-import * as vite from 'vite';
import { InlineConfig } from 'vite';
import { NuxtConfig, Nuxt } from '@nuxt/schema';
import { InlineConfig as InlineConfig$1 } from 'vitest';
diff --git a/node_modules/@nuxt/test-utils/dist/shared/test-utils.B57u8E0c.mjs b/node_modules/@nuxt/test-utils/dist/shared/test-utils.B57u8E0c.mjs
index 1a511b7..57b51cc 100644
--- a/node_modules/@nuxt/test-utils/dist/shared/test-utils.B57u8E0c.mjs
+++ b/node_modules/@nuxt/test-utils/dist/shared/test-utils.B57u8E0c.mjs
@@ -197,6 +197,6 @@ async function setup(options = {}) {
await setupFn(hooks);
}
-const distDir = dirname(fileURLToPath(import.meta.url));
+const distDir = dirname(fileURLToPath(import.meta.url + '/../'));
export { createPage as a, buildFixture as b, createBrowser as c, distDir as d, createTest as e, setup as f, getBrowser as g, loadFixture as l, setupMaps as s, waitForHydration as w };
This issue body was partially generated by patch-package.
This bug sill exists in 3.13.1, any update?
New user of Nuxt, trying to follow instructions in documentation for tests. I have the same error message. Had to downgrade to 3.11 to make it work, but this is quite a massive drop, since this version is not compatible with vitest 2.x:
"devDependencies": {
"@nuxt/test-utils": "~3.11.0",
"@testing-library/vue": "^8.1.0",
"@vue/test-utils": "^2.4.6",
"happy-dom": "^13.0.0",
"typescript": "^5.5.4",
"vitest": "^1.0.0",
"vue-tsc": "^2.0.29"
}
As a workaround, I was able to run the tests using just the vitest command. In fact, nuxt test is never mentioned in the documentation, I realized.. https://nuxt.com/docs/getting-started/testing#using-vuetest-utils