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

In browser mode, aliases in the test section of vite.config are ignored #3086

Closed
6 tasks done
dospunk opened this issue Mar 27, 2023 · 0 comments · Fixed by #3040
Closed
6 tasks done

In browser mode, aliases in the test section of vite.config are ignored #3086

dospunk opened this issue Mar 27, 2023 · 0 comments · Fixed by #3040
Labels
feat: browser Issues and PRs related to the browser runner

Comments

@dospunk
Copy link

dospunk commented Mar 27, 2023

Describe the bug

When using browser mode, aliases that are defined in the vite config's resolve.alias section work as expected but aliases defined in test.alias throw an error as if they are packages that have not been installed.

vite config example:

/// <reference types="vitest" />

import { defineConfig } from 'vite';
import { resolve } from 'path';

function pathResolve(dir: string) {
  return resolve(process.cwd(), '.', dir);
}

export default defineConfig({
  resolve: {
    // works
    alias: [{ find: /@src\//, replacement: pathResolve('src') + '/' }],
  },
  test: {
    browser: { enabled: true },
    // fails
    alias: [{ find: /@tests\//, replacement: pathResolve('test') + '/' }],
  },
});

output example:

Error: The following dependencies are imported but could not be resolved:

  @tests/testUtils (imported by path/to/the/test.ts)

Are they installed?

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-rb4nqu?file=vite.config.ts

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
    Memory: 7.92 GB / 15.78 GB
  Binaries:
    Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (111.0.1661.54)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    @vitest/browser: ^0.29.7 => 0.29.7
    @vitest/ui: latest => 0.29.7
    vite: latest => 4.2.1
    vitest: latest => 0.29.7

Used Package Manager

npm

Validations

@Aslemammad Aslemammad added bug feat: browser Issues and PRs related to the browser runner labels Mar 27, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: browser Issues and PRs related to the browser runner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants