import{test} from 'vitest' import { ConfigReader } from '../models/ConfigReader'; const cfgTemplate = ` ` test("read from a file", async ({expect})=>{ const sut = new ConfigReader(); const file = new File([cfgTemplate],'cfg.json.xml',{type:'application/xml'}); // define a missing jsdom text() function, // that presents in the real DOM Object.defineProperty(file, 'text', { value: () => Promise.resolve(cfgTemplate), writable: true }); const cfg = await sut.parseFromFile(file); expect(cfg).not.toBeUndefined(); }); test("load environments and params", ({expect})=>{ const sut = new ConfigReader(); const cfg = sut.parseFromString(cfgTemplate); expect(cfg?.envs).toHaveLength(3); expect(cfg?.envs.map(x=>x.name)) .toEqual(expect.arrayContaining(["DEFAULT", "env1", "env2"])); expect(cfg?.envs.flatMap(x=>x.params)) .toHaveLength(5); }); test("load template", ({expect})=>{ const sut = new ConfigReader(); const cfg = sut.parseFromString(cfgTemplate); expect(cfg?.template).toBeDefined(); expect(cfg?.template.content.length).toBeGreaterThan(20); expect(cfg?.template.Params).toHaveLength(5) expect(cfg?.getTemplateAsJson()).not.toBeUndefined(); expect(cfg?.validateParams()).does.has.length(1).and.contain("no_param"); });