Skip to content

Commit

Permalink
chore: fix .only in dependent tests (#26503)
Browse files Browse the repository at this point in the history
Fixes #26492
  • Loading branch information
pavelfeldman committed Aug 16, 2023
1 parent 1a1ff6c commit 929a849
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/playwright-test/src/plugins/webServerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export class WebServerPlugin implements TestRunnerPlugin {
this._reporter!.onStdErr?.(colors.dim('[WebServer] ') + line.toString());
});
launchedProcess.stdout!.on('data', line => {
process.stdout.write(line);
if (debugWebServer.enabled || this._options.stdout === 'pipe')
this._reporter!.onStdOut?.(colors.dim('[WebServer] ') + line.toString());
});
Expand Down
3 changes: 1 addition & 2 deletions packages/playwright-test/src/runner/projectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export function buildProjectsClosure(projects: FullProjectInternal[], hasTests?:
throw error;
}

const projectHasTests = hasTests ? hasTests(project) : true;
if (!projectHasTests && depth === 0)
if (depth === 0 && hasTests && !hasTests(project))
return;

if (result.get(project) !== 'dependency')
Expand Down
47 changes: 47 additions & 0 deletions tests/playwright-test/deps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,50 @@ test('should not run deps for projects filtered with grep', async ({ runInlineTe
expect(result.passed).toBe(3);
expect(result.outputLines).toEqual(['setupB', 'projectB', 'teardownB']);
});

test('should allow only in dependent', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = {
projects: [
{ name: 'setup', testMatch: '**/setup.ts' },
{ name: 'project', dependencies: ['setup'] },
],
};`,
'setup.ts': `
import { test, expect } from '@playwright/test';
test('setup', async ({}) => {});
`,
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test.only('test', async ({}) => {
});
test('test 2', async ({}) => { expect(1).toBe(2); });
`,
});
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(2);
});

test('should allow only in dependent (2)', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = {
projects: [
{ name: 'setup', testMatch: '**/setup.ts' },
{ name: 'project', dependencies: ['setup'] },
],
};`,
'setup.ts': `
import { test, expect } from '@playwright/test';
test.only('setup', async ({}) => {});
`,
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('test', async ({}) => { expect(1).toBe(2); });
test('test 2', async ({}) => { expect(1).toBe(2); });
`,
});
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});

0 comments on commit 929a849

Please sign in to comment.