Last active
April 14, 2020 16:11
-
-
Save coreylight/7239907541de9cbd4686ce90a0d92142 to your computer and use it in GitHub Desktop.
Run cypress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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