mochaに起動時にいろいろ(カスタム引数を渡すとか)やる
.mocharc.js
にてbootstrapをrequire
"use strict"; const { dirname } = require("path"); module.exports = { require: [ __dirname + "/test/bootstrap"], timeout: 10000, };
/test/bootstrap.js
がmocha起動時に実行される
// project root dir 基準の module path を可能に import { addPath } from "app-module-path"; addPath(__dirname + "/.."); // mochaにカスタム変数を渡せる const useWtf = process.argv.find((v) => v.indexOf("--wtf") == 0); process.env.GOOGLE_APPLICATION_CREDENTIALS = __dirname + "/../config/gcp-service-account/1234.json"; import * as wtf from "wtfnode"; exports.mochaHooks = { afterAll() { // mochaのプロセスが終了しないときの調査ツール // wftは残ってるprocessを教えてくれる https://github.com/myndzi/wtfnode , https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit if (useWtf) wtf.dump(); }, };