Skip to content

Instantly share code, notes, and snippets.

@coreylight
Last active April 14, 2020 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreylight/7239907541de9cbd4686ce90a0d92142 to your computer and use it in GitHub Desktop.
Save coreylight/7239907541de9cbd4686ce90a0d92142 to your computer and use it in GitHub Desktop.
Run cypress
#!/usr/bin/env node
const { execSync } = require("child_process");
const fs = require("fs");
const glob = require("glob");
const open = require("open");
const [, , filePath] = process.argv;
if (!filePath) {
console.error("File path must be present as first argument.");
process.exit(1);
}
try {
console.log("Running Cypress...");
const proc = execSync(`npx cypress run --spec ${filePath}`);
const output = proc.toString();
console.log(output);
const lines = output.split("\n");
const foundLine = lines.find((line) => line.match("Finished processing"));
const replaced = foundLine
.trim()
.replace("- Finished processing:", "")
.replace(/\(\d.*seconds\)/, "")
.trim();
const arr = glob
.sync(`${replaced}/**/*.mp4`)
.map((name) => ({ name, modified: fs.statSync(name).mtimeMs }))
.sort((a, b) => b.modified - a.modified);
if (arr.length) {
open(arr[0].name);
} else {
console.log("No video file to open.");
}
} catch (err) {
console.log(err.stdout.toString());
}
{
"name": "run-cy",
"version": "0.1.0",
"bin": "./index.js",
"dependencies": {
"glob": "^7.1.6",
"open": "^7.0.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment