-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUtils.ts
More file actions
64 lines (56 loc) · 2.25 KB
/
Utils.ts
File metadata and controls
64 lines (56 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Suite, Test } from '@ephox/bedrock-common';
import sourceMappedStackTrace from 'sourcemapped-stacktrace';
// eslint-disable-next-line @typescript-eslint/no-empty-function
export const noop = (): void => {};
export const makeQueryParams = (session: string, offset: number, failed: number, skipped: number, retry: number): string => {
if (offset > 0 || retry > 0 || skipped > 0) {
const rt = (retry > 0 ? '&retry=' + retry : '');
const sk = (skipped > 0 ? '&skipped=' + skipped : '');
return '?session=' + session + '&offset=' + offset + '&failed=' + failed + sk + rt;
} else {
return '';
}
};
export const makeUrl = (session: string, offset: number, failed: number, skipped: number, retry: number): string => {
const baseUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
return baseUrl + makeQueryParams(session, offset, failed, skipped, retry);
};
export const formatElapsedTime = (start: number, end: number): string => {
const millis = end - start;
const seconds = Math.floor(millis / 1000);
const point = Math.floor(millis - (seconds * 1000) / 100);
const printable =
point < 10 ? '00' + point :
point < 100 ? '0' + point :
'' + point;
return seconds + '.' + printable + 's';
};
export const getFullTitle = (suiteOrTest: Suite | Test, separator: string): string => {
const parentTitle = suiteOrTest.parent?.fullTitle();
if (parentTitle !== undefined && parentTitle.length > 0) {
return `${parentTitle} ${separator} ${suiteOrTest.title}`;
} else {
return suiteOrTest.title;
}
};
export const makeSessionId = (): string => '' + Math.ceil((Math.random() * 100000000));
export const mapStackTrace = (stack: string | undefined): Promise<string> => new Promise((resolve) => {
if (stack) {
// If the stack trace format can't be found then an Error will be thrown.
// In that case lets just return the original stack instead.
try {
sourceMappedStackTrace.mapStackTrace(stack, (stack: string[]) => resolve(stack.join('\n')));
} catch (e) {
resolve(stack);
}
} else {
resolve('');
}
});
export const setStack = (error: Error, stack: string | undefined): void => {
try {
error.stack = stack;
} catch (err) {
// Do nothing
}
};