Skip to content

Commit

Permalink
chore(e2e): fix reporter writer (fails if output directory does not e…
Browse files Browse the repository at this point in the history
…xist)
  • Loading branch information
ala-n committed Feb 12, 2024
1 parent ff9c37f commit 10ab011
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions e2e/reporters/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const {print} = require('./printers');

const sanitize = (str) => (str || '').replace(/\W+/g, '-').toLowerCase();

const writeFileSafe = (filename, data) => {
const dirname = path.dirname(filename);
if (!fs.existsSync(dirname)) {
fs.mkdirSync(dirname, {recursive: true});
}
fs.writeFileSync(filename, data);
};

class SnapshotAwareReporter {
constructor(globalConfig, options) {
this._globalConfig = globalConfig;
Expand Down Expand Up @@ -70,14 +78,14 @@ class SnapshotAwareReporter {
async onRunComplete(contexts, results) {
const stats = this.buildStats(results);
const files = this.buildTestResults(results);
fs.writeFileSync(this._options.outputPath, print({stats, files}));
writeFileSafe(this._options.outputPath, print({stats, files}));

if (process.env.GITHUB_ACTIONS && process.env.DIFF_REPORT_BRANCH && this._options.outputPublishPath) {
const serverUrl = process.env.GITHUB_SERVER_URL;
const repository = process.env.GITHUB_REPOSITORY;
const branch = process.env.DIFF_REPORT_BRANCH;
const basePath = `${serverUrl}/${repository}/blob/${branch}/`;
fs.writeFileSync(this._options.outputPublishPath, print({stats, files, basePath}));
writeFileSafe(this._options.outputPublishPath, print({stats, files, basePath}));
}
}
}
Expand Down

0 comments on commit 10ab011

Please sign in to comment.