2024-08-21 17:24:32 +08:00
|
|
|
import path, { join } from 'node:path';
|
2024-08-20 07:41:08 +08:00
|
|
|
import { parseContextFromWebPage } from '@/common/utils';
|
2024-08-21 17:24:32 +08:00
|
|
|
import { generateTestData } from 'tests/ai/e2e/tool';
|
2024-08-20 07:41:08 +08:00
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import { launchPage } from '../ai/puppeteer/utils';
|
|
|
|
|
2024-08-21 17:24:32 +08:00
|
|
|
const pagePath = join(__dirname, './fixtures/extractor/index.html');
|
2024-08-21 16:28:58 +08:00
|
|
|
describe(
|
2024-08-20 07:41:08 +08:00
|
|
|
'extractor',
|
|
|
|
() => {
|
|
|
|
it('basic', async () => {
|
2024-08-21 17:24:32 +08:00
|
|
|
const { page, reset } = await launchPage(`file://${pagePath}`);
|
|
|
|
|
|
|
|
const { content, screenshotBase64 } = await parseContextFromWebPage(page);
|
|
|
|
await generateTestData(
|
|
|
|
page,
|
|
|
|
path.join(__dirname, 'fixtures/extractor'),
|
|
|
|
screenshotBase64,
|
|
|
|
{
|
|
|
|
disableInputImage: false,
|
|
|
|
disableOutputImage: false,
|
|
|
|
disableOutputWithoutTextImg: true,
|
|
|
|
disableResizeOutputImg: true,
|
|
|
|
disableSnapshot: true,
|
|
|
|
},
|
|
|
|
);
|
2024-08-20 07:41:08 +08:00
|
|
|
|
|
|
|
const list = content.map((item) => {
|
|
|
|
return {
|
|
|
|
content: item.content,
|
|
|
|
attributes: item.attributes,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
expect(list).toMatchSnapshot();
|
2024-08-21 17:24:32 +08:00
|
|
|
await reset();
|
2024-08-20 07:41:08 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timeout: 90 * 1000,
|
|
|
|
},
|
|
|
|
);
|