UNPKG

@palmares/tests

Version:

This defines a default test framework testing stuff inside of the framework

68 lines (62 loc) 2.08 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/domain.ts import { domain } from "@palmares/core"; // src/commands/test.ts import { std } from "@palmares/core"; // src/utils.ts async function setTestAdapter(adapter, withCustomProps = false) { globalThis.$PTestAdapter = adapter; if (withCustomProps) { await adapter.getCustomProps().then((props) => { globalThis.$PTestAdapterCustomProps = props; }); } } __name(setTestAdapter, "setTestAdapter"); // src/commands/test.ts var filesToTest = []; async function test(domains, settings) { for (const domain2 of domains) { if (domain2.getTests) { const testFilesOrTestFile = domain2.getTests(); if (Array.isArray(testFilesOrTestFile)) filesToTest.push(...testFilesOrTestFile); else filesToTest.push(testFilesOrTestFile); } } const newTestAdapter = new settings.testAdapter(); await setTestAdapter(newTestAdapter); return newTestAdapter.run(filesToTest, `import { run } from '@palmares/tests'; await run('${await std.os.platform() === "windows" ? "file:/" : ""}${std.files.getPathToFileURL(settings.settingsLocation)}');`, { mkdir: std.files.makeDirectory, join: std.files.join, writeFile: std.files.writeFile, removeFile: std.files.removeFile }); } __name(test, "test"); // src/domain.ts var testDomainModifier = domain("@palmares/tests", "", {}); var testDomain = domain("@palmares/tests", "", { commands: { test: { description: "Run the tests in your palmares application", keywordArgs: void 0, positionalArgs: void 0, handler: /* @__PURE__ */ __name((args) => { test(args.domains, args.settings); }, "handler") } }, // eslint-disable-next-line ts/require-await load: /* @__PURE__ */ __name(async (settings) => { if (settings.$$test) { const adapterInstance = new settings.testAdapter(); await setTestAdapter(adapterInstance, true); } }, "load") }); export { testDomain, testDomainModifier };