Skip to content

Commit

Permalink
fix: use Eugene's technique instead
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Apr 29, 2022
1 parent 76c66b6 commit 72afdc0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 106 deletions.
20 changes: 4 additions & 16 deletions packages/@lwc/engine-core/src/testFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,8 @@

import features from '@lwc/features';

if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
window.addEventListener('test-dummy-flag', () => {
let hasFlag = false;
if (features.DUMMY_TEST_FLAG) {
hasFlag = true;
}

window.dispatchEvent(
new CustomEvent('has-dummy-flag', {
detail: {
package: '@lwc/engine-core',
hasFlag,
},
})
);
});
if (process.env.NODE_ENV !== 'production') {
if (features.ENABLE_TEST_EXCEPTION) {
throw new Error('Compile-time processing of feature flags is broken.');
}
}
6 changes: 3 additions & 3 deletions packages/@lwc/engine-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

// Tests -------------------------------------------------------------------------------------------
import './testFeatureFlag.ts';

// Polyfills ---------------------------------------------------------------------------------------
import './polyfills/aria-properties/main';

// Renderer initialization -------------------------------------------------------------------------
import './initializeRenderer';

// Tests -------------------------------------------------------------------------------------------
import './testFeatureFlag.ts';

// Engine-core public APIs -------------------------------------------------------------------------
export {
createContextProvider,
Expand Down
20 changes: 4 additions & 16 deletions packages/@lwc/engine-dom/src/testFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,8 @@

import features from '@lwc/features';

if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
window.addEventListener('test-dummy-flag', () => {
let hasFlag = false;
if (features.DUMMY_TEST_FLAG) {
hasFlag = true;
}

window.dispatchEvent(
new CustomEvent('has-dummy-flag', {
detail: {
package: '@lwc/engine-dom',
hasFlag,
},
})
);
});
if (process.env.NODE_ENV !== 'production') {
if (features.ENABLE_TEST_EXCEPTION) {
throw new Error('Compile-time processing of feature flags is broken.');
}
}
2 changes: 1 addition & 1 deletion packages/@lwc/features/src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { create, keys, defineProperty, isUndefined, isBoolean, globalThis } from
import { FeatureFlagMap, FeatureFlagName, FeatureFlagValue } from './types';

const features: FeatureFlagMap = {
DUMMY_TEST_FLAG: null,
ENABLE_ELEMENT_PATCH: null,
ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
ENABLE_HMR: null,
Expand All @@ -19,6 +18,7 @@ const features: FeatureFlagMap = {
ENABLE_NODE_PATCH: null,
ENABLE_REACTIVE_SETTER: null,
ENABLE_WIRE_SYNC_EMIT: null,
ENABLE_TEST_EXCEPTION: null,
};

if (!globalThis.lwcRuntimeFlags) {
Expand Down
11 changes: 6 additions & 5 deletions packages/@lwc/features/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
export type FeatureFlagValue = boolean | null;

export interface FeatureFlagMap {
/**
* This is only used to test that feature flags are actually working
*/
DUMMY_TEST_FLAG: FeatureFlagValue;

/**
* LWC engine flag to enable mixed shadow mode. Setting this flag to `true` enables usage of
* native shadow DOM even when the synthetic shadow polyfill is applied.
Expand Down Expand Up @@ -91,6 +86,12 @@ export interface FeatureFlagMap {
* of next tick. It only affects wire configurations that depend on component values.
*/
ENABLE_WIRE_SYNC_EMIT: FeatureFlagValue;

/**
* This is only used to test that feature flags are actually working. If set to true, it
* should throw an error.
*/
ENABLE_TEST_EXCEPTION: FeatureFlagValue;
}

export type FeatureFlagName = keyof FeatureFlagMap;
6 changes: 3 additions & 3 deletions packages/@lwc/synthetic-shadow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

// Tests
import './testFeatureFlag';

// Collecting env references before patching anything
import './env/node';
import './env/element';
Expand Down Expand Up @@ -39,6 +42,3 @@ import './faux-shadow/html-element';
import './faux-shadow/slot';
import './faux-shadow/portal';
import './faux-shadow/shadow-token';

// Tests
import './testFeatureFlag';
20 changes: 4 additions & 16 deletions packages/@lwc/synthetic-shadow/src/testFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,8 @@

import features from '@lwc/features';

if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
window.addEventListener('test-dummy-flag', () => {
let hasFlag = false;
if (features.DUMMY_TEST_FLAG) {
hasFlag = true;
}

window.dispatchEvent(
new CustomEvent('has-dummy-flag', {
detail: {
package: '@lwc/synthetic-shadow',
hasFlag,
},
})
);
});
if (process.env.NODE_ENV !== 'production') {
if (features.ENABLE_TEST_EXCEPTION) {
throw new Error('Compile-time processing of feature flags is broken.');
}
}
46 changes: 0 additions & 46 deletions packages/integration-karma/test/features/index.spec.js

This file was deleted.

0 comments on commit 72afdc0

Please sign in to comment.