Skip to content

Commit

Permalink
workflow(ci): optimize ai e2e test (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw authored Aug 22, 2024
1 parent eb82d28 commit 65367fa
Show file tree
Hide file tree
Showing 16 changed files with 1,103 additions and 84 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ jobs:
- name: Build project
run: pnpm run build:pkg

- name: Run e2e tests cache
run: pnpm run e2e:cache

- name: Run e2e tests report
run: pnpm run e2e:report

- name: Run e2e tests
run: pnpm run e2e

Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ playwright/.cache/

# Midscene.js dump files
__ai_responses__/
midscene_run/

.nx/cache
.nx/workspace-data
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"test": "nx run-many --target=test --projects=@midscene/core,@midscene/visualizer,@midscene/web --verbose",
"test:ai": "nx run-many --target=test:ai --projects=@midscene/core,@midscene/visualizer,@midscene/web --verbose",
"e2e": "nx run-many --target=e2e --projects=@midscene/core,@midscene/visualizer,@midscene/web --verbose",
"e2e:cache": "nx run-many --target=e2e:cache --projects=@midscene/web --verbose",
"e2e:report": "nx run-many --target=e2e:report --projects=@midscene/web --verbose",
"prepare": "pnpm run build:pkg && simple-git-hooks",
"check-dependency-version": "check-dependency-version-consistency .",
"lint": "npx biome check . --diagnostic-level=warn --no-errors-on-unmatched --fix",
Expand Down
8 changes: 7 additions & 1 deletion packages/midscene/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
import path, { basename, join } from 'node:path';
import path, { basename, dirname, join } from 'node:path';
import type { Rect, ReportDumpWithAttributes } from './types';

interface PkgInfo {
Expand Down Expand Up @@ -123,6 +123,12 @@ export function writeLogFile(opts: {
}

const filePath = join(targetDir, `${fileName}.${fileExt}`);

const outputResourceDir = dirname(filePath);
if (!existsSync(outputResourceDir)) {
mkdirSync(outputResourceDir, { recursive: true });
}

writeFileSync(filePath, fileContent);

if (opts?.generateReport) {
Expand Down
24 changes: 12 additions & 12 deletions packages/midscene/tests/ai/automation/planning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ modelList.forEach((model) => {
expect(plans[3].param).toMatchSnapshot();
});

it('should raise an error when prompt is irrelevant with page', async () => {
const { context } = await getPageDataOfTestName('todo');
// it('should raise an error when prompt is irrelevant with page', async () => {
// const { context } = await getPageDataOfTestName('todo');

expect(async () => {
await plan(
'Tap the blue T-shirt in left top corner, and click the "add to cart" button',
{
context,
},
model,
);
}).rejects.toThrowError();
});
// expect(async () => {
// await plan(
// 'Tap the blue T-shirt in left top corner, and click the "add to cart" button',
// {
// context,
// },
// model,
// );
// }).rejects.toThrowError();
// });

it('Error message in Chinese', async () => {
const { context } = await getPageDataOfTestName('todo');
Expand Down
Loading

0 comments on commit 65367fa

Please sign in to comment.