Leyang ca644d8914
feat(core): allow custom midscene_run dir (#631)
* feat(core): support custom midscene_run dir

* feat(report): add search functionality to PlaywrightCaseSelector component

* refactor(shared): simplify base directory resolution and remove unused environment variable

* feat(shared): integrate shared environment variables across multiple packages

* refactor(shared): update base directory resolution to use dynamic midscene_run directory

* fix(puppeteer): increase screenshot timeout from 3s to 10s for improved reliability
2025-04-24 22:54:52 +08:00

46 lines
1.5 KiB
TypeScript

import { describeUserPage } from '@/ai-model/prompt/util';
import { vlLocateMode } from '@midscene/shared/env';
import { getContextFromFixture } from 'tests/evaluation';
import { describe, expect, it, vi } from 'vitest';
// Mock vlLocateMode to return false during tests
vi.mock('@midscene/shared/env', async () => {
const actual = await vi.importActual('@midscene/shared/env');
return {
...actual,
vlLocateMode: () => false,
};
});
describe.skipIf(vlLocateMode())('prompt utils', () => {
let lengthOfDescription: number;
it('describe context', async () => {
const context = await getContextFromFixture('taobao');
const { description } = await describeUserPage(context.context);
lengthOfDescription = description.length;
const stringLengthOfEachItem =
lengthOfDescription / context.context.content.length;
expect(description).toBeTruthy();
expect(stringLengthOfEachItem).toBeLessThan(250);
});
it('describe context, length = 100, filterNonTextContent = true', async () => {
const context = await getContextFromFixture('taobao');
const { description } = await describeUserPage(context.context, {
truncateTextLength: 100,
filterNonTextContent: true,
});
const stringLengthOfEachItem =
description.length / context.context.content.length;
expect(description).toBeTruthy();
expect(stringLengthOfEachItem).toBeLessThan(160);
if (!vlLocateMode()) {
expect(description.length).toBeLessThan(lengthOfDescription * 0.8);
}
});
});