Files
api/web/nuxt.config.ts
Michael Datelle 0e008aaf1e test: setup initial test, config and testing libraries (#1309)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced comprehensive testing utilities for Vue components
utilizing the composition API.
- Enhanced testing coverage for the `DownloadApiLogs` and `KeyActions`
components, ensuring robust functionality and user interaction
validation.
- Added mock implementations for various libraries and components to
facilitate isolated unit testing.
- Improved flexibility in the `DummyServerSwitcher` component's input
handling.
- Added a new test setup file to configure the testing environment for
Vue applications.
- Added new test files for `AuthComponent` and `KeyActions` with
comprehensive test cases.
- Introduced a new mock implementation for UI components to streamline
testing.
- Added a new mock implementation for the `useRequest` composable to
prevent hanging issues during tests.
- Added a new mock implementation for the server store used by the Auth
component.

- **Bug Fixes**
- Improved sanitization process to block inline styles for a safer and
more consistent display.

- **Documentation**
- Added README documentation for Vue Component Testing Utilities,
detailing usage and examples.
  - Updated ESLint configuration to ignore coverage directory files.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: mdatelle <mike@datelle.net>
Co-authored-by: Eli Bosley <ekbosley@gmail.com>
2025-04-03 15:50:49 -04:00

157 lines
3.9 KiB
TypeScript

import removeConsole from 'vite-plugin-remove-console';
/**
* Used to avoid redeclaring variables in the webgui codebase.
* @see alt solution https://github.com/terser/terser/issues/1001, https://github.com/terser/terser/pull/1038
*/
function terserReservations(inputStr: string) {
const combinations = ['ace'];
// Add 1-character combinations
for (let i = 0; i < inputStr.length; i++) {
combinations.push(inputStr[i]);
}
// Add 2-character combinations
for (let i = 0; i < inputStr.length; i++) {
for (let j = 0; j < inputStr.length; j++) {
combinations.push(inputStr[i] + inputStr[j]);
}
}
return combinations;
}
const charsToReserve = '_$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devServer: {
port: 4321,
},
devtools: {
enabled: process.env.NODE_ENV === 'development',
},
modules: [
'@vueuse/nuxt',
'@pinia/nuxt',
'@nuxtjs/tailwindcss',
'nuxt-custom-elements',
'@nuxt/eslint',
],
// Properly handle ES modules in testing and build environments
build: {
transpile: [/node_modules\/.*\.mjs$/],
},
ignore: ['/webGui/images'],
components: [
{ path: '~/components/Brand', prefix: 'Brand' },
{ path: '~/components/ConnectSettings', prefix: 'ConnectSettings' },
{ path: '~/components/UserProfile', prefix: 'Upc' },
{ path: '~/components/UpdateOs', prefix: 'UpdateOs' },
'~/components',
],
vite: {
plugins: [
// Only remove non-critical console methods when VITE_ALLOW_CONSOLE_LOGS is false
// Keeps console.warn and console.error for debugging purposes
!process.env.VITE_ALLOW_CONSOLE_LOGS &&
removeConsole({
includes: ['log', 'info', 'debug'],
}),
],
define: {
'globalThis.__DEV__': process.env.NODE_ENV === 'development',
__VUE_PROD_DEVTOOLS__: false,
},
build: {
minify: 'terser',
terserOptions: {
mangle: {
reserved: terserReservations(charsToReserve),
toplevel: true,
},
},
},
},
customElements: {
entries: [
{
name: 'UnraidComponents',
tags: [
{
name: 'UnraidI18nHost',
path: '@/components/I18nHost.ce',
},
{
name: 'UnraidAuth',
path: '@/components/Auth.ce',
},
{
name: 'UnraidConnectSettings',
path: '@/components/ConnectSettings/ConnectSettings.ce',
},
{
name: 'UnraidDownloadApiLogs',
path: '@/components/DownloadApiLogs.ce',
},
{
name: 'UnraidHeaderOsVersion',
path: '@/components/HeaderOsVersion.ce',
},
{
name: 'UnraidModals',
path: '@/components/Modals.ce',
},
{
name: 'UnraidUserProfile',
path: '@/components/UserProfile.ce',
},
{
name: 'UnraidUpdateOs',
path: '@/components/UpdateOs.ce',
},
{
name: 'UnraidDowngradeOs',
path: '@/components/DowngradeOs.ce',
},
{
name: 'UnraidRegistration',
path: '@/components/Registration.ce',
},
{
name: 'UnraidWanIpCheck',
path: '@/components/WanIpCheck.ce',
},
{
name: 'UnraidWelcomeModal',
path: '@/components/WelcomeModal.ce',
},
{
name: 'UnraidSsoButton',
path: '@/components/SsoButton.ce',
},
{
name: 'UnraidLogViewer',
path: '@/components/Logs/LogViewer.ce',
},
{
name: 'UnraidThemeSwitcher',
path: '@/components/ThemeSwitcher.ce',
},
],
},
],
},
compatibilityDate: '2024-12-05',
ssr: false,
});