mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(test-runner): smaller error message paths (#7384)
This commit is contained in:
parent
a62aac3ff8
commit
d72efbe181
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { wrapInPromise } from './util';
|
||||
import { formatLocation, wrapInPromise } from './util';
|
||||
import * as crypto from 'crypto';
|
||||
import { FixturesWithLocation, Location, WorkerInfo, TestInfo } from './types';
|
||||
|
||||
@ -353,7 +353,3 @@ function errorWithLocations(message: string, ...defined: { location: Location, n
|
||||
}
|
||||
return new Error(message);
|
||||
}
|
||||
|
||||
function formatLocation(location: Location) {
|
||||
return location.file + ':' + location.line + ':' + location.column;
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import type { LaunchOptions, BrowserContextOptions, Page } from '../../types/types';
|
||||
import type { TestType, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, FullConfig, TestInfo } from '../../types/test';
|
||||
import type { TestType, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '../../types/test';
|
||||
import { rootTestType } from './testType';
|
||||
import { createGuid, removeFolders } from '../utils/utils';
|
||||
export { expect } from './expect';
|
||||
@ -180,7 +180,7 @@ export const test = _baseTest.extend<PlaywrightTestArgs & PlaywrightTestOptions,
|
||||
}));
|
||||
}
|
||||
|
||||
const prependToError = testInfo.status === 'timedOut' ? formatPendingCalls((context as any)._connection.pendingProtocolCalls(), testInfo) : '';
|
||||
const prependToError = testInfo.status === 'timedOut' ? formatPendingCalls((context as any)._connection.pendingProtocolCalls()) : '';
|
||||
await context.close();
|
||||
if (prependToError) {
|
||||
if (!testInfo.error) {
|
||||
@ -215,17 +215,17 @@ export const test = _baseTest.extend<PlaywrightTestArgs & PlaywrightTestOptions,
|
||||
});
|
||||
export default test;
|
||||
|
||||
function formatPendingCalls(calls: ProtocolCall[], testInfo: TestInfo) {
|
||||
function formatPendingCalls(calls: ProtocolCall[]) {
|
||||
if (!calls.length)
|
||||
return '';
|
||||
return 'Pending operations:\n' + calls.map(call => {
|
||||
const frame = call.stack && call.stack[0] ? formatStackFrame(testInfo.config, call.stack[0]) : '<unknown>';
|
||||
const frame = call.stack && call.stack[0] ? formatStackFrame(call.stack[0]) : '<unknown>';
|
||||
return ` - ${call.apiName} at ${frame}\n`;
|
||||
}).join('') + '\n';
|
||||
}
|
||||
|
||||
function formatStackFrame(config: FullConfig, frame: StackFrame) {
|
||||
const file = path.relative(config.rootDir, frame.file) || path.basename(frame.file);
|
||||
function formatStackFrame(frame: StackFrame) {
|
||||
const file = path.relative(process.cwd(), frame.file) || path.basename(frame.file);
|
||||
return `${file}:${frame.line || 1}:${frame.column || 1}`;
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
import { installTransform } from './transform';
|
||||
import type { FullConfig, Config, FullProject, Project, ReporterDescription, PreserveOutput } from './types';
|
||||
import { isRegExp, mergeObjects } from './util';
|
||||
import { isRegExp, mergeObjects, errorWithFile } from './util';
|
||||
import { setCurrentlyLoadingFileSuite } from './globals';
|
||||
import { Suite } from './test';
|
||||
import { SerializedLoaderData } from './ipc';
|
||||
@ -236,10 +236,6 @@ function toLaunchServers(launchConfigs?: LaunchConfig | LaunchConfig[]): LaunchC
|
||||
return launchConfigs;
|
||||
}
|
||||
|
||||
function errorWithFile(file: string, message: string) {
|
||||
return new Error(`${file}: ${message}`);
|
||||
}
|
||||
|
||||
function validateConfig(file: string, config: Config) {
|
||||
if (typeof config !== 'object' || !config)
|
||||
throw errorWithFile(file, `Configuration file must export a single object`);
|
||||
|
||||
@ -15,7 +15,8 @@
|
||||
*/
|
||||
|
||||
import util from 'util';
|
||||
import type { TestError } from './types';
|
||||
import path from 'path';
|
||||
import type { TestError, Location } from './types';
|
||||
import { default as minimatch } from 'minimatch';
|
||||
|
||||
export class DeadlineRunner<T> {
|
||||
@ -147,3 +148,17 @@ export function forceRegExp(pattern: string): RegExp {
|
||||
return new RegExp(match[1], match[2]);
|
||||
return new RegExp(pattern, 'g');
|
||||
}
|
||||
|
||||
export function relativeFilePath(file: string): string {
|
||||
if (!path.isAbsolute(file))
|
||||
return file;
|
||||
return path.relative(process.cwd(), file);
|
||||
}
|
||||
|
||||
export function formatLocation(location: Location) {
|
||||
return relativeFilePath(location.file) + ':' + location.line + ':' + location.column;
|
||||
}
|
||||
|
||||
export function errorWithFile(file: string, message: string) {
|
||||
return new Error(`${relativeFilePath(file)}: ${message}`);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user