Skip to content

Commit 5d77332

Browse files
fix: vars
1 parent 856e889 commit 5d77332

6 files changed

Lines changed: 19 additions & 64 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@
104104
"prepack": "sf-prepack",
105105
"prepare": "sf-install",
106106
"test": "wireit",
107-
"test:nuts": "mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel=false",
108-
"test:nuts:local": "node -r dotenv/config ./node_modules/.bin/nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel=false",
109-
"test:nut:local": "node -r dotenv/config ./node_modules/.bin/nyc mocha --slow 4500 --timeout 600000",
107+
"test:nuts": "mocha \"**/*.nut.ts\" --slow 30000 --timeout 600000 --parallel=false",
108+
"test:nuts:local": "node -r dotenv/config ./node_modules/.bin/nyc mocha \"**/*.nut.ts\" --slow 30000 --timeout 600000 --parallel=false",
109+
"test:nut:local": "node -r dotenv/config ./node_modules/.bin/nyc mocha --slow 30000 --timeout 600000",
110110
"test:only": "wireit",
111111
"unlink-lwr": "yarn unlink @lwrjs/api @lwrjs/app-service @lwrjs/asset-registry @lwrjs/asset-transformer @lwrjs/auth-middleware @lwrjs/base-view-provider @lwrjs/base-view-transformer @lwrjs/client-modules @lwrjs/config @lwrjs/core @lwrjs/dev-proxy-server @lwrjs/diagnostics @lwrjs/esbuild @lwrjs/everywhere @lwrjs/fs-asset-provider @lwrjs/fs-watch @lwrjs/html-view-provider @lwrjs/instrumentation @lwrjs/label-module-provider @lwrjs/lambda @lwrjs/legacy-npm-module-provider @lwrjs/loader @lwrjs/lwc-module-provider @lwrjs/lwc-ssr @lwrjs/markdown-view-provider @lwrjs/module-bundler @lwrjs/module-registry @lwrjs/npm-module-provider @lwrjs/nunjucks-view-provider @lwrjs/o11y @lwrjs/resource-registry @lwrjs/router @lwrjs/security @lwrjs/server @lwrjs/shared-utils @lwrjs/static @lwrjs/tools @lwrjs/types @lwrjs/view-registry lwr",
112112
"update-snapshots": "node --loader ts-node/esm --no-warnings=ExperimentalWarning \"./bin/dev.js\" snapshot:generate",

test/commands/lightning/dev/component-preview/browserMenu.nut.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { expect } from 'chai';
2121
import { type Browser, type Page } from 'playwright';
2222
import { getSession } from '../helpers/sessionUtils.js';
2323
import { startLightningDevServer, getPreviewURL } from '../helpers/devServerUtils.js';
24+
import { killServerProcess } from '../helpers/processUtils.js';
2425
import { getPreview } from '../helpers/browserUtils.js';
2526

