Skip to content

Commit

Permalink
fix(ui): respect --output param (#32351)
Browse files Browse the repository at this point in the history
Closes #32331

We're already passing the `outputDir` param to the UI, but the UI isn't
passing it back to the TestServer. This PR fixes that. I've added it to
`listTests`, which is requires to that
`TestServerDispatcher#_ignoredProjectOutputs` is populated with the
correct output dir. And i've added it to `runGlobalSetup`, which is what
the bug report was about.
  • Loading branch information
Skn0tt authored Aug 30, 2024
1 parent 90e7b9e commit ed5c21b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/playwright/src/isomorphic/testServerInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface TestServerInterface {

installBrowsers(params: {}): Promise<void>;

runGlobalSetup(params: {}): Promise<{
runGlobalSetup(params: { outputDir?: string }): Promise<{
report: ReportEntry[],
status: reporterTypes.FullResult['status']
}>;
Expand Down Expand Up @@ -81,6 +81,7 @@ export interface TestServerInterface {
locations?: string[];
grep?: string;
grepInvert?: string;
outputDir?: string;
}): Promise<{
report: ReportEntry[],
status: reporterTypes.FullResult['status']
Expand Down
6 changes: 5 additions & 1 deletion packages/playwright/src/runner/testServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ class TestServerDispatcher implements TestServerInterface {
async runGlobalSetup(params: Parameters<TestServerInterface['runGlobalSetup']>[0]): ReturnType<TestServerInterface['runGlobalSetup']> {
await this.runGlobalTeardown();

const { config, error } = await this._loadConfig();
const overrides: ConfigCLIOverrides = {
outputDir: params.outputDir,
};
const { config, error } = await this._loadConfig(overrides);
if (!config) {
const { reporter, report } = await this._collectingInternalReporter();
// Produce dummy config when it has an error.
Expand Down Expand Up @@ -256,6 +259,7 @@ class TestServerDispatcher implements TestServerInterface {
const overrides: ConfigCLIOverrides = {
repeatEach: 1,
retries: 0,
outputDir: params.outputDir,
};
const { config, error } = await this._loadConfig(overrides);
if (!config) {
Expand Down
8 changes: 5 additions & 3 deletions packages/trace-viewer/src/ui/uiModeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,14 @@ export const UIModeView: React.FC<{}> = ({
interceptStdio: true,
watchTestDirs: true
});
const { status, report } = await testServerConnection.runGlobalSetup({});
const { status, report } = await testServerConnection.runGlobalSetup({
outputDir: queryParams.outputDir,
});
teleSuiteUpdater.processGlobalReport(report);
if (status !== 'passed')
return;

const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args, grep: queryParams.grep, grepInvert: queryParams.grepInvert });
const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args, grep: queryParams.grep, grepInvert: queryParams.grepInvert, outputDir: queryParams.outputDir });
teleSuiteUpdater.processListReport(result.report);

testServerConnection.onReport(params => {
Expand Down Expand Up @@ -333,7 +335,7 @@ export const UIModeView: React.FC<{}> = ({
commandQueue.current = commandQueue.current.then(async () => {
setIsLoading(true);
try {
const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args, grep: queryParams.grep, grepInvert: queryParams.grepInvert });
const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args, grep: queryParams.grep, grepInvert: queryParams.grepInvert, outputDir: queryParams.outputDir });
teleSuiteUpdater.processListReport(result.report);
} catch (e) {
// eslint-disable-next-line no-console
Expand Down
26 changes: 18 additions & 8 deletions tests/playwright-test/ui-mode-test-setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import path from 'path';

test.describe.configure({ mode: 'parallel', retries });

test('should run global setup and teardown', async ({ runUITest }) => {
test('should run global setup and teardown', async ({ runUITest }, testInfo) => {
const { page, testProcess } = await runUITest({
'playwright.config.ts': `
import { defineConfig } from '@playwright/test';
Expand All @@ -29,26 +29,36 @@ test('should run global setup and teardown', async ({ runUITest }) => {
});
`,
'globalSetup.ts': `
export default () => console.log('\\n%%from-global-setup');
import { basename } from "node:path";
export default (config) => {
console.log('\\n%%from-global-setup');
console.log("setupOutputDir: " + basename(config.projects[0].outputDir));
};
`,
'globalTeardown.ts': `
export default () => console.log('\\n%%from-global-teardown');
export default (config) => {
console.log('\\n%%from-global-teardown');
console.log('%%' + JSON.stringify(config));
};
`,
'a.test.js': `
import { test, expect } from '@playwright/test';
test('should work', async ({}) => {});
`
});
}, undefined, { additionalArgs: ['--output=foo'] });
await page.getByTitle('Run all').click();
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');

await page.getByTitle('Toggle output').click();
await expect(page.getByTestId('output')).toContainText('from-global-setup');
const output = page.getByTestId('output');
await expect(output).toContainText('from-global-setup');
await expect(output).toContainText('setupOutputDir: foo');
await page.close();

await expect.poll(() => testProcess.outputLines()).toEqual([
'from-global-teardown',
]);
await expect.poll(() => testProcess.outputLines()).toContain('from-global-teardown');

const teardownConfig = JSON.parse(testProcess.outputLines()[1]);
expect(teardownConfig.projects[0].outputDir).toEqual(testInfo.outputPath('foo'));
});

test('should teardown on sigint', async ({ runUITest, nodeVersion }) => {
Expand Down

0 comments on commit ed5c21b

Please sign in to comment.