Skip to content

Commit 5b99438

Browse files
committed
test: add unit for isFeatureEnabledFnName case
1 parent d5d1fc6 commit 5b99438

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable no-console */
2+
import { FEATURE_A, isEnabled } from './features'
3+
4+
if (isEnabled(FEATURE_A)) {
5+
console.log('enabled FEATURE_A')
6+
}

packages/feature-flags-webpack-plugin/__tests__/fixtures/features.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ export const FEATURE_B = {
99
export function isFeatureEnabled(_flag) {
1010
return false
1111
}
12+
13+
export function isEnabled(_flag) {
14+
return false
15+
}

packages/feature-flags-webpack-plugin/__tests__/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,15 @@ describe('FeatureFlagsWebpackPlugin', () => {
2828
`"(()=>{\\"use strict\\";console.log(\\"enabled FEATURE_A\\"),console.log(\\"enabled FEATURE_B\\")})();"`,
2929
)
3030
})
31+
32+
test.only('should compile code with enabled feature and custom feature name', async () => {
33+
const plugin = new FeatureFlagsWebpackPlugin({
34+
isFeatureEnabledFnName: 'isEnabled',
35+
flags: { FEATURE_A },
36+
})
37+
const { compiler } = await compile('./component-c.js', { plugins: [plugin] })
38+
expect(getResult(compiler)).toMatchInlineSnapshot(
39+
`"(()=>{\\"use strict\\";console.log(\\"enabled FEATURE_A\\")})();"`,
40+
)
41+
})
3142
})

0 commit comments

Comments
 (0)