diff --git a/packages/feature-flags-webpack-plugin/__tests__/fixtures/component-c.js b/packages/feature-flags-webpack-plugin/__tests__/fixtures/component-c.js new file mode 100644 index 00000000..1f62fe38 --- /dev/null +++ b/packages/feature-flags-webpack-plugin/__tests__/fixtures/component-c.js @@ -0,0 +1,6 @@ +/* eslint-disable no-console */ +import { FEATURE_A, isEnabled } from './features' + +if (isEnabled(FEATURE_A)) { + console.log('enabled FEATURE_A') +} diff --git a/packages/feature-flags-webpack-plugin/__tests__/fixtures/features.js b/packages/feature-flags-webpack-plugin/__tests__/fixtures/features.js index 15875b21..72482a58 100644 --- a/packages/feature-flags-webpack-plugin/__tests__/fixtures/features.js +++ b/packages/feature-flags-webpack-plugin/__tests__/fixtures/features.js @@ -9,3 +9,7 @@ export const FEATURE_B = { export function isFeatureEnabled(_flag) { return false } + +export function isEnabled(_flag) { + return false +} diff --git a/packages/feature-flags-webpack-plugin/__tests__/index.test.ts b/packages/feature-flags-webpack-plugin/__tests__/index.test.ts index 58674e40..e31a7090 100644 --- a/packages/feature-flags-webpack-plugin/__tests__/index.test.ts +++ b/packages/feature-flags-webpack-plugin/__tests__/index.test.ts @@ -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\\")})();"`, + ) + }) })