Skip to content

Commit 0768b67

Browse files
wjhsfcardoso
andauthored
@W-17592100 chore: run unit tests in production mode (#5270)
* ci: run unit tests in prod mode * test(engine-dom): skip testing dev mode feature in prod mode * test(ssr-compiler): avoid checking dev mode error text in prod mode * test(engine-server): skip fixture tests in prod mode there are a lot of failures that we'll get to later * chore(tests): support NODE_ENV=production * Apply suggestions from code review * chore(coverage): bump minimum function threshold for SSR packages * chore: remove unused file * test(coverage): ignore ssr-client-utils and bump thresholds for SSR * ci: don't generate coverage for prod mode Coverage will always be lower because we have a ton of `NODE_ENV !== production checks`, but no `===` checks. --------- Co-authored-by: Matheus Cardoso <[email protected]>
1 parent 51b9797 commit 0768b67

File tree

9 files changed

+30
-21
lines changed

9 files changed

+30
-21
lines changed

.github/workflows/unit.yml

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ jobs:
6666
run: yarn test:types
6767
- name: Run unit tests
6868
run: yarn test:ci
69+
- name: Run unit tests in production mode
70+
run: yarn test:production --no-watch
6971
- name: Upload unit test coverage report
7072
uses: actions/upload-artifact@v4
7173
with:

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"copy-fork": "./scripts/tasks/unsafe-external-contributor-ci-workaround.sh",
2020
"dev": "nx run-many --target=dev --all --parallel=999 --exclude=@lwc/perf-benchmarks,@lwc/perf-benchmarks-components,@lwc/integration-tests",
2121
"test": "vitest --workspace vitest.workspace.mjs",
22+
"test:production": "VITE_NODE_ENV=production vitest --workspace vitest.workspace.mjs",
2223
"test:bespoke": "nx run-many --target=test",
2324
"test:debug": "vitest --workspace vitest.workspace.mjs --inspect-brk --no-file-parallelism",
2425
"test:ci": "vitest run --workspace vitest.workspace.mjs --coverage",

packages/@lwc/engine-dom/src/formatters/__tests__/component.spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { LOWEST_API_VERSION } from '@lwc/shared';
1616

1717
// it needs to be imported from the window, otherwise the checks for associated vms is done against "@lwc/engine-core"
18-
const LightningElementFormatter = (globalThis as any)['devtoolsFormatters'].find((f: any) => {
18+
const LightningElementFormatter = (globalThis as any)['devtoolsFormatters']?.find((f: any) => {
1919
return f.name === 'LightningElementFormatter';
2020
});
2121

@@ -33,8 +33,9 @@ class WireAdapter {
3333
disconnect() {}
3434
}
3535

36-
describe('Lightning Element formatter', () => {
37-
const { header } = LightningElementFormatter;
36+
// LightningElementFormatter is not exposed in prod mode
37+
describe.skipIf(process.env.NODE_ENV === 'production')('Lightning Element formatter', () => {
38+
const header = LightningElementFormatter?.header;
3839

3940
it('should not contain body', () => {
4041
expect(LightningElementFormatter.hasBody()).toBe(false);

packages/@lwc/engine-server/src/__tests__/fixtures.spec.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { testFixtureDir, formatHTML, pluginVirtual } from '@lwc/test-utils-lwc-i
1313
import { setFeatureFlagForTest } from '../index';
1414
import type { LightningElementConstructor } from '@lwc/engine-core/dist/framework/base-lightning-element';
1515
import type { RollupLwcOptions } from '@lwc/rollup-plugin';
16+
import type { FeatureFlagName } from '@lwc/features/dist/types';
1617

1718
vi.mock('lwc', async () => {
1819
const lwcEngineServer = await import('../index');
@@ -33,6 +34,9 @@ interface FixtureConfig {
3334

3435
/** Props to provide to the root component. */
3536
props?: Record<string, string>;
37+
38+
/** Feature flags to enable for the test. */
39+
features: FeatureFlagName[];
3640
}
3741

3842
async function compileFixture({
@@ -162,7 +166,8 @@ function testFixtures(options?: RollupLwcOptions) {
162166
);
163167
}
164168

165-
describe.concurrent('fixtures', () => {
169+
// TODO [#5134]: Enable these tests in production mode
170+
describe.skipIf(process.env.NODE_ENV === 'production').concurrent('fixtures', () => {
166171
beforeAll(() => {
167172
// ENABLE_WIRE_SYNC_EMIT is used because this mimics the behavior for LWR in SSR mode. It's also more reasonable
168173
// for how both `engine-server` and `ssr-runtime` behave, which is to use sync rendering.

packages/@lwc/ssr-compiler/src/__tests__/estemplate.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe.each(
6161
`;
6262
const doReplacement = () => tmpl(b.literal('I am not an identifier') as any);
6363
expect(doReplacement).toThrow(
64-
'Validation failed for templated node. Expected type identifier, but received Literal.'
64+
/^Validation failed for templated node\. Expected type .+?, but received Literal\.$/
6565
);
6666
});
6767
});

packages/@lwc/ssr-compiler/src/optimizer.ts

-12
This file was deleted.

packages/@lwc/ssr-runtime/src/stubs.ts

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
66
*/
77

8+
/* v8 ignore start */
9+
810
// Stubs for all the un-implemented exports from @lwc/engine-server
911

1012
export function api(..._: unknown[]): never {
@@ -216,3 +218,5 @@ export const renderer = {
216218
*/
217219
// A real stub, not a "not implemented" one! 😯
218220
export const hot = undefined;
221+
222+
/* v8 ignore stop */

vitest.config.mjs

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export default defineConfig({
2222
'**/packages/@lwc/engine-dom/**',
2323
'**/packages/@lwc/engine-core/**',
2424
'**/packages/@lwc/synthetic-shadow/**',
25+
// TODO [#5272]: add tests
26+
'**/packages/@lwc/ssr-client-utils/**',
2527
// Ignore test packages
2628
'**/packages/@lwc/integration-karma/**',
2729
'**/packages/@lwc/integration-tests/**',
@@ -36,9 +38,9 @@ export default defineConfig({
3638
// SSR compiler/runtime is relatively newer, so has lower thresholds for now
3739
'**/packages/@lwc/ssr-*/**': {
3840
branches: 90,
39-
functions: 60,
40-
lines: 85,
41-
statements: 85,
41+
functions: 90,
42+
lines: 90,
43+
statements: 90,
4244
},
4345

4446
'!**/packages/@lwc/ssr-*/**': {

vitest.shared.mjs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import inspector from 'node:inspector';
2+
import process from 'node:process';
23
import { defineConfig } from 'vitest/config';
34
import pkg from './package.json';
4-
55
export default defineConfig({
66
test: {
7+
// We can't set `NODE_ENV` directly (i.e. `NODE_ENV=production yarn test`), because some packages
8+
// set their env to jsdom, and NODE_ENV=production + jsdom causes `node:` imports to break
9+
env: {
10+
NODE_ENV: process.env.VITE_NODE_ENV,
11+
},
712
// Don't time out if we detect a debugger attached
813
testTimeout: inspector.url()
914
? // Largest allowed delay, see https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value
@@ -28,6 +33,7 @@ export default defineConfig({
2833
'rollup-plugin',
2934
'shared',
3035
'signals',
36+
'ssr-client-utils',
3137
'ssr-compiler',
3238
'ssr-runtime',
3339
'style-compiler',

0 commit comments

Comments
 (0)