mirror of
https://github.com/web-infra-dev/midscene.git
synced 2025-11-22 21:16:52 +00:00
* feat: add environment variable interpolation to YAML script parser * Update environment variable interpolation syntax in YAML utils --------- Co-authored-by: George Lei <george.lei@lesmills.com>
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { buildYaml, flowItemBrief, parseYamlScript } from '@/yaml';
|
|
import { describe, expect, test } from 'vitest';
|
|
|
|
describe('utils', () => {
|
|
test('build yaml', () => {
|
|
const yaml = buildYaml({ url: 'https://www.baidu.com' }, []);
|
|
expect(yaml).toMatchSnapshot();
|
|
});
|
|
|
|
test('action brief text', () => {
|
|
expect(flowItemBrief({ ai: 'search for weather' })).toMatchSnapshot();
|
|
expect(flowItemBrief({ sleep: 1000 })).toMatchSnapshot();
|
|
expect(
|
|
flowItemBrief({ aiWaitFor: 'wait for something' }),
|
|
).toMatchSnapshot();
|
|
});
|
|
|
|
describe('parseYamlScript', () => {
|
|
test('interpolates environment variables', () => {
|
|
process.env.TEST_URL = 'https://example.com';
|
|
process.env.TEST_PATH = '/test/path';
|
|
|
|
const yamlContent = `
|
|
target:
|
|
url: "\${TEST_URL}\${TEST_PATH}"
|
|
tasks:
|
|
- sleep: 1000
|
|
`;
|
|
|
|
const result = parseYamlScript(yamlContent);
|
|
expect(result.target.url).toBe('https://example.com/test/path');
|
|
});
|
|
|
|
test('throws error for undefined environment variables', () => {
|
|
const yamlContent = `
|
|
target:
|
|
url: "\${UNDEFINED_ENV_VAR}"
|
|
tasks:
|
|
- sleep: 1000
|
|
`;
|
|
|
|
expect(() => parseYamlScript(yamlContent)).toThrow(
|
|
'Environment variable "UNDEFINED_ENV_VAR" is not defined',
|
|
);
|
|
});
|
|
});
|
|
});
|