admin管理员组文章数量:1327750
I'm trying to run tests using Vitest on a Vue.js app that uses Element Plus registered as a plugin.
If I use mount
on a ponent that contains an Element Plus ponent, I get the following error:
TypeError: Unknown file extension ".scss" for /home/projects/vitejs-vite-zcdxhn/node_modules/element-plus/theme-chalk/src/button.scss
The issue can be replicated on this StackBlitz.
My vite.config.js file looks like this:
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import ElementPlus from 'unplugin-element-plus/vite';
export default defineConfig({
plugins: [vue(), ElementPlus({ useSource: true })],
});
My HelloWorld.vue ponent looks like this:
<script setup>
import { ElButton } from 'element-plus';
</script>
<template>
<el-button type="primary">Hello</el-button>
</template>
My HelloWorld.spec.js looks like this:
import { test, expect } from 'vitest';
import HelloWorld from '../HelloWorld.vue';
import { mount } from '@vue/test-utils';
test('hello world test', async () => {
const wrapper = mount(HelloWorld);
expect(wrapper.text()).toContain('Hello');
});
The seems to be specifically related to the ElementPlus({ useSource: true })]
"unplugin" in plugins
in vite.config.js because when I remove that, the problem goes away.
I've reviewed the docs for the various tools (Element Plus, Vite, Vitest), but I've not been able to find how to get this working.
Is there a custom test config that needs to be applied?
I'm trying to run tests using Vitest on a Vue.js app that uses Element Plus registered as a plugin.
If I use mount
on a ponent that contains an Element Plus ponent, I get the following error:
TypeError: Unknown file extension ".scss" for /home/projects/vitejs-vite-zcdxhn/node_modules/element-plus/theme-chalk/src/button.scss
The issue can be replicated on this StackBlitz.
My vite.config.js file looks like this:
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import ElementPlus from 'unplugin-element-plus/vite';
export default defineConfig({
plugins: [vue(), ElementPlus({ useSource: true })],
});
My HelloWorld.vue ponent looks like this:
<script setup>
import { ElButton } from 'element-plus';
</script>
<template>
<el-button type="primary">Hello</el-button>
</template>
My HelloWorld.spec.js looks like this:
import { test, expect } from 'vitest';
import HelloWorld from '../HelloWorld.vue';
import { mount } from '@vue/test-utils';
test('hello world test', async () => {
const wrapper = mount(HelloWorld);
expect(wrapper.text()).toContain('Hello');
});
The seems to be specifically related to the ElementPlus({ useSource: true })]
"unplugin" in plugins
in vite.config.js because when I remove that, the problem goes away.
I've reviewed the docs for the various tools (Element Plus, Vite, Vitest), but I've not been able to find how to get this working.
Is there a custom test config that needs to be applied?
Share Improve this question asked Jan 4, 2023 at 14:10 LondonAppDevLondonAppDev 9,6739 gold badges67 silver badges96 bronze badges3 Answers
Reset to default 3This issue still happens to me even with vitest 2.1.1 (with error related to css extension)
The solution is to set the pool option to use vmThreads or vmForks, like this:
test: {
pool: "vmThreads",
},
With this option, the following option deps.web.transformCss
will be set to true by default, which will resolve the problem
In my situation, it fixed by add deps.inline: ['element-plus']
in vitest config
References:
Unknown file extension ".css" when using with unplugin-vue-ponents · Issue #1388 · vitest-dev/vitest · GitHub
Configuring Vitest | Vitest
vitest: '^0.34.3'
Vitest "deps.inline" is deprecated. If you rely on vite-node directly, use "server.deps.inline" instead. Otherwise, consider using "deps.optimizer.web.include"
deps: {
optimizer: {
web: {
include: ['element-plus']
}
}
}
It's works for me
本文标签: javascriptVitest with element plus unplugin unknown extension for scssStack Overflow
版权声明:本文标题:javascript - Vitest with element plus unplugin unknown extension for scss - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742233023a2437569.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论