mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +02:00

* Creates a utility method `jsdomIt` that overrides `it` from `vitest` and fakes a browser environment by : * Creating a DOM with `jsdom` (and `canvas`) * Adding (for the duration of the test) that DOM's `window` and `document` on `global` * Monkey-patching DOM methods that require a rendering engine (`Element.getBBox` & `Element.getComputedLength`) * Removes all d3 mocking since it can now work normally in `jsdomIt` tests * Re-writes existing rendering tests to : * Use `jsdomIt` * Get rid of most of the involved mocking * Run `expect` calls on the generated SVG instead Inspired by d3's own test code mocking : https://github.com/d3/d3-selection/blob/v3.0.0/test/jsdom.js
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import jison from './.vite/jisonPlugin.js';
|
|
import jsonSchemaPlugin from './.vite/jsonSchemaPlugin.js';
|
|
import typescript from '@rollup/plugin-typescript';
|
|
import { defaultExclude, defineConfig } from 'vitest/config';
|
|
|
|
export default defineConfig({
|
|
resolve: {
|
|
extensions: ['.js'],
|
|
},
|
|
plugins: [
|
|
jison(),
|
|
jsonSchemaPlugin(), // handles .schema.yaml JSON Schema files
|
|
typescript({ compilerOptions: { declaration: false } }),
|
|
],
|
|
test: {
|
|
environment: 'jsdom',
|
|
globals: true,
|
|
// TODO: should we move this to a mermaid-core package?
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: ['text', 'json', 'html', 'lcov'],
|
|
reportsDirectory: './coverage/vitest',
|
|
exclude: [...defaultExclude, './tests/**', '**/__mocks__/**', '**/generated/'],
|
|
},
|
|
includeSource: ['packages/*/src/**/*.{js,ts}'],
|
|
clearMocks: true,
|
|
},
|
|
build: {
|
|
/** If you set esmExternals to true, this plugins assumes that
|
|
all external dependencies are ES modules */
|
|
|
|
commonjsOptions: {
|
|
esmExternals: true,
|
|
},
|
|
},
|
|
define: {
|
|
// Needs to be string
|
|
includeLargeFeatures: 'true',
|
|
'import.meta.vitest': 'undefined',
|
|
},
|
|
});
|