Skip to content

Commit 856e889

Browse files
fix: vars
1 parent ba0c1e2 commit 856e889

6 files changed

Lines changed: 28 additions & 32 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@
104104
"prepack": "sf-prepack",
105105
"prepare": "sf-install",
106106
"test": "wireit",
107-
"test:nuts": "mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000",
108-
"test:nuts:local": "node -r dotenv/config ./node_modules/.bin/nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000",
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",
109109
"test:nut:local": "node -r dotenv/config ./node_modules/.bin/nyc mocha --slow 4500 --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",

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ describe('lightning preview menu', () => {
3737
session = await getSession();
3838
});
3939

40-
after(async () => {
41-
await session?.clean();
42-
});
43-
4440
beforeEach(async () => {
4541
childProcess = startLightningDevServer(
4642
session.project?.dir ?? '',
@@ -53,11 +49,11 @@ describe('lightning preview menu', () => {
5349
});
5450

5551
afterEach(async () => {
52+
if (page) await page.close();
53+
if (browser) await browser.close();
5654
if (childProcess?.kill) {
5755
childProcess.kill('SIGKILL');
5856
}
59-
if (page) await page.close();
60-
if (browser) await browser.close();
6157
});
6258

6359
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
@@ -48,12 +48,11 @@ describe('lightning preview component error', () => {
4848
});
4949

5050
after(async () => {
51+
if (page) await page.close();
52+
if (browser) await browser.close();
5153
if (childProcess?.kill) {
5254
childProcess.kill('SIGKILL');
5355
}
54-
if (page) await page.close();
55-
if (browser) await browser.close();
56-
await session?.clean();
5756
});
5857

5958
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
@@ -50,12 +50,11 @@ describe('lightning preview hot module reload', () => {
5050
});
5151

5252
after(async () => {
53+
if (page) await page.close();
54+
if (browser) await browser.close();
5355
if (childProcess?.kill) {
5456
childProcess.kill('SIGKILL');
5557
}
56-
if (page) await page.close();
57-
if (browser) await browser.close();
58-
await session?.clean();
5958
});
6059

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

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { Readable, Writable } from 'node:stream';
1818
import { TestSession } from '@salesforce/cli-plugins-testkit';
1919
import { Connection, Messages, Org } from '@salesforce/core';
2020
import { expect } from 'chai';
21+
import { type Browser, type Page } from 'playwright';
2122
import { MetaUtils } from '../../../../../src/shared/metaUtils.js';
2223
import { getSession } from '../helpers/sessionUtils.js';
2324
import {
@@ -38,6 +39,8 @@ describe('lightning preview component prompts', () => {
3839
let session: TestSession;
3940
let childProcess: ChildProcessByStdio<Writable, Readable, Readable> | undefined;
4041
let connection: Connection;
42+
let browser: Browser;
43+
let page: Page;
4144

4245
before(async () => {
4346
session = await getSession();
@@ -51,16 +54,14 @@ describe('lightning preview component prompts', () => {
5154
await MetaUtils.setMyDomainFirstPartyCookieRequirement(connection, true);
5255
});
5356

54-
afterEach(() => {
57+
afterEach(async () => {
58+
if (page) await page.close();
59+
if (browser) await browser.close();
5560
if (childProcess?.kill) {
5661
childProcess.kill('SIGKILL');
5762
}
5863
});
5964

60-
after(async () => {
61-
await session?.clean();
62-
});
63-
6465
it('should error out when local dev is not enabled and AUTO_ENABLE_LOCAL_DEV is false', async () => {
6566
childProcess = startLightningDevServer(session.project?.dir, session.hubOrg.username, {
6667
AUTO_ENABLE_LOCAL_DEV: false,
@@ -95,14 +96,11 @@ describe('lightning preview component prompts', () => {
9596
childProcess.stdin?.write('\n');
9697

9798
const previewUrl = await getPreviewURL(childProcess.stdout);
98-
const { browser, page } = await getPreview(previewUrl, session.hubOrg.accessToken);
99+
({ browser, page } = await getPreview(previewUrl, session.hubOrg.accessToken));
99100

100-
// Assert that it rendered correctly
101101
const greetingLocator = page.getByText('Hello World');
102+
await greetingLocator.waitFor({ state: 'visible' });
102103
expect(await greetingLocator.textContent()).to.equal('Hello World');
103-
104-
if (page) await page.close();
105-
if (browser) await browser.close();
106104
});
107105

108106
it('should render without a prompt and disable first party cookies when AUTO_ENABLE_LOCAL_DEV=true', async () => {
@@ -114,16 +112,13 @@ describe('lightning preview component prompts', () => {
114112
);
115113

116114
const previewUrl = await getPreviewURL(childProcess.stdout);
117-
const { browser, page } = await getPreview(previewUrl, session.hubOrg.accessToken);
115+
({ browser, page } = await getPreview(previewUrl, session.hubOrg.accessToken));
118116

119-
// Assert that it rendered correctly
120117
const greetingLocator = page.getByText('Hello World');
118+
await greetingLocator.waitFor({ state: 'visible' });
121119
expect(await greetingLocator.textContent()).to.equal('Hello World');
122120

123121
// Command with AUTO_ENABLE_LOCAL_DEV calls ensureFirstPartyCookiesNotRequired, so requirement is disabled
124122
expect(await MetaUtils.isFirstPartyCookieRequired(connection)).to.be.false;
125-
126-
if (page) await page.close();
127-
if (browser) await browser.close();
128123
});
129124
});

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { PROJECT_PATH } from './utils.js';
1919

2020
const SESSION_RETRIES = 3;
2121
const SESSION_RETRY_DELAY_MS = 5000;
22+
let cachedSession: TestSession;
2223

2324
function isJwtAuthError(error: unknown): boolean {
2425
const message = error instanceof Error ? error.message : String(error);
@@ -32,19 +33,25 @@ function isJwtAuthError(error: unknown): boolean {
3233
}
3334

3435
/**
35-
* Get the session. JWT auth is flaky hence the retries
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.
3639
*
37-
* @returns
40+
* @returns The shared TestSession
3841
*/
3942
export async function getSession(): Promise<TestSession> {
43+
if (cachedSession) {
44+
return cachedSession;
45+
}
4046
let lastError: unknown;
4147
for (let attempt = 1; attempt <= SESSION_RETRIES; attempt++) {
4248
try {
4349
// eslint-disable-next-line no-await-in-loop
44-
return await TestSession.create({
50+
cachedSession = await TestSession.create({
4551
devhubAuthStrategy: 'AUTO',
4652
project: { sourceDir: PROJECT_PATH },
4753
});
54+
return cachedSession;
4855
} catch (error) {
4956
lastError = error;
5057
if (!isJwtAuthError(error) || attempt === SESSION_RETRIES) {

0 commit comments

Comments
 (0)