UNPKG

archunit

Version:

ArchUnit TypeScript is an architecture testing library, to specify and assert architecture rules in your TypeScript app

50 lines (45 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extendVitestMatchers = extendVitestMatchers; const result_factory_1 = require("../common/result-factory"); const violation_factory_1 = require("../common/violation-factory"); function isVitestProject() { return typeof process !== 'undefined' && !!process.env.VITEST; } function extendVitestMatchers(force = true) { // Unless we force it, only apply extend logic if its a vitest project if (!force && !isVitestProject()) { return; } if (typeof expect === 'undefined') { throw Error(`ArchUnitTS Vitest Integration Error: 'expect' is not defined globally. **Vitest Hint:** If you're using Vitest, you must have configured Vitest with \`globals: true\` in your \`vitest.config.ts\`. This means you need a \`vitest.config.ts\` file at project root with content that may look like this: \`\`\`ts import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { globals: true, // This line matters !! environment: 'node', coverage: { provider: 'v8', reporter: ['text', 'json', 'html'], }, include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)'], }, }); \`\`\` Without \`globals: true\`, the global \`expect\` function is not available, which prevents ArchUnitTS from extending Vitest with custom matchers like \`toPassAsync()\`.`); } expect.extend({ async toPassAsync(checkable, options) { if (!checkable) { return result_factory_1.ResultFactory.error('expected something checkable as an argument for expect()'); } const violations = await checkable.check(options); const testViolations = violations.map((v) => violation_factory_1.ViolationFactory.from(v)); return result_factory_1.ResultFactory.result(Boolean(this.isNot), testViolations); }, }); } //# sourceMappingURL=vitest-adapter.js.map