2025-03-24 09:50:27 +08:00
|
|
|
import { buildYaml, parseYamlScript } from '@/yaml';
|
2024-11-25 16:05:01 +08:00
|
|
|
import { describe, expect, test } from 'vitest';
|
|
|
|
|
|
2024-12-25 20:23:12 +08:00
|
|
|
describe('utils', () => {
|
|
|
|
|
test('build yaml', () => {
|
2025-05-16 17:16:56 +08:00
|
|
|
const yaml = buildYaml({ url: 'https://www.example.com' }, []);
|
2024-12-25 20:23:12 +08:00
|
|
|
expect(yaml).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-10 17:03:56 +13:00
|
|
|
describe('parseYamlScript', () => {
|
2025-05-21 19:18:29 +08:00
|
|
|
test('interpolates environment variables', () => {
|
|
|
|
|
const yamlContent = `
|
|
|
|
|
target:
|
|
|
|
|
url: "sample_url"
|
|
|
|
|
tasks:
|
|
|
|
|
- sleep: 1000
|
|
|
|
|
- aiTap: "sample_button"
|
|
|
|
|
- aiInput: "sample_input"
|
|
|
|
|
locate: input description
|
|
|
|
|
- aiInput:
|
|
|
|
|
locate: input description
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const result = parseYamlScript(yamlContent);
|
|
|
|
|
expect(result).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-10 17:03:56 +13:00
|
|
|
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);
|
2025-05-16 17:16:56 +08:00
|
|
|
expect(result.target?.url).toBe('https://example.com/test/path');
|
2025-01-10 17:03:56 +13:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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',
|
|
|
|
|
);
|
|
|
|
|
});
|
2025-05-22 07:31:55 +08:00
|
|
|
|
|
|
|
|
test('android number-style deviceId', () => {
|
|
|
|
|
const yamlContent = `
|
|
|
|
|
android:
|
|
|
|
|
deviceId: 001234567890
|
|
|
|
|
tasks:
|
|
|
|
|
- sleep: 1000
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const result = parseYamlScript(yamlContent);
|
|
|
|
|
expect(result.android?.deviceId).toBe('001234567890');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('illegal android deviceId', () => {
|
|
|
|
|
const yamlContent = `
|
|
|
|
|
android:
|
|
|
|
|
deviceId: 0x222
|
|
|
|
|
tasks:
|
|
|
|
|
- sleep: 1000
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
expect(() => parseYamlScript(yamlContent)).toThrow();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('legal android deviceId', () => {
|
|
|
|
|
const yamlContent = `
|
|
|
|
|
android:
|
|
|
|
|
deviceId: '0aacde222'
|
|
|
|
|
tasks:
|
|
|
|
|
- sleep: 1000
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const result = parseYamlScript(yamlContent);
|
|
|
|
|
expect(result.android?.deviceId).toBe('0aacde222');
|
|
|
|
|
});
|
2025-01-10 17:03:56 +13:00
|
|
|
});
|
2024-11-25 16:05:01 +08:00
|
|
|
});
|