diff --git a/.gitignore b/.gitignore index 9c243f01..f19c6dcb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /_build/ /static/*.bundle.js /static/*.bundle.js.map +/static/bundle.css # Build helper files. /.build* diff --git a/package.json b/package.json index d3bf3133..9e6d4c77 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,8 @@ "stats-webpack-plugin": "^0.7.0", "typescript": "3.9.3", "webpack": "4.41.0", - "webpack-cli": "3.3.2" + "webpack-cli": "3.3.2", + "why-is-node-running": "2.0.3" }, "dependencies": { "@gristlabs/connect-sqlite3": "0.9.11", diff --git a/test/mocha.opts b/test/mocha.opts index ac4bcb20..59f9bdad 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,2 +1,3 @@ --require source-map-support/register +test/report-why-tests-hang test/init-mocha-webdriver diff --git a/test/report-why-tests-hang.js b/test/report-why-tests-hang.js new file mode 100644 index 00000000..716fca23 --- /dev/null +++ b/test/report-why-tests-hang.js @@ -0,0 +1,34 @@ +/** + * Mocha 4 no longer forces exit of a process after tests end, so if a setTimeout() or anything + * else is keeping node running, tests will hang after finishing. + * + * This helper module, always included via mocha.opts, ensures we print something if that happens. + * We use why-is-node-running module to print something informative. + */ + +/* global after */ + +const whyIsNodeRunning = require('why-is-node-running'); + +function report() { + whyIsNodeRunning(); + console.warn("*******************************************************"); + console.warn("Something above prevented node from exiting on its own."); + console.warn("*******************************************************"); + // We want to exit, but process.exit(1) doesn't work, since mocha catches it and insists on + // exiting with the test status result (which may be 0, and we need to indicate failure). + process.kill(process.pid, 'SIGTERM'); +} + +after(() => { + // --no-exit|-E flag is interpreted by mocha-webdriver library to start REPL on failure, and we + // do NOT want to output a big dump about that. + const noexit = process.argv.includes("--no-exit") || process.argv.includes('-E'); + if (noexit) { + console.log("report-why-tests-hang silenced with --no-exit flag"); + } else { + // If still hanging after 5s after tests finish, say something. Unref() ensures that THIS + // timeout doesn't itself keep node from exiting. + setTimeout(report, 5000).unref(); + } +}); diff --git a/yarn.lock b/yarn.lock index d0dc66fb..4bedf649 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5957,6 +5957,11 @@ stack-trace@0.0.x: resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0" integrity sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA= +stackback@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/stackback/-/stackback-0.0.2.tgz#1ac8a0d9483848d1695e418b6d031a3c3ce68e3b" + integrity sha1-Gsig2Ug4SNFpXkGLbQMaPDzmjjs= + static-extend@^0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" @@ -6894,6 +6899,13 @@ which@1.3.1, which@^1.2.14, which@^1.2.9: dependencies: isexe "^2.0.0" +why-is-node-running@2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/why-is-node-running/-/why-is-node-running-2.0.3.tgz#86619c2861405d3509f55268684fc85e7f4ce145" + integrity sha512-XmzbFN2T859avcs5qAsiiK1iu0nUpSUXRgiGsoHPcNijxhIlp1bPQWQk6ANUljDWqBtAbIR2jF1HxR0y2l2kCA== + dependencies: + stackback "0.0.2" + wide-align@1.1.3, wide-align@^1.1.0: version "1.1.3" resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457"