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

"TypeError: window.matchMedia" is not a function and "Error: Path contains invalid characters" #515

Closed
szulcus opened this issue Sep 21, 2023 · 1 comment

Comments

@szulcus
Copy link

szulcus commented Sep 21, 2023

I had problems with the module from the very beginning. Unfortunately, there is almost no information in the documentation on how to configure the module. I've searched all over the internet and still can't run the tests. Here are the things I did in a nutshell:

  • I installed a previous version of Vitest to make it compatible with the nuxt-vitest module
  • I defined the environment as jsdom
  • I configured the setup file to have access to window.matchMedia
  • I have specified that coverage should not take virtual nuxt into account

The testing module is still not working. What else should I do? Unfortunately, Stackblitz does not allow reproduction. Here is my configuration:

~/vitest.config.mjs

import { defineVitestConfig } from 'nuxt-vitest/config';
import { coverageConfigDefaults } from 'vitest/config';

export default defineVitestConfig({
	define: {
		'import.meta.vitest': 'undefined',
	},
	test: {
		dir: 'tests',
		testTimeout: 2000,
		globals: true,
		// includeSource: ['tests/**/*.nuxt.spec.ts'],
		coverage: {
			reporter: ['text', 'html'],
			exclude: [...coverageConfigDefaults.exclude, '**/virtual:nuxt:/**'],
		},
		environment: 'nuxt',
		environmentOptions: {
			nuxt: {
				domEnvironment: 'jsdom',
			},
		},
		setupFiles: ['./tests/setup.ts'],
		// reporters: 'dot',
	},
});

~/tests/setup.ts

import { Blob } from 'node:buffer';
import { afterEach, beforeAll, vi } from 'vitest';

console.log('--- setup ---');
Object.defineProperty(window, 'matchMedia', {
	writable: true,
	value: vi.fn().mockImplementation((query) => ({
		matches: false,
		media: query,
		onchange: null,
		addListener: vi.fn(), // deprecated
		removeListener: vi.fn(), // deprecated
		addEventListener: vi.fn(),
		removeEventListener: vi.fn(),
		dispatchEvent: vi.fn(),
	})),
});

beforeAll(() => {
	// @ts-expect-error
	globalThis.Blob = Blob;

	console.log('📝 Before all Setup...');
});

afterEach(() => {
	vi.clearAllMocks();
});

// // TypeError: window.matchMedia is not a function
// // https://github.com/vitest-dev/vitest/issues/821#issuecomment-1046954558
// console.log('---setup');

~/tests/components/F24Teest.nuxt.spec.ts

import { mountSuspended } from 'nuxt-vitest/utils';
import Teest from '~/components/Teest.vue';

it('can also mount an app', async () => {
	const component = await mountSuspended(Teest, { route: '/-tests' });
	expect(component.text()).toMatchInlineSnapshot('"..."');
});

~/components/Teest.vue

<script setup lang="ts">
	//
</script>

<template>
	<div class="teest">
		...
	</div>
</template>

~/pages/-test/index.vue

<script setup lang="ts">
	// Options
	defineOptions({ name: 'PageTests' });
</script>

<template>
	<div class="page-tests" />
</template>

Nuxi info:

  • Operating System: Windows_NT
  • Node Version: v16.19.0
  • Nuxt Version: 3.6.5
  • Nitro Version: 2.5.2
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: extends, app, imports, css, modules, vite, runtimeConfig, alias, build
  • Runtime Modules: nuxt-icon@0.2.11, nuxt-typed-router@3.2.5, nuxt-vitest@0.10.5, @nuxtjs/i18n@8.0.0-beta.10, @vite-pwa/nuxt@0.1.0
  • Build Modules: -

My output:

$ yarn test
yarn run v1.22.19
$ vitest --coverage
✔ #nuxt-layer-base types generated
✔ #nuxt-layer-icons types generated
✔ Router autocompletions generated 🚦

 DEV  v0.33.0 C:/Users/Jakub Schulz/Desktop/PRACA/SAT-TECH sp. z o.o/f24-admin
      Coverage enabled with v8

stdout | unknown test
<Suspense> is an experimental feature and its API will likely change.

stderr | unknown test
[nuxt] error caught during app initialization TypeError: window.matchMedia is not a function
    at C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\.nuxt\templates.pwa.client.d26fd198.ts:18:29
    at C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:112:60
    at fn (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:156:44)
    at Object.runWithContext (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:3855:18)
    at callWithNuxt (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:161:24)
    at Object.runWithContext (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:32:29)
    at applyPlugin (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:112:39)
    at Module.applyPlugins (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:125:21)
    at initApp (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\entry.js:55:7)
    at Object.setup (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\vitest-environment-nuxt\dist\index.mjs:125:5)
