Skip to content

Commit

Permalink
Merge pull request #4 from pengx17/master
Browse files Browse the repository at this point in the history
fix: correct logic of requireEnv
  • Loading branch information
iFaxity authored Jun 21, 2021
2 parents 2c03bfb + 6496be1 commit 92b2798
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Creates the vite plugin from a set of optional plugin options.
* `opts.include {string|string[]}` - Optional string or array of strings of glob patterns to include
* `opts.exclude {string|string[]}` - Optional string or array of strings of glob patterns to exclude
* `opts.extension {string|string[]}` - Optional string or array of strings of extensions to include (dot prefixed like .js or .ts)
* `opts.requireEnv {string}` - Optional string to require env to be true to instrument to code, otherwise it will instrument even if env variable is not set
* `opts.cypress {string}` - Optional string to change the env to CYPRESS_COVERAGE instead of VITE_COVERAGE. For more ease of use with @cypress/code-coverage
* `opts.requireEnv {boolean}` - Optional boolean to require env to be true to instrument to code, otherwise it will instrument even if env variable is not set
* `opts.cypress {boolean}` - Optional boolean to change the env to CYPRESS_COVERAGE instead of VITE_COVERAGE. For more ease of use with @cypress/code-coverage

Examples
--------------------------
Expand All @@ -56,7 +56,7 @@ module.exports = {
plugins: [
istanbul({
include: 'src/*',
exclude: [/node_modules/, 'test/'],
exclude: ['node_modules', 'test/'],
extension: [ '.js', '.ts' ],
}),
],
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ function createTransform(opts: IstanbulPluginOptions = {}): TransformHook {
function istanbulPlugin(opts?: IstanbulPluginOptions): Plugin {
// Only instrument when we want to, as we only want instrumentation in test
const env = opts.cypress ? process.env.CYPRESS_COVERAGE : process.env.VITE_COVERAGE;
const defaultValue = opts.requireEnv ? '' : 'true';
const requireEnv = opts.requireEnv ?? false;

if ((env || defaultValue).toLowerCase() == 'true') {
if (requireEnv && env?.toLowerCase() === 'false') {
return { name: 'vite:istanbul' };
}

Expand Down

0 comments on commit 92b2798

Please sign in to comment.