Skip to content

Commit e86d620

Browse files
authored
chore(ui): ensure isTTY is correct (#38044)
1 parent 5b04cf5 commit e86d620

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

packages/playwright/src/reporters/base.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ type TestSummary = {
4949
export type CommonReporterOptions = {
5050
configDir: string,
5151
_mode?: 'list' | 'test' | 'merge',
52-
_isTestServer?: boolean,
5352
_commandHash?: string,
5453
};
5554

packages/playwright/src/reporters/html.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ class HtmlReporter implements ReporterV2 {
150150
if (process.env.CI || !this._buildResult)
151151
return;
152152
const { ok, singleTestId } = this._buildResult;
153-
const shouldOpen = !this._options._isTestServer && (this._open === 'always' || (!ok && this._open === 'on-failure'));
153+
const shouldOpen = !!process.stdin.isTTY && (this._open === 'always' || (!ok && this._open === 'on-failure'));
154154
if (shouldOpen) {
155155
await showHTMLReport(this._outputFolder, this._host, this._port, singleTestId);
156-
} else if (this._options._mode === 'test' && !this._options._isTestServer) {
156+
} else if (this._options._mode === 'test' && !!process.stdin.isTTY) {
157157
const packageManagerCommand = getPackageManagerExecCommand();
158158
const relativeReportPath = this._outputFolder === standaloneDefaultFolder() ? '' : ' ' + path.relative(process.cwd(), this._outputFolder);
159159
const hostArg = this._host ? ` --host ${this._host}` : '';

packages/playwright/src/reporters/merge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type ReportData = {
4242
};
4343

4444
export async function createMergedReport(config: FullConfigInternal, dir: string, reporterDescriptions: ReporterDescription[], rootDirOverride: string | undefined) {
45-
const reporters = await createReporters(config, 'merge', false, reporterDescriptions);
45+
const reporters = await createReporters(config, 'merge', reporterDescriptions);
4646
const multiplexer = new Multiplexer(reporters);
4747
const stringPool = new StringInternPool();
4848

packages/playwright/src/runner/reporters.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import type { BuiltInReporter, FullConfigInternal } from '../common/config';
3636
import type { CommonReporterOptions, Screen } from '../reporters/base';
3737
import type { ReporterV2 } from '../reporters/reporterV2';
3838

39-
export async function createReporters(config: FullConfigInternal, mode: 'list' | 'test' | 'merge', isTestServer: boolean, descriptions?: ReporterDescription[]): Promise<ReporterV2[]> {
39+
export async function createReporters(config: FullConfigInternal, mode: 'list' | 'test' | 'merge', descriptions?: ReporterDescription[]): Promise<ReporterV2[]> {
4040
const defaultReporters: { [key in BuiltInReporter]: new(arg: any) => ReporterV2 } = {
4141
blob: BlobReporter,
4242
dot: mode === 'list' ? ListModeReporter : DotReporter,
@@ -52,7 +52,7 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' |
5252
descriptions ??= config.config.reporter;
5353
if (config.configCLIOverrides.additionalReporters)
5454
descriptions = [...descriptions, ...config.configCLIOverrides.additionalReporters];
55-
const runOptions = reporterOptions(config, mode, isTestServer);
55+
const runOptions = reporterOptions(config, mode);
5656
for (const r of descriptions) {
5757
const [name, arg] = r;
5858
const options = { ...runOptions, ...arg };
@@ -103,11 +103,10 @@ export function createErrorCollectingReporter(screen: Screen): ErrorCollectingRe
103103
};
104104
}
105105

106-
function reporterOptions(config: FullConfigInternal, mode: 'list' | 'test' | 'merge', isTestServer: boolean): CommonReporterOptions {
106+
function reporterOptions(config: FullConfigInternal, mode: 'list' | 'test' | 'merge'): CommonReporterOptions {
107107
return {
108108
configDir: config.configDir,
109109
_mode: mode,
110-
_isTestServer: isTestServer,
111110
_commandHash: computeCommandHash(config),
112111
};
113112
}

packages/playwright/src/runner/testRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export class TestRunner extends EventEmitter<TestRunnerEventMap> {
340340
config.preOnlyTestFilters.push(test => testIdSet.has(test.id));
341341
}
342342

343-
const configReporters = params.disableConfigReporters ? [] : await createReporters(config, 'test', true);
343+
const configReporters = params.disableConfigReporters ? [] : await createReporters(config, 'test');
344344
const reporter = new InternalReporter([...configReporters, userReporter]);
345345
const stop = new ManualPromise();
346346
const tasks = [
@@ -453,7 +453,7 @@ export async function runAllTestsWithConfig(config: FullConfigInternal): Promise
453453
// Legacy webServer support.
454454
webServerPluginsForConfig(config).forEach(p => config.plugins.push({ factory: p }));
455455

456-
const reporters = await createReporters(config, listOnly ? 'list' : 'test', false);
456+
const reporters = await createReporters(config, listOnly ? 'list' : 'test');
457457
const lastRun = new LastRunReporter(config);
458458
if (config.cliLastFailed)
459459
await lastRun.filterLastFailed();

packages/playwright/src/runner/testServer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const originalStdoutWrite = process.stdout.write;
4040
// eslint-disable-next-line no-restricted-properties
4141
const originalStderrWrite = process.stderr.write;
4242

43+
const originalStdinIsTTY = process.stdin.isTTY;
44+
4345
class TestServer {
4446
private _configLocation: ConfigLocation;
4547
private _configCLIOverrides: ConfigCLIOverrides;
@@ -250,10 +252,17 @@ export class TestServerDispatcher implements TestServerInterface {
250252
};
251253
process.stdout.write = stdoutWrite;
252254
process.stderr.write = stderrWrite;
255+
256+
// Override isTTY to prevent reporters from thinking they can block and wait for user SIGINT.
257+
// We don't have a test for this, so be careful!
258+
// https://github.com/microsoft/playwright/issues/37867
259+
// @ts-expect-error types are wrong, isTTY can be undefined
260+
process.stdin.isTTY = undefined;
253261
} else {
254262
debug.log = originalDebugLog;
255263
process.stdout.write = originalStdoutWrite;
256264
process.stderr.write = originalStderrWrite;
265+
process.stdin.isTTY = originalStdinIsTTY;
257266
}
258267
/* eslint-enable no-restricted-properties */
259268
}

tests/playwright-test/reporter-html.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
14941494
expect(output).toContain('html-report');
14951495
});
14961496

1497-
test('it should only identify exact matches as clashing folders', async ({ runInlineTest, useIntermediateMergeReport }) => {
1497+
test('it should only identify exact matches as clashing folders', async ({ runInlineTest, useIntermediateMergeReport }, testInfo) => {
14981498
test.skip(useIntermediateMergeReport);
14991499
const result = await runInlineTest({
15001500
'playwright.config.ts': `
@@ -1509,9 +1509,8 @@ for (const useIntermediateMergeReport of [true, false] as const) {
15091509
`,
15101510
});
15111511
expect(result.exitCode).toBe(0);
1512-
const output = result.output;
1513-
expect(output).not.toContain('Configuration Error');
1514-
expect(output).toContain('test-results-html');
1512+
expect(result.output).not.toContain('Configuration Error');
1513+
expect(fs.existsSync(testInfo.outputPath('test-results-html'))).toBeTruthy();
15151514
});
15161515

15171516
test.describe('report location', () => {

0 commit comments

Comments
 (0)