An open source design system that's fully customizable and agent ready
TypeScript
test(cli): provider-ledger loads the code under test natively (#10311)
Christopher Chedeaua477abd53859
diff --git a/packages/cli/foundation/integrations/provider-ledger.test.mjs b/packages/cli/foundation/integrations/provider-ledger.test.mjsindex ba26a484d6..0c966b5e8b 100644--- a/packages/cli/foundation/integrations/provider-ledger.test.mjs+++ b/packages/cli/foundation/integrations/provider-ledger.test.mjs@@ -7,15 +7,15 @@* codemod policy says otherwise.** The expected candidates come from the scenario description, never from the- * resolver. Fixtures live under a repo-local temp dir, not /tmp, because Vite- * refuses to dynamically import a module from outside the project root.+ * resolver. Fixtures live under the system temp folder, so TMPDIR chooses the+ * filesystem that takes each seed's writes and removals.*/import {afterAll, beforeAll, describe, expect, it} from 'vitest';import * as fs from 'node:fs';+import {createRequire} from 'node:module';+import * as os from 'node:os';import * as path from 'node:path';-import {Project, providerLedgerOf} from '../config/project.mjs';-import {loadProjectContext} from '../../api/upgrade/_adapter.mjs';import {expectedProjectInputs,generateScenario,@@ -23,6 +23,16 @@ import {writeScenario,} from '../../test-utils/provider-scenarios.mjs';+// The code under test loads natively, as the CLI runs, so each seed's fixture+// modules load as Node loads them. Through Vitest, each would be one fetch from+// its main process, which waits behind other workers on a loaded box.+// SYNC: require any other code under test here too.+const require = createRequire(import.meta.url);+/** @type {typeof import('../config/project.mjs')} */+const {Project, providerLedgerOf} = require('../config/project.mjs');+/** @type {typeof import('../../api/upgrade/_adapter.mjs')} */+const {loadProjectContext} = require('../../api/upgrade/_adapter.mjs');+// 200 seeds keep this near 4 s; any seed range must hold.const SEEDS = Array.from({length: 200}, (_, index) => index + 1);const OUTCOMES = ['contributes', 'set-aside', 'load-failed', 'alias-of'];@@ -34,7 +44,7 @@ let originalCwd;beforeAll(() => {originalCwd = process.cwd();- root = fs.mkdtempSync(path.join(process.cwd(), '.astryx-provider-ledger-'));+ root = fs.mkdtempSync(path.join(os.tmpdir(), '.astryx-provider-ledger-'));});// Only a seed that failed before removing its folder leaves one here.