[nuxt] error caught during app initialization TypeError: $localePath is not a function
    at C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@frontend\nuxt-layer-base\middleware\f24-auth.global.ts:70:57
    at C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\pages\runtime\plugins\router.js:133:26 {
  statusCode: 500,
  fatal: false,
  unhandled: false,
  __nuxt_error: true
}
[Vue warn]: Unhandled error during execution of setup function
  at <Error error= TypeError: window.matchMedia is not a function
    at C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\.nuxt\templates.pwa.client.d26fd198.ts:18:29
    at C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:112:60
    at fn (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:156:44)
    at Object.runWithContext (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:3855:18)
    at callWithNuxt (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:161:24)
    at Object.runWithContext (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:32:29)
    at applyPlugin (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:112:39)
    at Module.applyPlugins (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:125:21)
    at initApp (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\entry.js:55:7)
    at Object.setup (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\vitest-environment-nuxt\dist\index.mjs:125:5) >
  at <Error key=0 error= TypeError: window.matchMedia is not a function
    at C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\.nuxt\templates.pwa.client.d26fd198.ts:18:29
    at C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:112:60
    at fn (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:156:44)
    at Object.runWithContext (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:3855:18)
    at callWithNuxt (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:161:24)
    at Object.runWithContext (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:32:29)
    at applyPlugin (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:112:39)
    at Module.applyPlugins (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\nuxt.js:125:21)
    at initApp (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\nuxt\dist\app\entry.js:55:7)
    at Object.setup (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\vitest-environment-nuxt\dist\index.mjs:125:5) >
  at <NuxtRoot>
