Skip to content

Commit

Permalink
use strip-ansi on examples outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Nov 4, 2023
1 parent 6c43202 commit c5805d4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs = require('fs');
import path = require('path');
import childProcess = require('child_process');
import stripAnsi = require('strip-ansi');

const examplesDir = path.join(__dirname, '../examples');
const examples = fs.readdirSync(examplesDir).filter(ex => /^\d/.exec(ex));
Expand Down Expand Up @@ -28,6 +29,7 @@ examples.forEach(ex => {
.filter(Boolean)
.flatMap(cmd => {
let output = childProcess.execSync(`sh -c "${cmd} 2>&1"`, { cwd: dir }).toString().trim();
output = stripAnsi(output);
output = cmd.startsWith('npm') || cmd.endsWith('--help') ? '...' : output; // npm commands and `--help` are formatted inconsistently and aren't v relevant
output = output.split(process.cwd()).join('<<cwd>>'); // cwd varies by machine
output = output.replace(/durationSeconds: .*/g, 'durationSeconds: ???'); // migrations durations vary by a few milliseconds
Expand Down

0 comments on commit c5805d4

Please sign in to comment.