#Get current vitest workspace's config inside test.

1 messages · Page 1 of 1 (latest)

spring pewter
#

I am aiming to run different vite configs against the same set of tests to verify that different plugin implementations result in the same css transforms (namely a postcss-plugin and a vite-plugin). I have the following vitest.workspace.ts:

import { defineConfig, mergeConfig } from 'vite';
import { defineWorkspace } from 'vitest/config';
import postcssPlugin from './dist/postcss';
import vitePlugin from './dist/vite';

const base = defineConfig({
  root: 'test',
  build: {
    write: false,
    ssr: true
  },
  test: {
    css: true,
    root: 'test'
  }
});

export default defineWorkspace([
  mergeConfig(base, {
    plugins: [vitePlugin()],
    test: {
      name: 'vite-plugin'
    }
  }),
  mergeConfig(base, {
    css: {
      postcss: { plugins: [postcssPlugin()] }
    },
    test: {
      name: 'postcss-plugin'
    }
  })
]);

If I plan to use vite's build() inside a vitest beforeAll hook, how can I make sure build uses each workspace's respective config?

spice zinc
#

If I plan to use vite's build() inside a vitest beforeAll hook, how can I make sure build uses each workspace's respective config?
This use case itself doesn't sound like what Vitest workspace is for.

From the description, I understood you would want a following, but if I'm missing something, can you elaborate with the actual test cases you're writing?

function myParametrizedTests(name config) {
  describe(`test with config ${name}`, () => {
    beforeAll(async () => {
      await build(config);
    })
  
    test("do something with build artifact 1", () => {})
    test("do something with build artifact 2", () => {})
  })
}

myParametrizedTests("config1", mergeConfig(base, {
  plugins: [vitePlugin()],
}))

myParametrizedTests("config2", mergeConfig(base, {
  css: {
    postcss: { plugins: [postcssPlugin()] }
  },
}))