Skip to content

Commit b97458d

Browse files
committed
saving status quo
1 parent 7c19bbd commit b97458d

File tree

6 files changed

+46
-40
lines changed

6 files changed

+46
-40
lines changed

__tests__/web.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const test = base.extend<MyActors>({
4141
// TODO: implement test for DoubleClick
4242
// TODO: test different details between Fill and Type
4343
test.describe('Testing screenplay-playwright-js web module', () => {
44-
test.skip('Navigate', async ({ actor }) => {
44+
test('Navigate', async ({ actor }) => {
4545
await test.step('Navigate to playwright page', async () => {
4646
await actor.attemptsTo(
4747
Navigate.to('https://google.de'),

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@playwright/test": "^1.38.0"
5454
},
5555
"dependencies": {
56-
"@testla/screenplay": "^1.0.0"
56+
"@testla/screenplay": "^1.1.0-beta.1"
5757
},
5858
"engines": {
5959
"node": ">=18.x.x"

src/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ export const ICON = {
44
FAIL: '✗',
55
SKIP: '⤿',
66
};
7+
8+
export const BLANKS_PER_INDENTATION_LEVEL = 4;

src/reporter/text-reporter.ts

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { STRUCTURED_LOGS_ENVVAR_NAME } from '@testla/screenplay';
12
import type {
23
FullResult,
34
Reporter, TestCase, TestResult, TestStatus,
@@ -37,7 +38,9 @@ class TextReporter implements Reporter {
3738
break;
3839
case 'failed':
3940
case 'timedOut':
40-
this.failed.push(testId);
41+
if (!this.failed.some((entry) => entry === testId)) {
42+
this.failed.push(testId);
43+
}
4144
break;
4245
case 'passed':
4346
default:
@@ -76,16 +79,6 @@ class TextReporter implements Reporter {
7679
}
7780
}
7881

79-
// async onStdOut(chunk: string | Buffer, test: TestCase): Promise<void> {
80-
// const result = await streamToString(
81-
// Readable.from(chunk)
82-
// .pipe(new FilterEventStream())
83-
// .pipe(new ParseEventStream())
84-
// .pipe(new TransformEventToTextStream()),
85-
// );
86-
// this.addToResultBuffer(result, test.id);
87-
// }
88-
8982
onBegin() {
9083
if (this.outputFile && existsSync(this.outputFile)) {
9184
rm(this.outputFile, (err) => {
@@ -95,25 +88,18 @@ class TextReporter implements Reporter {
9588
});
9689
}
9790

98-
process.env.TEASLA_SCREENPLAY_STRUCTURED_LOGS = 'true';
91+
process.env[STRUCTURED_LOGS_ENVVAR_NAME] = 'true';
9992
}
10093

10194
async onTestEnd(test: TestCase, result: TestResult) {
102-
// test.results[0].stdout
103-
// this.addToResultBuffer(`${new Date().toISOString()} [CASE] ${TextReporter.getResultStatusIcon(result.status)} ${test.parent.title} > ${test.title} [${test._projectId.toUpperCase()}] [${result.status.toUpperCase()}] (${TextReporter.printRuntime(result.duration)})`, test.id);
104-
// this.write(`${new Date().toISOString()} [CASE${result.retry > 0 ? ` RETRY#${result.retry}` : ''}] ${TextReporter.getResultStatusIcon(result.status)} ${test.parent.title} > ${test.title} [${test._projectId.toUpperCase()}] [${result.status.toUpperCase()}] (${TextReporter.printRuntime(result.duration)})`);
105-
// this.write(`${TextReporter.getResultStatusIcon(result.status)} ${test.parent.title} › ${test.title} ${result.retry > 0 ? `[RETRY#${result.retry}] ` : ''}[${result.status.toUpperCase()} after ${TextReporter.printRuntime(result.duration)}] (${test._projectId.toUpperCase()})`);
95+
// eslint-disable-next-line
96+
// @ts-ignore
97+
// eslint-disable-next-line
10698
this.write(`[${test._projectId.toUpperCase()}] ${TextReporter.getResultStatusIcon(result.status)} ${test.parent.title}${test.title} ${result.retry > 0 ? `[RETRY#${result.retry}] ` : ''}[${result.status.toUpperCase()} after ${TextReporter.printRuntime(result.duration)}]`);
107-
this.write('────────────────────────────────');
108-
// test.results[0].stdout.forEach((line: string): void => {
109-
110-
// });
111-
// test.results.forEach((result, index) => {
112-
// eslint-disable-next-line no-restricted-syntax
113-
// for (const resultX of test.results) {
114-
// if (resultX.retry > 0) {
115-
// this.write(`--- retry #${resultX.retry} ---`);
116-
// }
99+
if (result.status !== 'skipped') {
100+
this.write('────────────────────────────────');
101+
}
102+
117103
// eslint-disable-next-line no-await-in-loop
118104
const reportString = await streamToString(
119105
Readable.from(result.stdout)
@@ -124,14 +110,14 @@ class TextReporter implements Reporter {
124110
this.write(reportString);
125111

126112
this.putIntoBucket(TextReporter.getTestId(test), result.status);
127-
// };
128113
}
129114

130115
onEnd(result: FullResult) {
131116
this.write('────────────────────────────────\n');
132117
this.write(`Finished the run: ${result.status.toUpperCase()} after ${TextReporter.printRuntime(result.duration)}\n`);
133118
if (this.failed.length) {
134119
this.write(`Failed: ${this.failed.length}`);
120+
this.failed.sort().forEach((failed: string) => this.write(` - ${TextReporter.reformatFailedString(failed)}`))
135121
}
136122
if (this.skipped.length) {
137123
this.write(`Skipped: ${this.skipped.length}`);
@@ -149,6 +135,12 @@ class TextReporter implements Reporter {
149135

150136
private static printRuntime = (time: number) => `${(Math.round(time * 1000) / 1000000).toFixed(3)}s`;
151137

138+
private static reformatFailedString = (str: string) => {
139+
const firstArrowReplaced = str.replace('>', '›');
140+
const parts = firstArrowReplaced.split('›');
141+
return `[${parts[0].trim().toUpperCase()}] ✗ ${parts[1].trim().replaceAll('>', '›')}`;
142+
};
143+
152144
// eslint-disable-next-line class-methods-use-this
153145
printsToStdio(): boolean {
154146
return false;

src/streams/EventToTextTransformer.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ACTIVITY_TYPE, EXEC_STATUS } from '@testla/screenplay';
22
import { ExecStatus, LogEvent } from '@testla/screenplay/lib/interfaces';
33
import { Transform, TransformCallback } from 'stream';
4-
import { ICON } from '../constants';
4+
import { BLANKS_PER_INDENTATION_LEVEL, ICON } from '../constants';
55

66
export class TransformEventToTextStream extends Transform {
77
constructor() {
@@ -28,20 +28,32 @@ export class TransformEventToTextStream extends Transform {
2828
return badge;
2929
}
3030

31+
private static indent(level: number) {
32+
let indentation = ' ';
33+
34+
for (let i = 0; i <= level * BLANKS_PER_INDENTATION_LEVEL; i += 1) {
35+
indentation = ` ${indentation}`;
36+
}
37+
38+
return indentation;
39+
}
40+
3141
// eslint-disable-next-line no-underscore-dangle
3242
_transform(record: LogEvent, encoding: BufferEncoding, callback: TransformCallback) {
3343
const msg = `${
3444
record.time
3545
} [${
3646
TransformEventToTextStream.getStatusText(record.status)
37-
}] ${
47+
}]${
48+
TransformEventToTextStream.indent(record.wrapLevel)
49+
}${
3850
record.status !== EXEC_STATUS.FAILED ? (record.activityType === ACTIVITY_TYPE.QUESTION ? ICON.PASS : ICON.EXEC) : ICON.FAIL
3951
} ${
4052
record.actor
4153
} ${
42-
record.activity
54+
record.activityAction
4355
} ${
44-
record.activityText
56+
record.activityDetails
4557
} (${record.filePath})`;
4658

4759
this.push(msg);

0 commit comments

Comments
 (0)