-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(engine-dom): make feature flags work (#2812)
* fix(engine-dom): make feature flags work Fixes #2811 * fix: license headers * test: fix jest tests * test: fix test * test: fix test * fix: use Eugene's technique instead * Revert "fix: use Eugene's technique instead" This reverts commit 72afdc0. * fix: use Eugene's technique instead * fix: revert unnecessary test change * fix: revert, use the elaborate test instead * fix: fix feature flags in engine-server as well
- Loading branch information
1 parent
e92881c
commit d9bdaa5
Showing
13 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
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, | ||
}, | ||
}) | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
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, | ||
}, | ||
}) | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
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, | ||
}, | ||
}) | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { setFeatureFlagForTest } from 'lwc'; | ||
|
||
describe('feature flags', () => { | ||
let packages; | ||
|
||
const onHasDummyFlag = (event) => { | ||
if (event.detail.hasFlag) { | ||
packages.push(event.detail.package); | ||
} | ||
}; | ||
|
||
beforeEach(() => { | ||
packages = []; | ||
window.addEventListener('has-dummy-flag', onHasDummyFlag); | ||
}); | ||
|
||
afterEach(() => { | ||
window.removeEventListener('has-dummy-flag', onHasDummyFlag); | ||
}); | ||
|
||
describe('flag enabled', () => { | ||
beforeEach(() => { | ||
setFeatureFlagForTest('DUMMY_TEST_FLAG', true); | ||
}); | ||
|
||
afterEach(() => { | ||
setFeatureFlagForTest('DUMMY_TEST_FLAG', false); | ||
}); | ||
|
||
it('works', () => { | ||
window.dispatchEvent(new CustomEvent('test-dummy-flag')); | ||
const expected = ['@lwc/engine-core', '@lwc/engine-dom']; | ||
if (process.env.SYNTHETIC_SHADOW_ENABLED) { | ||
expected.push('@lwc/synthetic-shadow'); | ||
} | ||
expect(packages.sort()).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('flag disabled', () => { | ||
it('works', () => { | ||
window.dispatchEvent(new CustomEvent('test-dummy-flag')); | ||
expect(packages.sort()).toEqual([]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters