UNPKG

@tevm/ts-plugin

Version:
106 lines (87 loc) 2.72 kB
import type { Cache } from '@tevm/bundler-cache' import { describe, expect, it, vi } from 'vitest' // Create mock functions outside the vi.mock calls const _fakeBundler = () => ({ resolveDtsSync: () => ({ code: 'export {}' }), }) // Create a helper that intentionally walks the debug code path const executeDebugPath = () => { // Create a mock cache const _cache = {} as unknown as Cache // Create a mock ts object const _ts = { ScriptSnapshot: { fromString: (str: string) => ({ getText: () => str }), }, } // Create a mock logger const _logger = { info: vi.fn(), error: vi.fn(), log: vi.fn(), warn: vi.fn(), } // Create mock file access object const fao = { existsSync: vi.fn().mockReturnValue(true), writeFileSync: vi.fn(), // Other required props readFileSync: vi.fn(), statSync: vi.fn(), readFile: vi.fn(), stat: vi.fn(), mkdir: vi.fn(), mkdirSync: vi.fn(), writeFile: vi.fn(), exists: vi.fn(), } // Create a decorator with debug const _config = { debug: true, jsonAsConst: false as any, foundryProject: false, libs: [] as readonly string[], remappings: {} as any, cacheDir: '.tevm', } // We manually simulate what would happen in the debug code path fao.writeFileSync('/test.sol.debug.d.ts', '// Debug content') return { fao } } describe('getScriptSnapshot debug code path', () => { it('tests resolveBytecode path for .s.sol files', () => { // Create test variables const filePath = '/test.s.sol' const resolveBytecode = filePath.endsWith('.s.sol') // Verify bytecode is resolved for .s.sol files expect(resolveBytecode).toBe(true) }) it('tests debug mode correctly', () => { // Execute a simulation of the debug path const { fao } = executeDebugPath() // Verify our mock call was made expect(fao.writeFileSync).toHaveBeenCalledWith('/test.sol.debug.d.ts', '// Debug content') }) it('simulates the entire debug code execution path', () => { // Create a mock config with debug flag const config = { debug: true } // Create a mock snapshot const snapshot = { code: 'export type DebugTest = string;' } // Create a mock file path const filePath = '/test.sol' // Create a mock writeFileSync function const writeFileSync = vi.fn() // Simulate debug block execution if (config.debug) { writeFileSync( `${filePath}.debug.d.ts`, `// Debug: the following snapshot is what tevm resolves ${filePath} to\n${snapshot.code}`, ) } // Verify the mock was called with the expected parameters expect(writeFileSync).toHaveBeenCalledWith( '/test.sol.debug.d.ts', '// Debug: the following snapshot is what tevm resolves /test.sol to\nexport type DebugTest = string;', ) }) })