Skip to content

Commit

Permalink
Update reporters independent of upload (#262)
Browse files Browse the repository at this point in the history
updateReporters was only triggered when uploading was enabled
so non-upload workflows never saw the junit updates.

Added context to the "test-run" pending work so it could
trigger the updateReporters call instead.
  • Loading branch information
ryanjduffy authored Oct 19, 2023
1 parent 659797e commit 7fc569b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
27 changes: 13 additions & 14 deletions packages/cypress/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference types="cypress" />

import semver from "semver";
import { getPlaywrightBrowserPath, RecordingEntry, listAllRecordings } from "@replayio/replay";
import { TestMetadataV2, initMetadataFile, log, warn } from "@replayio/test-utils";
import { getPlaywrightBrowserPath, RecordingEntry } from "@replayio/replay";
import { TestMetadataV2, initMetadataFile } from "@replayio/test-utils";
import path from "path";
import dbg from "debug";
import chalk from "chalk";
Expand Down Expand Up @@ -59,8 +59,8 @@ function getAuthKey<T extends { env?: { [key: string]: any } }>(config: T): stri

function updateReporters(
relativePath: string,
config: Cypress.PluginConfigOptions,
filter: PluginOptions["filter"]
recordings: RecordingEntry[],
config: Cypress.PluginConfigOptions
) {
const { reporter, reporterOptions } = config;
debug("updateReporter: %o", { reporter, reporterOptions });
Expand All @@ -69,8 +69,6 @@ function updateReporters(
}

const projectBase = path.dirname(config.configFile);
const recordings = listAllRecordings({ all: true, filter: getSpecFilter(relativePath, filter) });
debug("Found %d recordings for %s", recordings.length, relativePath);
if (recordings.length === 0) {
return;
}
Expand Down Expand Up @@ -122,17 +120,18 @@ async function onAfterRun() {

const utilsPendingWork = await cypressReporter.onEnd();
utilsPendingWork.forEach(entry => {
if (entry.type === "upload" && "recording" in entry && entry.recording.metadata.test) {
const testRun = entry.recording.metadata.test as TestMetadataV2.TestRun;
const tests = testRun.tests;
if (entry.type === "post-test" && !("error" in entry)) {
const {
testRun: {
tests,
source: { path },
},
recordings,
} = entry;
const completedTests = tests.filter(t => ["passed", "failed", "timedOut"].includes(t.result));

if (cypressReporter) {
updateReporters(
testRun.source.path,
cypressReporter.config,
cypressReporter.options.filter
);
updateReporters(path, recordings, cypressReporter.config);
}

if (
Expand Down
10 changes: 9 additions & 1 deletion packages/test-utils/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ type UploadPendingWork = PendingWorkEntry<
recording: RecordingEntry;
}
>;
type PostTestPendingWork = PendingWorkEntry<"post-test">;
type PostTestPendingWork = PendingWorkEntry<
"post-test",
{
recordings: RecordingEntry[];
testRun: TestRun;
}
>;
type PendingWork =
| TestRunPendingWork
| TestRunTestsPendingWork
Expand Down Expand Up @@ -736,6 +742,8 @@ class ReplayReporter {

return {
type: "post-test",
recordings,
testRun,
};
}

Expand Down

0 comments on commit 7fc569b

Please sign in to comment.