Skip to content

Commit 3463450

Browse files
committed
test(wtr): remove console suppression
It was originally implemented to suppress distracting warnings in Karma tests, but WTR's log output is different / managed differently.
1 parent ec0186f commit 3463450

File tree

2 files changed

+6
-52
lines changed

2 files changed

+6
-52
lines changed

packages/@lwc/integration-karma/test-hydration/context/index.spec.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
export default {
2-
// server is expected to generate the same console error as the client
3-
expectedSSRConsoleCalls: {
4-
error: [],
5-
warn: [
6-
'Attempted to connect to trusted context but received the following error',
7-
'Multiple contexts of the same variety were provided. Only the first context will be used.',
8-
],
9-
},
102
requiredFeatureFlags: ['ENABLE_EXPERIMENTAL_SIGNALS'],
113
snapshot(target) {
124
const grandparent = target.shadowRoot.querySelector('x-grandparent');

packages/@lwc/integration-not-karma/configs/plugins/serve-hydration.js

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -73,39 +73,6 @@ async function compileModule(input, targetSSR, format) {
7373
return output[0].code;
7474
}
7575

76-
async function throwOnUnexpectedConsoleCalls(runnable, expectedConsoleCalls = {}) {
77-
// The console is shared between the VM and the main realm. Here we ensure that known warnings
78-
// are ignored and any others cause an explicit error.
79-
const methods = ['error', 'warn', 'log', 'info'];
80-
const originals = {};
81-
for (const method of methods) {
82-
// eslint-disable-next-line no-console
83-
originals[method] = console[method];
84-
// eslint-disable-next-line no-console
85-
console[method] = function (error) {
86-
if (
87-
method === 'warn' &&
88-
// This eslint warning is a false positive due to RegExp.prototype.test
89-
// eslint-disable-next-line vitest/no-conditional-tests
90-
/Cannot set property "(inner|outer)HTML"/.test(error?.message)
91-
) {
92-
return;
93-
} else if (
94-
expectedConsoleCalls[method]?.some((matcher) => error.message.includes(matcher))
95-
) {
96-
return;
97-
}
98-
99-
throw new Error(`Unexpected console.${method} call: ${error}`);
100-
};
101-
}
102-
try {
103-
return await runnable();
104-
} finally {
105-
Object.assign(console, originals);
106-
}
107-
}
108-
10976
/**
11077
* This is the function that takes SSR bundle code and test config, constructs a script that will
11178
* run in a separate JS runtime environment with its own global scope. The `context` object
@@ -117,7 +84,7 @@ async function throwOnUnexpectedConsoleCalls(runnable, expectedConsoleCalls = {}
11784
* So, script runs, generates markup, & we get that markup out and return it for use
11885
* in client-side tests.
11986
*/
120-
async function getSsrCode(moduleCode, filePath, expectedSSRConsoleCalls) {
87+
async function getSsrCode(moduleCode, filePath) {
12188
// LWC itself requires configuration before each test (`setHooks` and
12289
// `setFeatureFlagForTest`). Ideally, this would be done in pure isolation,
12390
// but getting that set up for `vm.Script`/`vm.Module` is non-trivial.
@@ -140,10 +107,7 @@ async function getSsrCode(moduleCode, filePath, expectedSSRConsoleCalls) {
140107
}
141108
);
142109

143-
return await throwOnUnexpectedConsoleCalls(
144-
() => script.runInContext(vm.createContext({ LWC: lwcSsr })),
145-
expectedSSRConsoleCalls
146-
);
110+
return await script.runInContext(vm.createContext({ LWC: lwcSsr }));
147111
}
148112

149113
async function existsUp(dir, file) {
@@ -160,12 +124,10 @@ async function existsUp(dir, file) {
160124
* This function wraps those configs in the test code to be executed.
161125
*/
162126
async function wrapHydrationTest(configPath) {
163-
const {
164-
default: { expectedSSRConsoleCalls, requiredFeatureFlags },
165-
} = await import(path.join(ROOT_DIR, configPath));
127+
const { default: config } = await import(path.join(ROOT_DIR, configPath));
166128

167129
try {
168-
requiredFeatureFlags?.forEach((featureFlag) => {
130+
config.requiredFeatureFlags?.forEach((featureFlag) => {
169131
lwcSsr.setFeatureFlagForTest(featureFlag, true);
170132
});
171133

@@ -175,7 +137,7 @@ async function wrapHydrationTest(configPath) {
175137
const onlyFileExists = await existsUp(suiteDir, '.only');
176138

177139
const componentDefSSR = await compileModule(componentEntrypoint, !ENGINE_SERVER, 'iife');
178-
const ssrOutput = await getSsrCode(componentDefSSR, configPath, expectedSSRConsoleCalls);
140+
const ssrOutput = await getSsrCode(componentDefSSR, configPath);
179141

180142
return `
181143
import { runTest } from '/helpers/test-hydrate.js';
@@ -187,7 +149,7 @@ async function wrapHydrationTest(configPath) {
187149
);
188150
`;
189151
} finally {
190-
requiredFeatureFlags?.forEach((featureFlag) => {
152+
config.requiredFeatureFlags?.forEach((featureFlag) => {
191153
lwcSsr.setFeatureFlagForTest(featureFlag, false);
192154
});
193155
}

0 commit comments

Comments
 (0)