Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(list mode): print errors to stderr (#13016)
Dmitry Gozman3688e74e3e83
diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.tsindex 68c00e2ff8..51af2d9d1d 100644--- a/packages/playwright-test/src/runner.ts+++ b/packages/playwright-test/src/runner.ts@@ -25,6 +25,7 @@ import { TestCase, Suite } from './test';import { Loader } from './loader';import { FullResult, Reporter, TestError } from '../types/testReporter';import { Multiplexer } from './reporters/multiplexer';+import { formatError } from './reporters/base';import DotReporter from './reporters/dot';import GitHubReporter from './reporters/github';import LineReporter from './reporters/line';@@ -684,7 +685,10 @@ function createTestGroups(rootSuite: Suite): TestGroup[] {}class ListModeReporter implements Reporter {+ private config!: FullConfig;+onBegin(config: FullConfig, suite: Suite): void {+ this.config = config;// eslint-disable-next-line no-consoleconsole.log(`Listing tests:`);const tests = suite.allTests();@@ -701,6 +705,11 @@ class ListModeReporter implements Reporter {// eslint-disable-next-line no-consoleconsole.log(`Total: ${tests.length} ${tests.length === 1 ? 'test' : 'tests'} in ${files.size} ${files.size === 1 ? 'file' : 'files'}`);}++ onError(error: TestError) {+ // eslint-disable-next-line no-console+ console.error('\n' + formatError(this.config, error, false).message);+ }}function createForbidOnlyError(config: FullConfig, onlyTestsAndSuites: (TestCase | Suite)[]): TestError {diff --git a/tests/playwright-test/list-mode.spec.ts b/tests/playwright-test/list-mode.spec.tsindex c6eaac536d..1c93ea32f1 100644--- a/tests/playwright-test/list-mode.spec.ts+++ b/tests/playwright-test/list-mode.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { test, expect } from './playwright-test-fixtures';+import { test, expect, stripAnsi } from './playwright-test-fixtures';import path from 'path';import fs from 'fs';@@ -140,3 +140,14 @@ test('outputDir should not be removed', async ({ runInlineTest }, testInfo) => {expect(result2.exitCode).toBe(0);expect(fs.existsSync(path.join(outputDir, 'a-my-test', 'myfile.txt'))).toBe(true);});++test('should report errors', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'a.test.js': `+ const oh = '';+ oh = 2;+ `+ }, { 'list': true });+ expect(result.exitCode).toBe(1);+ expect(stripAnsi(result.output)).toContain('> 6 | oh = 2;');+});