Skip to content

Commit

Permalink
chore: update cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Sep 4, 2024
1 parent 0165108 commit 726802a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/web-integration/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dotenv.config({
*/
export default defineConfig({
// testDir: './tests/ai/e2e',
// testIgnore: 'generate-test-data.spec.ts',
testIgnore: 'generate-test-data.spec.ts',
timeout: 900 * 1000,
/* Run tests in files in parallel */
fullyParallel: true,
Expand Down
6 changes: 4 additions & 2 deletions packages/web-integration/src/common/task-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type AiTaskCache = {
};

export class TaskCache {
cache: AiTaskCache | undefined;
cache: AiTaskCache;

cacheId: string;

Expand All @@ -56,7 +56,9 @@ export class TaskCache {
constructor(opts?: { fileName?: string }) {
this.midscenePkgInfo = getMidscenePkgInfo(__dirname);
this.cacheId = generateCacheId(opts?.fileName);
this.cache = this.readCacheFromFile();
this.cache = this.readCacheFromFile() || {
aiTasks: [],
};
this.newCache = {
aiTasks: [],
};
Expand Down
4 changes: 2 additions & 2 deletions packages/web-integration/tests/ai/e2e/ai-online-order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ test('ai online order', async ({ ai, page, aiQuery }) => {
// productPrice: "商品价格",
// productDescription: "商品描述(饮品的各种参数,吸管、冰沙等),在价格下面",
// }));
expect(cardDetail.productName).toContain('多肉葡萄');
expect(cardDetail.productDescription).toContain('绿妍');

console.log('商品订单详情:', {
productName: cardDetail.productName,
productPrice: cardDetail.productPrice,
productDescription: cardDetail.productDescription,
});
expect(cardDetail.productName).toContain('多肉葡萄');
expect(cardDetail.productDescription).toContain('绿妍');
});
28 changes: 13 additions & 15 deletions packages/web-integration/tests/unit-test/task-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@ describe('TaskCache', () => {
});

it('should return false if the prompt does not match', async () => {
if (taskCache.cache) {
taskCache.cache.aiTasks = [
{
prompt: 'different prompt',
tasks: [
{
type: 'plan',
prompt: 'different prompt',
pageContext,
response: { plans: [] },
},
],
},
];
}
taskCache.cache.aiTasks = [
{
prompt: 'different prompt',
tasks: [
{
type: 'plan',
prompt: 'different prompt',
pageContext,
response: { plans: [] },
},
],
},
];
const cacheGroup = taskCache.getCacheGroupByPrompt('test prompt');
const result = cacheGroup.readCache(
formalPageContext,
Expand Down

0 comments on commit 726802a

Please sign in to comment.