Skip to content

Instantly share code, notes, and snippets.

@rowellx68
Created March 15, 2019 23:00
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 rowellx68/ea57bbbcd1ed416bcef8cf55fb1cfd98 to your computer and use it in GitHub Desktop.
Save rowellx68/ea57bbbcd1ed416bcef8cf55fb1cfd98 to your computer and use it in GitHub Desktop.
const gulp = require("gulp");
const { spawn } = require("child_process");
const cypress = require("../gulp-cypress");
// hold onto the server process
let server;
function startServer(done) {
server = spawn(process.argv[0], ["au", "watch", "---env", "stage"], {
detached: true,
stdio: "ignore"
});
server.unref();
done();
}
function runCypress(done) {
const spec = "test/cypress/integration/**/*.spec.ts";
return gulp
.src("/")
.pipe(cypress({spec}))
.on("error", error => handleError(error, done))
.on("end", () => killServer(done));
}
function killServer(done) {
server.kill();
done();
}
function handleError(error, done) {
server.kill();
done(error);
}
const runTests = gulp.series(startServer, runCypress, killServer);
module.exports = {
run: runTests
};
const es = require("event-stream");
const cypress = require("cypress");
module.exports = function (options) {
// change as required
const defaults = {
reporter: "mocha-teamcity-reporter",
browser: "chrome"
};
options = Object.assign(defaults, options || {});
return es.through(() => { }, function () {
const stream = this;
cypress.run(options)
.then(() => {
stream.emit("end");
})
.catch(() => {
stream.emit("error");
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment