Skip to content

Commit d866116

Browse files
authored
test(wtr): consolidate __lwcReset functions into a single file @W-19098255 (#5532)
* test(wtr): use shorter name for function * test(wtr): consolidate __lwcReset methods into single file * test(wtr): move global reset into files as needed * test(wtr): remove test that just tests test setup * test(wtr): move global DOM reset into per-file resets * test(wtr): rename `test-karma-lwc` to `test-lwc-integration` we don't use karma any more * test(wtr): reset logged messages in ARIA tests * test(wtr): flatten logic in file
1 parent b6e43be commit d866116

File tree

41 files changed

+387
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+387
-324
lines changed

packages/@lwc/engine-core/src/framework/check-version-mismatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { Stylesheet } from '@lwc/shared';
1616
let warned = false;
1717

1818
// Only used in LWC's Karma tests
19-
if (process.env.NODE_ENV === 'test-karma-lwc') {
19+
if (process.env.NODE_ENV === 'test-lwc-integration') {
2020
(window as any).__lwcResetWarnedOnVersionMismatch = () => {
2121
warned = false;
2222
};

packages/@lwc/engine-core/src/framework/fragment-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const fragmentCache: WeakMap<string[], Element>[] = ArrayFrom(
2525
);
2626

2727
// Only used in LWC's Karma tests
28-
if (process.env.NODE_ENV === 'test-karma-lwc') {
28+
if (process.env.NODE_ENV === 'test-lwc-integration') {
2929
(window as any).__lwcResetFragmentCache = () => {
3030
for (let i = 0; i < fragmentCache.length; i++) {
3131
fragmentCache[i] = new WeakMap();

packages/@lwc/engine-core/src/framework/hot-swaps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let activeComponents: WeakMultiMap<LightningElementConstructor, VM> =
3434
let activeStyles: WeakMultiMap<Stylesheet, VM> = /*@__PURE__@*/ new WeakMultiMap();
3535

3636
// Only used in LWC's Karma tests
37-
if (process.env.NODE_ENV === 'test-karma-lwc') {
37+
if (process.env.NODE_ENV === 'test-lwc-integration') {
3838
// Used to reset the global state between test runs
3939
(window as any).__lwcResetHotSwaps = () => {
4040
swappedTemplateMap = new WeakMap();

packages/@lwc/engine-core/src/framework/mutation-logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function logMutation(reactiveObserver: ReactiveObserver, target: object,
9999
// because the unit tests just create Reactive Observers on-the-fly.
100100
// Note we could explicitly target Vitest with `process.env.NODE_ENV === 'test'`, but then that would also
101101
// affect our downstream consumers' Jest/Vitest tests, and we don't want to throw an error just for a logger.
102-
if (process.env.NODE_ENV === 'test-karma-lwc') {
102+
if (process.env.NODE_ENV === 'test-lwc-integration') {
103103
throw new Error('The VM should always be defined except possibly in unit tests');
104104
}
105105
} else {

packages/@lwc/engine-core/src/framework/stylesheet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let stylesheetsToCssContent: WeakMap<Stylesheet, Set<string>> = /*@__PURE__@*/ n
3737
let cssContentToAbortControllers: Map<string, AbortController> = /*@__PURE__@*/ new Map();
3838

3939
// Only used in LWC's Karma tests
40-
if (process.env.NODE_ENV === 'test-karma-lwc') {
40+
if (process.env.NODE_ENV === 'test-lwc-integration') {
4141
// Used to reset the global state between test runs
4242
(window as any).__lwcResetStylesheetCache = () => {
4343
stylesheetsToCssContent = new WeakMap();

packages/@lwc/engine-core/src/framework/vm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ function computeShadowMode(
516516
if (
517517
// Force the shadow mode to always be native. Used for running tests with synthetic shadow patches
518518
// on, but components running in actual native shadow mode
519-
(process.env.NODE_ENV === 'test-karma-lwc' &&
519+
(process.env.NODE_ENV === 'test-lwc-integration' &&
520520
process.env.FORCE_NATIVE_SHADOW_MODE_FOR_TEST) ||
521521
// If synthetic shadow is explicitly disabled, use pure-native
522522
lwcRuntimeFlags.DISABLE_SYNTHETIC_SHADOW ||

packages/@lwc/engine-core/src/shared/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { VM } from '../framework/vm';
1212
const alreadyLoggedMessages = new Set();
1313

1414
// Only used in LWC's Karma tests
15-
if (process.env.NODE_ENV === 'test-karma-lwc') {
15+
if (process.env.NODE_ENV === 'test-lwc-integration') {
1616
(window as any).__lwcResetAlreadyLoggedMessages = () => {
1717
alreadyLoggedMessages.clear();
1818
};

packages/@lwc/engine-dom/src/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const stylesheetCache: Map<string, CacheData> = new Map();
5151
//
5252

5353
// Only used in LWC's Karma tests
54-
if (process.env.NODE_ENV === 'test-karma-lwc') {
54+
if (process.env.NODE_ENV === 'test-lwc-integration') {
5555
(window as any).__lwcResetGlobalStylesheets = () => {
5656
stylesheetCache.clear();
5757
};

packages/@lwc/features/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export function setFeatureFlag(name: FeatureFlagName, value: FeatureFlagValue):
6060
);
6161
return;
6262
}
63-
// This may seem redundant, but `process.env.NODE_ENV === 'test-karma-lwc'` is replaced by Karma tests
64-
if (process.env.NODE_ENV === 'test-karma-lwc' || process.env.NODE_ENV !== 'production') {
63+
// This may seem redundant, but `process.env.NODE_ENV === 'test-lwc-integration'` is replaced by Karma tests
64+
if (process.env.NODE_ENV === 'test-lwc-integration' || process.env.NODE_ENV !== 'production') {
6565
// Allow the same flag to be set more than once outside of production to enable testing
6666
flags[name] = value;
6767
} else {
@@ -86,8 +86,8 @@ export function setFeatureFlag(name: FeatureFlagName, value: FeatureFlagValue):
8686
* @example setFeatureFlag("DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE", true)
8787
*/
8888
export function setFeatureFlagForTest(name: FeatureFlagName, value: FeatureFlagValue): void {
89-
// This may seem redundant, but `process.env.NODE_ENV === 'test-karma-lwc'` is replaced by Karma tests
90-
if (process.env.NODE_ENV === 'test-karma-lwc' || process.env.NODE_ENV !== 'production') {
89+
// This may seem redundant, but `process.env.NODE_ENV === 'test-lwc-integration'` is replaced by Karma tests
90+
if (process.env.NODE_ENV === 'test-lwc-integration' || process.env.NODE_ENV !== 'production') {
9191
setFeatureFlag(name, value);
9292
}
9393
}

packages/@lwc/integration-karma/scripts/karma-plugins/hydration-tests.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ function createHCONFIG2JSPreprocessor(config, logger, emitter) {
266266
testWatchFiles.concat(componentWatchFilesCSR).concat(componentWatchFilesSSR)
267267
);
268268
ssrOutput = await getSsrCode(
269-
componentDefSSR.replace(`process.env.NODE_ENV === 'test-karma-lwc'`, 'true'),
269+
componentDefSSR.replace(
270+
`process.env.NODE_ENV === 'test-lwc-integration'`,
271+
'true'
272+
),
270273
testCode,
271274
path.join(suiteDir, 'ssr.js'),
272275
expectedSSRConsoleCalls

0 commit comments

Comments
 (0)