From 42dfd813fedb9497e3df23fc100f810e5f4cdab7 Mon Sep 17 00:00:00 2001 From: OrcaWin Date: Fri, 16 Oct 2026 11:05:42 -0700 Subject: [PATCH] test(ci): consolidate import resolution behavior proof (#29782) Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com> --- .../scripts/ci-unit-dependency-graph.test.mjs | 39 +++++++++++- .../ci-unit-import-resolution-budget.test.mjs | 59 ------------------- 2 files changed, 37 insertions(+), 61 deletions(-) delete mode 100644 config/scripts/ci-unit-import-resolution-budget.test.mjs diff --git a/config/scripts/ci-unit-dependency-graph.test.mjs b/config/scripts/ci-unit-dependency-graph.test.mjs index 3859d72949e..b22566711f8 100644 --- a/config/scripts/ci-unit-dependency-graph.test.mjs +++ b/config/scripts/ci-unit-dependency-graph.test.mjs @@ -1,8 +1,11 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' -import { afterEach, expect, it } from 'vitest' -import { collectUnitDependencyGraph } from './ci-unit-dependency-graph.mjs' +import { afterEach, describe, expect, it } from 'vitest' +import { + buildUnitDependencyGraph, + collectUnitDependencyGraph +} from './ci-unit-dependency-graph.mjs' import { selectUnitFiles } from './ci-unit-selection.mjs' const temporary = [] @@ -141,3 +144,35 @@ it.each([ }) } ) + +describe('unit graph import resolution', () => { + it('keeps first-match precedence across literal paths, extensions and index files', () => { + const sources = new Map([ + ['src/leaf', ''], + ['src/leaf.ts', ''], + ['src/leaf.tsx', ''], + ['src/component.tsx', ''], + ['src/component.js', ''], + ['src/folder/index.ts', ''], + ['src/folder/index.tsx', ''], + ['src/config.json', '{}'], + ['src/renderer/src/view.tsx', ''], + ['src/use.ts', "import './leaf'; import './component'; import './folder'; import './config'"], + ['src/aliases.ts', "import '@renderer/view'; import '@/view'; import 'external-package'"], + ['src/missing.ts', "import './missing-file'"], + ['src/dynamic.ts', 'import(variablePath)'], + ['config/owner.mjs', "import '../src/leaf'"], + ['tests/owner.ts', "import '../src/leaf'"] + ]) + expect(buildUnitDependencyGraph(sources)).toEqual({ + reverse: new Map([ + ['src/leaf', new Set(['src/use.ts', 'config/owner.mjs', 'tests/owner.ts'])], + ['src/component.tsx', new Set(['src/use.ts'])], + ['src/folder/index.ts', new Set(['src/use.ts'])], + ['src/config.json', new Set(['src/use.ts'])], + ['src/renderer/src/view.tsx', new Set(['src/aliases.ts'])] + ]), + opaque: new Set(['src/missing.ts', 'src/dynamic.ts', 'config/owner.mjs', 'tests/owner.ts']) + }) + }) +}) diff --git a/config/scripts/ci-unit-import-resolution-budget.test.mjs b/config/scripts/ci-unit-import-resolution-budget.test.mjs deleted file mode 100644 index bf1f04941b5..00000000000 --- a/config/scripts/ci-unit-import-resolution-budget.test.mjs +++ /dev/null @@ -1,59 +0,0 @@ -import { describe, expect, it, vi } from 'vitest' -import { buildUnitDependencyGraph } from './ci-unit-dependency-graph.mjs' - -describe('unit graph import resolution', () => { - it('avoids allocating an extension-candidate array for every resolved import', () => { - const consumers = Array.from({ length: 1000 }, (_, index) => `src/consumer-${index}.ts`) - const sources = new Map([ - ['src/leaf', 'export const value = 1'], - ...consumers.map((file) => [file, "import './leaf'"]) - ]) - const originalMap = Array.prototype.map - let extensionArrays = 0 - const spy = vi.spyOn(Array.prototype, 'map').mockImplementation(function (...args) { - if (this.length === 10 && this[0] === '' && this[1] === '.ts' && this[9] === '/index.js') { - extensionArrays += 1 - } - return originalMap.apply(this, args) - }) - try { - const graph = buildUnitDependencyGraph(sources) - spy.mockRestore() - expect([...graph.reverse]).toEqual([['src/leaf', new Set(consumers)]]) - expect(graph.opaque).toEqual(new Set()) - expect(extensionArrays).toBe(0) - } finally { - spy.mockRestore() - } - }) - - it('keeps first-match precedence across literal paths, extensions and index files', () => { - const sources = new Map([ - ['src/leaf', ''], - ['src/leaf.ts', ''], - ['src/leaf.tsx', ''], - ['src/component.tsx', ''], - ['src/component.js', ''], - ['src/folder/index.ts', ''], - ['src/folder/index.tsx', ''], - ['src/config.json', '{}'], - ['src/renderer/src/view.tsx', ''], - ['src/use.ts', "import './leaf'; import './component'; import './folder'; import './config'"], - ['src/aliases.ts', "import '@renderer/view'; import '@/view'; import 'external-package'"], - ['src/missing.ts', "import './missing-file'"], - ['src/dynamic.ts', 'import(variablePath)'], - ['config/owner.mjs', "import '../src/leaf'"], - ['tests/owner.ts', "import '../src/leaf'"] - ]) - expect(buildUnitDependencyGraph(sources)).toEqual({ - reverse: new Map([ - ['src/leaf', new Set(['src/use.ts', 'config/owner.mjs', 'tests/owner.ts'])], - ['src/component.tsx', new Set(['src/use.ts'])], - ['src/folder/index.ts', new Set(['src/use.ts'])], - ['src/config.json', new Set(['src/use.ts'])], - ['src/renderer/src/view.tsx', new Set(['src/aliases.ts'])] - ]), - opaque: new Set(['src/missing.ts', 'src/dynamic.ts', 'config/owner.mjs', 'tests/owner.ts']) - }) - }) -})