2627
const COMPONENT_NAME = 'helloWorld';
@@ -33,11 +34,8 @@ describe('lightning preview menu', () => {
3334
let browser: Browser;
3435
let page: Page;
3536

36-
before(async () => {
37-
session = await getSession();
38-
});
39-
4037
beforeEach(async () => {
38+
session = await getSession();
4139
childProcess = startLightningDevServer(
4240
session.project?.dir ?? '',
4341
session.hubOrg.username,
@@ -51,9 +49,7 @@ describe('lightning preview menu', () => {
5149
afterEach(async () => {
5250
if (page) await page.close();
5351
if (browser) await browser.close();
54-
if (childProcess?.kill) {
55-
childProcess.kill('SIGKILL');
56-
}
52+
killServerProcess(childProcess);
5753
});
5854

5955
it('should render select link and hamburger menu with helloWorld available and clickable', async () => {

test/commands/lightning/dev/component-preview/componentError.nut.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { expect } from 'chai';
2121
import { type Browser, type Page } from 'playwright';
2222
import { getSession } from '../helpers/sessionUtils.js';
2323
import { startLightningDevServer, getPreviewURL } from '../helpers/devServerUtils.js';
24+
import { killServerProcess } from '../helpers/processUtils.js';
2425
import { getPreview } from '../helpers/browserUtils.js';
2526

2627
const COMPONENT_NAME = 'withError';
@@ -50,9 +51,7 @@ describe('lightning preview component error', () => {
5051
after(async () => {
5152
if (page) await page.close();
5253
if (browser) await browser.close();
53-
if (childProcess?.kill) {
54-
childProcess.kill('SIGKILL');
55-
}
54+
killServerProcess(childProcess);
5655
});
5756

5857
it('should render the error component and display the error modal', async () => {

test/commands/lightning/dev/component-preview/hmr.nut.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { expect } from 'chai';
2323
import { type Browser, type Page } from 'playwright';
2424
import { getSession, getComponentPath } from '../helpers/sessionUtils.js';
2525
import { startLightningDevServer, getPreviewURL } from '../helpers/devServerUtils.js';
26+
import { killServerProcess } from '../helpers/processUtils.js';
2627
import { getPreview } from '../helpers/browserUtils.js';
2728

2829
const COMPONENT_NAME = 'helloWorld';
@@ -52,9 +53,7 @@ describe('lightning preview hot module reload', () => {
5253
after(async () => {
5354
if (page) await page.close();
5455
if (browser) await browser.close();
55-
if (childProcess?.kill) {
56-
childProcess.kill('SIGKILL');
57-
}
56+
killServerProcess(childProcess);
5857
});
5958

6059
it('should re-render component and hot reload .js changes', async () => {

test/commands/lightning/dev/component-preview/prompts.nut.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
waitForProcessExit,
2828
getPreviewURL,
2929
} from '../helpers/devServerUtils.js';
30+
import { killServerProcess } from '../helpers/processUtils.js';
3031
import { getPreview } from '../helpers/browserUtils.js';
3132

3233
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -42,11 +43,8 @@ describe('lightning preview component prompts', () => {
4243
let browser: Browser;
4344
let page: Page;
4445

45-
before(async () => {
46-
session = await getSession();
47-
});
48-
4946
beforeEach(async () => {
47+
session = await getSession();
5048
const org = await Org.create({ aliasOrUsername: session.hubOrg.username });
5149
connection = org.getConnection();
5250
// Unset required org configuration to trigger prompt behavior
@@ -57,9 +55,7 @@ describe('lightning preview component prompts', () => {
5755
afterEach(async () => {
5856
if (page) await page.close();
5957
if (browser) await browser.close();
60-
if (childProcess?.kill) {
61-
childProcess.kill('SIGKILL');
62-
}
58+
killServerProcess(childProcess);
6359
});
6460

6561
it('should error out when local dev is not enabled and AUTO_ENABLE_LOCAL_DEV is false', async () => {

test/commands/lightning/dev/helpers/sessionUtils.ts

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,16 @@ import path from 'node:path';
1717
import { TestSession } from '@salesforce/cli-plugins-testkit';
1818
import { PROJECT_PATH } from './utils.js';
1919

20-
const SESSION_RETRIES = 3;
21-
const SESSION_RETRY_DELAY_MS = 5000;
2220
let cachedSession: TestSession;
2321

24-
function isJwtAuthError(error: unknown): boolean {
25-
const message = error instanceof Error ? error.message : String(error);
26-
const name = error instanceof Error ? (error.constructor?.name ?? '') : '';
27-
return (
28-
name.includes('Jwt') ||
29-
message.includes('JWT') ||
30-
message.includes('client identifier invalid') ||
31-
message.includes('audience is invalid')
32-
);
33-
}
34-
35-
/**
36-
* Get or create the shared session. Reuses one TestSession per process so we only stub process.cwd once
37-
* (avoids "Attempted to wrap cwd which is already wrapped" when multiple NUT files run in one Mocha process).
38-
* JWT auth is flaky hence the retries on create.
39-
*
40-
* @returns The shared TestSession
41-
*/
4222
export async function getSession(): Promise<TestSession> {
43-
if (cachedSession) {
44-
return cachedSession;
45-
}
46-
let lastError: unknown;
47-
for (let attempt = 1; attempt <= SESSION_RETRIES; attempt++) {
48-
try {
49-
// eslint-disable-next-line no-await-in-loop
50-
cachedSession = await TestSession.create({
51-
devhubAuthStrategy: 'AUTO',
52-
project: { sourceDir: PROJECT_PATH },
53-
});
54-
return cachedSession;
55-
} catch (error) {
56-
lastError = error;
57-
if (!isJwtAuthError(error) || attempt === SESSION_RETRIES) {
58-
throw error;
59-
}
60-
// eslint-disable-next-line no-await-in-loop
61-
await new Promise((resolve) => setTimeout(resolve, SESSION_RETRY_DELAY_MS));
62-
}
23+
if (!cachedSession) {
24+
cachedSession = await TestSession.create({
25+
devhubAuthStrategy: 'AUTO',
26+
project: { sourceDir: PROJECT_PATH },
27+
});
6328
}
64-
throw lastError;
29+
return new Promise((r) => r(cachedSession));
6530
}
6631

6732
export function getComponentPath(session: TestSession, componentName: string) {

0 commit comments

Comments
 (0)