From 3104f998da8be8358070d99fc63d486ccb44f7f8 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Tue, 15 Oct 2019 14:50:06 -0400 Subject: [PATCH] default e2e browser -> electron Run afterEaches when skipping testo Recurse upwards with runAfterEach stop promise chains --- .../server/test/support/helpers/e2e.coffee | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/server/test/support/helpers/e2e.coffee b/packages/server/test/support/helpers/e2e.coffee index 6c794495d4..f4d1f4b0d1 100644 --- a/packages/server/test/support/helpers/e2e.coffee +++ b/packages/server/test/support/helpers/e2e.coffee @@ -1,6 +1,7 @@ require("../../spec_helper") _ = require("lodash") +chalk = require("chalk") cp = require("child_process") niv = require("npm-install-version") path = require("path") @@ -110,6 +111,8 @@ normalizeStdout = (str, options = {}) -> startServer = (obj) -> { onServer, port, https } = obj + console.log('STARTING ON', port) + app = express() if https @@ -117,6 +120,8 @@ startServer = (obj) -> else srv = http.Server(app) + srv.port = port + allowDestroy(srv) app.use(morgan("dev")) @@ -132,7 +137,13 @@ startServer = (obj) -> resolve(srv) +## since the resolved object is a .thenable, it won't get wrapped in a +## Promise, which then leads to the rest of the Promise.chain getting no-op'd +stopPromise = () -> + { then: stopPromise, catch: stopPromise } + stopServer = (srv) -> + console.log('STOPPING ON', srv.port) srv.destroyAsync() copy = -> @@ -199,6 +210,20 @@ localItFn = (title, options = {}) -> .each(runTestInEachBrowser) .value() +runAfterEach = (runnable) -> + Promise.map runnable._afterEach || [], (afterEachHook) -> + { fn } = afterEachHook + + fn = fn.bind(runnable) + + if fn.length == 1 + return Promise.fromCallback fn + + return fn() + .then -> + if runnable.parent + runAfterEach(runnable.parent) + ## eslint-ignore-next-line localItFn.only = (title, options) -> options.only = true @@ -287,6 +312,7 @@ module.exports = e2e = { options: (ctx, options = {}) -> _.defaults(options, { + browser: 'electron' project: e2ePath timeout: if options.exit is false then 3000000 else 120000 originalTitle: null @@ -373,14 +399,18 @@ module.exports = e2e = { expect(process.exit).to.be.calledWith(code) exec: (ctx, options = {}) -> - ## if the current test wasn't meant to run in the current browser, skip it - if (b = process.env.BROWSER) and b isnt options.browser - console.log("The current test is meant to run in #{options.browser}, but BROWSER env var = #{b}. Skipping...") - return ctx.skip() - options = @options(ctx, options) args = @args(options) + ## if the current test wasn't meant to run in the current browser, skip it + if (b = process.env.BROWSER) and b isnt options.browser + console.log(chalk.cyan("This test is meant to run in #{chalk.green(options.browser)}, but process.env.BROWSER is #{chalk.green(b)}. Skipping...")) + + return runAfterEach(ctx._runnable).then -> + ctx.skip() + ## dirty-nasty trick to halt Promises chained off e2e.exec + stopPromise() + args = ["index.js"].concat(args) stdout = ""