Skip to content

Commit

Permalink
test: add unit for isFeatureEnabledFnName case
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed Dec 20, 2020
1 parent d5d1fc6 commit 80453eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable no-console */
import { FEATURE_A, isEnabled } from './features'

if (isEnabled(FEATURE_A)) {
console.log('enabled FEATURE_A')
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export const FEATURE_B = {
export function isFeatureEnabled(_flag) {
return false
}

export function isEnabled(_flag) {
return false
}
11 changes: 11 additions & 0 deletions packages/feature-flags-webpack-plugin/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@ describe('FeatureFlagsWebpackPlugin', () => {
`"(()=>{\\"use strict\\";console.log(\\"enabled FEATURE_A\\"),console.log(\\"enabled FEATURE_B\\")})();"`,
)
})

test('should compile code with enabled feature and custom feature name', async () => {
const plugin = new FeatureFlagsWebpackPlugin({
isFeatureEnabledFnName: 'isEnabled',
flags: { FEATURE_A },
})
const { compiler } = await compile('./component-c.js', { plugins: [plugin] })
expect(getResult(compiler)).toMatchInlineSnapshot(
`"(()=>{\\"use strict\\";console.log(\\"enabled FEATURE_A\\")})();"`,
)
})
})

0 comments on commit 80453eb

Please sign in to comment.