[nuxt] error caught during app initialization SyntaxError: Need to install with `app.use` function
    at Module.createCompileError (file:///C:/Users/Jakub%20Schulz/Desktop/PRACA/SAT-TECH%20sp.%20z%20o.o/f24-admin/node_modules/@intlify/core-base/node_modules/@intlify/message-compiler/dist/message-compiler.mjs:54:19)
    at createI18nError (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\vue-i18n\dist\vue-i18n.runtime.mjs:97:34)
    at Module.useI18n (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\vue-i18n\dist\vue-i18n.runtime.mjs:2253:15)
    at Module.useLocalePath (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\vue-i18n-routing\dist\vue-i18n-routing.mjs:980:32)
    at Module.useLocalePath (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@nuxtjs\i18n\dist\runtime\composables.mjs:23:32)
    at setup (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@frontend\nuxt-layer-base\components\view\Error.vue:26:46)
    at callWithErrorHandling (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:156:18)
    at setupStatefulComponent (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7190:25)
    at setupComponent (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7151:36)
    at mountComponent (C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:5555:7) {
  code: 18,
  domain: undefined
}

stderr | unknown test
<empty line>
stdout | unknown test
--- setup ---

stderr | unknown test
<empty line>
stdout | unknown test
📝 Before all Setup...

 ✓ tests/components/F24Teest.nuxt.spec.ts (1)
   ✓ can also mount an app

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  12:25:44
   Duration  17.32s (transform 6.81s, setup 67ms, collect 703ms, tests 59ms, environment 15.81s, prepare 196ms)

 % Coverage report from v8
 % Coverage report from v8
-------------------------------------------------------------------------------------------------------|---------|----------|---------|---------|--------------------------------
File                                                                                                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------------------------------------------------------------------------------------|---------|----------|---------|---------|--------------------------------
All files                                                                                              |   43.38 |    28.02 |     6.7 |   43.38 | 
 f24-admin                                                                                             |     100 |      100 |     100 |     100 | 
  app.config.ts                                                                                        |     100 |      100 |     100 |     100 | 
  app.vue                                                                                              |     100 |      100 |     100 |     100 | 
 f24-admin/.nuxt                                                                                       |    2.04 |       25 |       0 |    2.04 | 
  app.config.mjs                                                                                       |     100 |      100 |     100 |     100 | 
  i18n.options.mjs                                                                                     |     0.5 |      100 |       0 |     0.5 | 9-2978
  templates.pwa.client.d26fd198.ts                                                                     |   29.41 |       25 |       0 |   29.41 | 26-41,48-49,51-68,72-74,80-136
 f24-admin/components                                                                                  |     100 |      100 |     100 |     100 | 
  Teest.vue                                                                                            |     100 |      100 |     100 |     100 | 
 f24-admin/components/f24/advanced                                                                     |     100 |      100 |     100 |     100 | 
  Cropper.vue                                                                                          |     100 |      100 |     100 |     100 | 
 f24-admin/components/f24/app/input                                                                    |     100 |      100 |     100 |     100 | 
  index.vue                                                                                            |     100 |      100 |     100 |     100 | 
 f24-admin/components/f24/loader                                                                       |     100 |      100 |     100 |     100 | 
  Mask.vue                                                                                             |     100 |      100 |     100 |     100 | 
 f24-admin/components/f24/modal                                                                        |     100 |      100 |       0 |     100 | 
  EditDetails.vue                                                                                      |     100 |      100 |     100 |     100 | 
  index.vue                                                                                            |     100 |      100 |       0 |     100 | 
 f24-admin/components/the/active-modals                                                                |     100 |      100 |     100 |     100 | 
  index.vue                                                                                            |     100 |      100 |     100 |     100 | 
 f24-admin/components/the/active-modals/organization                                                   |     100 |      100 |       0 |     100 | 
  General.vue                                                                                          |     100 |      100 |       0 |     100 | 
  index.vue                                                                                            |     100 |      100 |     100 |     100 | 
 f24-admin/components/the/active-modals/resource                                                       |     100 |      100 |     100 |     100 | 
  Attributes.vue                                                                                       |     100 |      100 |     100 |     100 | 
  General.vue                                                                                          |     100 |      100 |     100 |     100 | 
  Ssh.vue                                                                                              |     100 |      100 |     100 |     100 | 
  index.vue                                                                                            |     100 |      100 |     100 |     100 | 
 f24-admin/components/the/active-modals/user                                                           |     100 |      100 |       0 |     100 | 
  General.vue                                                                                          |     100 |      100 |       0 |     100 | 
  Organizations.vue                                                                                    |     100 |      100 |       0 |     100 | 
  index.vue                                                                                            |     100 |      100 |     100 |     100 | 
 f24-admin/composables                                                                                 |   23.88 |      100 |       0 |   23.88 | 
  useEditableFields.ts                                                                                 |   72.22 |      100 |       0 |   72.22 | 4-13
  useResources.ts                                                                                      |    6.12 |      100 |       0 |    6.12 | 5-96
 f24-admin/pages                                                                                       |   79.41 |      100 |       0 |   79.41 | 
  dashboard.vue                                                                                        |     100 |      100 |     100 |     100 | 
  index.vue                                                                                            |     100 |      100 |     100 |     100 | 
  organizations.vue                                                                                    |     100 |      100 |     100 |     100 | 
  settings.vue                                                                                         |   53.33 |      100 |       0 |   53.33 | 7-13                           
  users.vue                                                                                            |     100 |      100 |     100 |     100 | 
 f24-admin/pages/-tests                                                                                |     100 |      100 |     100 |     100 | 
  index.vue                                                                                            |     100 |      100 |     100 |     100 | 
 f24-admin/pages/resources                                                                             |     100 |      100 |     100 |     100 | 
  index.vue                                                                                            |     100 |      100 |     100 |     100 | 
 f24-admin/pages/resources/[type]                                                                      |   54.68 |      100 |       0 |   54.68 | 
  [subtype].vue                                                                                        |   52.63 |      100 |       0 |   52.63 | 19-36
  index.vue                                                                                            |   57.69 |      100 |       0 |   57.69 | 14-24
 f24-admin/plugins                                                                                     |   21.73 |      100 |     100 |   21.73 | 
  activeModals.ts                                                                                      |   21.73 |      100 |     100 |   21.73 | 6-23
 f24-admin/store                                                                                       |    5.17 |      100 |     100 |    5.17 | 
  root.ts                                                                                              |    5.17 |      100 |     100 |    5.17 | 4-58
 f24-admin/types                                                                                       |   93.67 |      100 |       0 |   93.67 | 
  api.ts                                                                                               |   91.47 |      100 |       0 |   91.47 | 7-16,21
  index.ts                                                                                             |     100 |      100 |     100 |     100 | 
 f24-admin/utils                                                                                       |   43.47 |      100 |       0 |   43.47 | 
  f24FlattenedQuery.ts                                                                                 |   41.66 |      100 |       0 |   41.66 | 15-35
  generateValuesFromApi.ts                                                                             |      50 |      100 |       0 |      50 | 4-8
 f24-admin/virtual:nuxt:C:/Users/Jakub Schulz/Desktop/PRACA/SAT-TECH sp. z o.o/f24-admin/.nuxt         |     100 |    27.27 |    7.73 |     100 | 
  app-component.mjs                                                                                    |     100 |      100 |       0 |     100 | 
  components.plugin.mjs                                                                                |     100 |      100 |     100 |     100 | 
  css.mjs                                                                                              |     100 |      100 |     100 |     100 | 
  error-component.mjs                                                                                  |     100 |      100 |     100 |     100 | 
  i18n.internal.mjs                                                                                    |     100 |      100 |       0 |     100 | 
  i18n.utils.mjs                                                                                       |     100 |      100 |       0 |     100 | 
  layouts.mjs                                                                                          |     100 |      100 |       0 |     100 | 
  middleware.mjs                                                                                       |     100 |      100 |      50 |     100 | 
  nitro.client.mjs                                                                                     |     100 |       80 |     100 |     100 | 1
  nuxt.config.mjs                                                                                      |     100 |      100 |   38.46 |     100 | 
  pages.mjs                                                                                            |     100 |      100 |       0 |     100 | 
  paths.mjs                                                                                            |     100 |      100 |       0 |     100 | 
  root-component.mjs                                                                                   |     100 |      100 |     100 |     100 | 
  router.options.mjs                                                                                   |     100 |      100 |     100 |     100 | 
  routes.mjs                                                                                           |     100 |     4.51 |    3.07 |     100 | 1
  vue-router.mjs                                                                                       |     100 |      100 |     100 |     100 | 
 f24-admin/virtual:nuxt:C:/Users/Jakub Schulz/Desktop/PRACA/SAT-TECH sp. z o.o/f24-admin/.nuxt/plugins |     100 |      100 |     100 |     100 | 
  client.mjs                                                                                           |     100 |      100 |     100 |     100 | 
-------------------------------------------------------------------------------------------------------|---------|----------|---------|---------|--------------------------------

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: Path contains invalid characters: C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\coverage\f24-admin\virtual:nuxt:C:\Users\Jakub Schulz\Desktop\PRACA\SAT-TECH sp. z o.o\f24-admin\.nuxt   
 ❯ checkPath node_modules/istanbul-lib-report/node_modules/make-dir/index.js:16:18
 ❯ AsyncFunction.module.exports.sync node_modules/istanbul-lib-report/node_modules/make-dir/index.js:107:2
 ❯ FileWriter.writeFile node_modules/istanbul-lib-report/lib/file-writer.js:184:16
 ❯ HtmlReport.onSummary node_modules/istanbul-reports/lib/html/index.js:364:44
 ❯ Visitor.value node_modules/istanbul-lib-report/lib/tree.js:38:38
 ❯ ReportNode.visit node_modules/istanbul-lib-report/lib/tree.js:86:21
 ❯ node_modules/istanbul-lib-report/lib/tree.js:92:19
 ❯ ReportNode.visit node_modules/istanbul-lib-report/lib/tree.js:91:28
 ❯ ReportTree.visit node_modules/istanbul-lib-report/lib/tree.js:127:24

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: {
  "code": "EINVAL",
}

I cleared the cache, reinstalled all modules and I still really have no idea what to do. I would be grateful for help 🙏.

@szulcus
Copy link
Author

szulcus commented Sep 26, 2023

Finally, after many hours, I managed to make a workaround for these errors. The problem was mainly in the nuxt virtual files and the @vite-pwa/nuxt module.

Workaround for "TypeError: window.matchMedia is not a function" error
In nuxt.config.ts:

export default defineNuxtConfig({
	// ...
	modules: [
		// ...
		process.env.NODE_ENV !== 'test' && ['@vite-pwa/nuxt', pwaOptions],
	],
});

Workaround for "Error: Path contains invalid characters" error
In vitest.config.mjs:

import { coverageConfigDefaults } from 'vitest/config';

export default defineVitestConfig({
	// ...
	test: {
		// ...
		coverage: {
			// ...
			exclude: [...coverageConfigDefaults.exclude, '**\\virtual:*'],
		},
	},
});

Thanks for: vitest-dev/vitest#3780, vitest-dev/vitest#3794

@szulcus szulcus closed this as completed Sep 26, 2023
@danielroe danielroe transferred this issue from danielroe/nuxt-vitest Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants