debian-image-builder-frontend/vitest.config.ts
Gianluca Zuccarelli 2b82fa3c4b tsconfig: cockpit plumbing
It was necessary to do a bit of plumbing to get typescript, webpack &
vitest all happy. To do this we had had to create a separate tsconfig
for the on-prem version and the service frontend.

We override the module resolution for both config files. For on-prem we
check modules in `pkg/lib` and for the service we resolve the modules to
stub functions of the `cockpit` & `cockpit/fsinfo` modules. This was so
typescript and webpack would not complain.

For on-prem we had to intruct webpack to resolve modules from both
`node_modules` and `pkg/lib`. While for the service we set the
resulotion for the two modules to false, which means they won't get
bundled with the service.

Lastly, we needed to set some aliases in the vitest config so that
vitest could resolve the `cockpit` & `cockpit/fsinfo` modules.

Using the cjs `require` keyword to import cockpit would have worked to
make typescript and webpack compile since these imports are not
statically analysed like the `import` keyword is. However, this approach
broke the tests as `require` imports are not supported in vitest.
2024-12-21 08:19:15 -06:00

46 lines
1.1 KiB
TypeScript

import react from '@vitejs/plugin-react';
import path from 'path';
const config = {
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./src/test/setup.ts'],
coverage: {
provider: 'v8',
},
server: {
deps: {
inline: ['vitest-canvas-mock', '@patternfly', '@monaco-editor'],
},
},
testTimeout: 10000,
fileParallelism: false,
exclude: ['./pkg/lib/**', '**/node_modules/**', '**/dist/**'],
},
reporters: ['default', 'junit'],
outputFile: {
junit: './coverage/junit.xml',
},
resolve: {
mainFields: ['module'],
alias: {
// we have to point vitest to the mocks for `cockpit` and `cockpit/fsinfo`
// by using aliases. This allows vitest to resolve these two packages
// and allows the tests to pass
cockpit: path.resolve(__dirname, 'src/test/mocks/cockpit'),
'cockpit/fsinfo': path.resolve(
__dirname,
'src/test/mocks/cockpit/fsinfo'
),
},
},
esbuild: {
loader: 'tsx',
include: /src\/.*\.[tj]sx?$/,
exclude: [],
},
};
export default config;