fetchfox-sdk 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/detach.js +1 -1
- package/src/fetchfox.js +3 -2
- package/tests/fetchfox.test.js +19 -0
package/package.json
CHANGED
package/src/detach.js
CHANGED
|
@@ -86,7 +86,7 @@ export const Job = class {
|
|
|
86
86
|
if (['completed', 'error'].includes(this.state)) {
|
|
87
87
|
this.trigger('finished');
|
|
88
88
|
// Just in case there are some straggler events, wait a few seconds
|
|
89
|
-
setTimeout(() => socket.disconnect(), 5000);
|
|
89
|
+
setTimeout(() => this.#socket.disconnect(), 5000);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
package/src/fetchfox.js
CHANGED
|
@@ -10,12 +10,13 @@ export const FetchFox = class {
|
|
|
10
10
|
const fns = [crawl, extract, scrape];
|
|
11
11
|
|
|
12
12
|
for (const fn of fns) {
|
|
13
|
-
this[fn.name] = (args)
|
|
14
|
-
fn({
|
|
13
|
+
this[fn.name] = function (args) {
|
|
14
|
+
return fn({
|
|
15
15
|
apiKey: this.apiKey,
|
|
16
16
|
host: this.host,
|
|
17
17
|
...args,
|
|
18
18
|
});
|
|
19
|
+
};
|
|
19
20
|
this[fn.name].detach = (args) =>
|
|
20
21
|
fn.detach({
|
|
21
22
|
apiKey: this.apiKey,
|
package/tests/fetchfox.test.js
CHANGED
|
@@ -13,6 +13,25 @@ test('use fetchfox object @fetchfox @sanity', async () => {
|
|
|
13
13
|
expect(out.results.hits.length).toBeGreaterThan(10);
|
|
14
14
|
}, 30_000);
|
|
15
15
|
|
|
16
|
+
test('use fetchfox object for detach @fetchfox @sanity', async () => {
|
|
17
|
+
const fox = new FetchFox({
|
|
18
|
+
apiKey: process.env.FETCHFOX_API_KEY,
|
|
19
|
+
});
|
|
20
|
+
const job = await fox.crawl.detach({
|
|
21
|
+
pattern: 'https://pokemondb.net/pokedex/*',
|
|
22
|
+
maxVisits: 5,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
let count = 0;
|
|
26
|
+
job.on('progress', (data) => {
|
|
27
|
+
count++;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
await job.finished();
|
|
31
|
+
|
|
32
|
+
expect(count).toBeGreaterThan(0);
|
|
33
|
+
}, 30_000);
|
|
34
|
+
|
|
16
35
|
test('invalid key fails @fetchfox @sanity', async () => {
|
|
17
36
|
const fox = new FetchFox({
|
|
18
37
|
apiKey: 'invalid',
|