console-fail-test
Version:
Gently fails test runs if the console was used during them. 📢
56 lines • 2.08 kB
JavaScript
import { selectAvaEnvironment } from "./ava.js";
import { selectJasmineEnvironment } from "./jasmine.js";
import { selectJestEnvironment } from "./jest.js";
import { selectLabEnvironment } from "./lab.js";
import { selectMochaEnvironment } from "./mocha.js";
import { selectNodeTapEnvironment } from "./nodeTap.js";
import { selectVitestEnvironment } from "./vitest.js";
const testEnvironmentsByName = /* @__PURE__ */ new Map([
["jasmine", selectJasmineEnvironment],
["jest", selectJestEnvironment],
["mocha", selectMochaEnvironment],
["vitest", selectVitestEnvironment]
]);
const detectableTestEnvironmentSelectors = [
// These environments only work with received modules, so they should come first
selectAvaEnvironment,
selectLabEnvironment,
selectNodeTapEnvironment,
selectVitestEnvironment,
// Jest should come before Jasmine because Jest includes a monkey-patched Jasmine
selectJestEnvironment,
selectJasmineEnvironment,
// Mocha should be last because it's difficult to accurately detect
// See https://github.com/JoshuaKGoldberg/console-fail-test/issues/10
selectMochaEnvironment
];
const selectTestFramework = (request) => {
if (typeof request.testFramework === "string") {
const getter = testEnvironmentsByName.get(request.testFramework);
if (getter === void 0) {
throw new Error(
`Requested test framework '${request.testFramework}' not known by name in console-fail-test.`
);
}
const environment = getter(request);
if (environment === void 0) {
throw new Error(
`Requested test framework '${request.testFramework}' does not seem to be active.`
);
}
return environment;
}
for (const testEnvironmentGetter of detectableTestEnvironmentSelectors) {
const environment = testEnvironmentGetter(request);
if (environment !== void 0) {
return environment;
}
}
throw new Error(
"Could not auto-detect test environment; consider passing it directly to cft."
);
};
export {
selectTestFramework
};
//# sourceMappingURL=selectTestFramework.js.map