mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-13 00:58:59 +08:00
Nick:
This commit is contained in:
parent
c5079074bc
commit
950a9512bd
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mendable/firecrawl-js",
|
"name": "@mendable/firecrawl-js",
|
||||||
"version": "1.23.2",
|
"version": "1.23.3",
|
||||||
"description": "JavaScript SDK for Firecrawl API",
|
"description": "JavaScript SDK for Firecrawl API",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -1,105 +0,0 @@
|
|||||||
import axios from 'axios';
|
|
||||||
import FirecrawlApp from '../../../../src/index';
|
|
||||||
|
|
||||||
jest.mock('axios');
|
|
||||||
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
|
||||||
|
|
||||||
describe('Change Tracking Tests', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.resetAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should support basic change tracking format', async () => {
|
|
||||||
mockedAxios.post.mockResolvedValueOnce({
|
|
||||||
status: 200,
|
|
||||||
data: {
|
|
||||||
success: true,
|
|
||||||
data: {
|
|
||||||
markdown: 'Test markdown content',
|
|
||||||
changeTracking: {
|
|
||||||
previousScrapeAt: '2023-01-01T00:00:00Z',
|
|
||||||
changeStatus: 'changed',
|
|
||||||
visibility: 'visible'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const app = new FirecrawlApp({ apiKey: process.env.TEST_API_KEY || 'dummy-api-key-for-testing' });
|
|
||||||
const result = await app.scrapeUrl('https://example.com', {
|
|
||||||
formats: ['markdown', 'changeTracking']
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockedAxios.post).toHaveBeenCalledTimes(1);
|
|
||||||
expect(mockedAxios.post.mock.calls[0][1].formats).toContain('changeTracking');
|
|
||||||
|
|
||||||
expect(result).toHaveProperty('changeTracking');
|
|
||||||
expect(result.changeTracking?.previousScrapeAt).toBe('2023-01-01T00:00:00Z');
|
|
||||||
expect(result.changeTracking?.changeStatus).toBe('changed');
|
|
||||||
expect(result.changeTracking?.visibility).toBe('visible');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should support change tracking options with git-diff and json modes', async () => {
|
|
||||||
mockedAxios.post.mockResolvedValueOnce({
|
|
||||||
status: 200,
|
|
||||||
data: {
|
|
||||||
success: true,
|
|
||||||
data: {
|
|
||||||
markdown: 'Test markdown content',
|
|
||||||
changeTracking: {
|
|
||||||
previousScrapeAt: '2023-01-01T00:00:00Z',
|
|
||||||
changeStatus: 'changed',
|
|
||||||
visibility: 'visible',
|
|
||||||
diff: {
|
|
||||||
text: '@@ -1,1 +1,1 @@\n-old content\n+new content',
|
|
||||||
json: {
|
|
||||||
files: [{
|
|
||||||
from: null,
|
|
||||||
to: null,
|
|
||||||
chunks: [{
|
|
||||||
content: '@@ -1,1 +1,1 @@',
|
|
||||||
changes: [{
|
|
||||||
type: 'del',
|
|
||||||
content: '-old content',
|
|
||||||
del: true,
|
|
||||||
ln: 1
|
|
||||||
}, {
|
|
||||||
type: 'add',
|
|
||||||
content: '+new content',
|
|
||||||
add: true,
|
|
||||||
ln: 1
|
|
||||||
}]
|
|
||||||
}]
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
json: {
|
|
||||||
title: {
|
|
||||||
previous: 'Old Title',
|
|
||||||
current: 'New Title'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const app = new FirecrawlApp({ apiKey: process.env.TEST_API_KEY || 'dummy-api-key-for-testing' });
|
|
||||||
const result = await app.scrapeUrl('https://example.com', {
|
|
||||||
formats: ['markdown', 'changeTracking'],
|
|
||||||
changeTrackingOptions: {
|
|
||||||
modes: ['git-diff', 'json'],
|
|
||||||
schema: { type: 'object', properties: { title: { type: 'string' } } }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockedAxios.post).toHaveBeenCalledTimes(1);
|
|
||||||
expect(mockedAxios.post.mock.calls[0][1].formats).toContain('changeTracking');
|
|
||||||
expect(mockedAxios.post.mock.calls[0][1].changeTrackingOptions.modes).toEqual(['git-diff', 'json']);
|
|
||||||
|
|
||||||
expect(result).toHaveProperty('changeTracking');
|
|
||||||
expect(result.changeTracking?.diff?.text).toBe('@@ -1,1 +1,1 @@\n-old content\n+new content');
|
|
||||||
expect(result.changeTracking?.json?.title.previous).toBe('Old Title');
|
|
||||||
expect(result.changeTracking?.json?.title.current).toBe('New Title');
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
x
Reference in New Issue
Block a user