There was an error while loading. Please reload this page.
loadYaml loads the contents of a YAML file and parses them into an object.
src: string | URL
The path or URL to the YAML file you’d like to load.
The contents of the YAML file, parsed as an object.
You can mock YAML files in your tests like so:
import { describe, expect, it, vi } from 'vitest' import { readFileSync } from 'node:fs' import yourFunctionThatUsesLoadYaml from './func.ts' vi.mock('node:fs', async importOriginal => ({ ...await importOriginal<typeof import('node:fs')>(), readFileSync: vi.fn() })) describe('yourFunctionThatUsesLoadYaml', () => { it('loads YAML', () => { vi.mocked(readFileSync).mockReturnValue('id: abc123\nname: Test File') const { id, name } = yourFunctionThatUsesLoadYaml() expect(id).toBe('abc123') expect(name).toBe('Test File') }) })
import { loadYaml } from '@revolutionarygamesco/common/testing' const { id, name } = loadYaml<{ id: string, name: string }>('./path/to/file.yaml')