Skip to content

Commit

Permalink
feat(console-reporter): revert to only global error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
In1th committed Feb 29, 2024
1 parent 3f9d729 commit a375788
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 62 deletions.
3 changes: 1 addition & 2 deletions integration/playwright-test/playwright.config.ts
Expand Up @@ -36,8 +36,7 @@ const config: PlaywrightTestConfig = {
crew: [
'@integration/testing-tools:ChildProcessReporter',
'@serenity-js/core:StreamReporter',
],
includeSnippetOnError: !!process.env.SHOW_SNIPPETS
]
},
],
...[
Expand Down
28 changes: 1 addition & 27 deletions integration/playwright-test/spec/failing_scenarios.spec.ts
Expand Up @@ -166,8 +166,7 @@ describe('@serenity-js/playwright-test', function () {

it('fails with unhandled global exception', () => playwrightTest(
'failing/global-error-thrown.spec.ts',
'--project=default',
'--pass-with-no-tests' // without that outcome changes to no tests found
'--project=default'
)
.then(ifExitCodeIsOtherThan(1, logOutput))
.then(result => {
Expand All @@ -182,30 +181,5 @@ describe('@serenity-js/playwright-test', function () {
})
;
}));

it('fails with unhandled global exception with snippet', () => playwrightTest(
'failing/global-error-thrown.spec.ts',
'--project=default',
'--pass-with-no-tests', // without that outcome changes to no tests found
'export SHOW_SNIPPETS=true'
)
.then(ifExitCodeIsOtherThan(1, logOutput))
.then(result => {
expect(result.exitCode).to.equal(1);

PickEvent.from(result.events)
.next(TestRunFinished, event => {
const outcome: ProblemIndication = event.outcome as ProblemIndication;
expect(outcome).to.be.instanceOf(ExecutionFailedWithError);
expect(outcome.error.name).to.equal('Error');
expect(outcome.error.message).to.include('Error: Something happened');
expect(outcome.error.message).to.include('at failing/global-error-thrown.spec.ts:5');
expect(outcome.error.message).to.include('describe(\'Playwright Test reporting\', () => {');
expect(outcome.error.message).to.include('> 5 |');
expect(outcome.error.message).to.include('throw new Error(\'Something happened\');');
expect(outcome.error.message).to.include('describe(\'A scenario\', () => {');
})
;
}));
});
});
11 changes: 0 additions & 11 deletions integration/playwright-test/src/playwright-test.ts
Expand Up @@ -29,17 +29,6 @@ export function playwrightTest(...params: string[]): Promise<SpawnResult> {
reporters.map(([name, outputPath]) => [ `REPORTER_${ name.toUpperCase() }`, outputPath ])
);

const envModifier = params.find(parameter => parameter.startsWith('export '));
if (envModifier){
try{
const [envKey, envValue] = envModifier.replace('export ', '').split('=');
env[envKey] = envValue;
}
catch{
throw new Error('Invalid env variable modifier. Use "export KEY=VALUE" format');
}
}

return spawner(
playwrightExecutable,
{ cwd: path.resolve(__dirname, '..'), env },
Expand Down
Expand Up @@ -80,13 +80,6 @@ export interface SerenityReporterForPlaywrightTestConfig {
* - {@apilink SerenityConfig.outputStream}
*/
outputStream?: OutputStream;

/**
* Flag for including code snippets on error
*
* Defaults to false.
*/
includeSnippetOnError?: boolean;
}

/**
Expand All @@ -98,7 +91,6 @@ export class SerenityReporterForPlaywrightTest implements Reporter {
private errorParser = new PlaywrightErrorParser();
private sceneIds: Map<string, CorrelationId> = new Map();
private unhandledError?: Error;
private includeSnippetOnError: boolean;

/**
* @param config
Expand All @@ -116,7 +108,6 @@ export class SerenityReporterForPlaywrightTest implements Reporter {
),
) {
this.serenity.configure(config);
this.includeSnippetOnError = config.includeSnippetOnError ?? false;
}

onBegin(config: FullConfig, suite: Suite): void {
Expand Down Expand Up @@ -218,7 +209,9 @@ export class SerenityReporterForPlaywrightTest implements Reporter {
}

onError(error: TestError): void {
this.unhandledError = this.errorParser.errorFrom(error, this.includeSnippetOnError);
if (!this.unhandledError) {
this.unhandledError = this.errorParser.errorFrom(error);
}
}

private determineScenarioOutcome(
Expand Down Expand Up @@ -249,11 +242,11 @@ export class SerenityReporterForPlaywrightTest implements Reporter {

if (['failed', 'interrupted', 'timedOut'].includes(result.status)) {
if (test.retries > result.retry) {
return new ExecutionIgnored(this.errorParser.errorFrom(result.error, this.includeSnippetOnError));
return new ExecutionIgnored(this.errorParser.errorFrom(result.error));
}

return new ExecutionFailedWithError(
this.errorParser.errorFrom(result.error, this.includeSnippetOnError),
this.errorParser.errorFrom(result.error),
);
}

Expand Down Expand Up @@ -360,19 +353,11 @@ class PlaywrightErrorParser {
'g',
);

public errorFrom(testError: TestError, includeSnippet: boolean): Error {
let message =
public errorFrom(testError: TestError): Error {
const message =
testError.message &&
PlaywrightErrorParser.stripAsciiFrom(testError.message);

if (includeSnippet){
const snippet =
testError.snippet &&
PlaywrightErrorParser.stripAsciiFrom(testError.snippet);

message = snippet ? [message, snippet].join('\n') : message;
}

let stack =
testError.stack && PlaywrightErrorParser.stripAsciiFrom(testError.stack);

Expand Down

0 comments on commit a375788

Please sign in to comment.