pkgroll icon indicating copy to clipboard operation
pkgroll copied to clipboard

Detect Vitest for in-source testing

Open ayuhito opened this issue 3 years ago • 1 comments

Love this bundler and I appreciate the peace of mind having not to configure anything for things to just work.

Vitest does support in-source testing which I think is great when writing unit tests, however, since this bundler isn't extensible, it isn't possible for us to modify the Rollup config to tree-shake the testing code out as specified in their docs.

Would it be possible to merge the following replace config into the default Rollup config of this project? Whilst the addition of this shouldn't affect non-Vitest users, we can still include a check just incase to only include it if Vitest is present in the package.json.

// rollup.config.js
+ import replace from '@rollup/plugin-replace'

export default {
  plugins: [
+   replace({
+     'import.meta.vitest': 'undefined',
+   })
  ],
  // other options
}

ayuhito avatar Jun 26 '22 14:06 ayuhito

That looks safe but I would rather not build in specific support for other tooling, or also make assumptions about how they need to be used.

I think I would prefer to add a --define CLI flag like the --env flag.

privatenumber avatar Jun 26 '22 20:06 privatenumber