1
|
|
|
import Sitemapper, { |
2
|
|
|
SitemapperOptions, |
3
|
|
|
SitemapperResponse, |
4
|
|
|
SitemapperErrorData, |
5
|
|
|
} from '../../sitemapper'; |
6
|
|
|
|
7
|
|
|
const sitemapper = new Sitemapper({ |
8
|
|
|
url: 'https://example.com/sitemap.xml', |
9
|
|
|
timeout: 30000, |
10
|
|
|
debug: false, |
11
|
|
|
concurrency: 5, |
12
|
|
|
retries: 1, |
13
|
|
|
rejectUnauthorized: true, |
14
|
|
|
lastmod: Date.now() - 24 * 60 * 60 * 1000, // 1 day ago |
15
|
|
|
exclusions: [/exclude-this/], |
16
|
|
|
}); |
17
|
|
|
|
18
|
|
|
async function testTypes() { |
19
|
|
|
try { |
20
|
|
|
// Check constructor options type |
21
|
|
|
const options = { |
22
|
|
|
url: 'https://test.com/sitemap.xml', |
23
|
|
|
timeout: 1000, |
24
|
|
|
lastmod: 0, |
25
|
|
|
concurrency: 1, |
26
|
|
|
retries: 0, |
27
|
|
|
debug: true, |
28
|
|
|
rejectUnauthorized: false, |
29
|
|
|
proxyAgent: { host: 'localhost' }, // Basic check, actual agent type is complex |
30
|
|
|
exclusions: [/test/], |
31
|
|
|
}; |
32
|
|
|
const sitemapperWithOptions = new Sitemapper(options); |
33
|
|
|
console.log( |
34
|
|
|
`Created sitemapper with options for ${sitemapperWithOptions.url}` |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
// Check fetch method and return type |
38
|
|
|
console.log(`Fetching sitemap from: ${sitemapper.url}`); |
39
|
|
|
const data = await sitemapper.fetch(); |
40
|
|
|
console.log(`Fetched ${data.sites.length} sites from ${data.url}`); |
41
|
|
|
|
42
|
|
|
// Check sites array type |
43
|
|
|
const sites = data.sites; |
44
|
|
|
sites.forEach((site) => { |
45
|
|
|
console.log(`- ${site}`); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
// Check errors array type |
49
|
|
|
const errors = data.errors; |
50
|
|
|
errors.forEach((error) => { |
51
|
|
|
console.error( |
52
|
|
|
`Error: ${error.type} for ${error.url}, retries: ${error.retries}` |
53
|
|
|
); |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
// Test setting properties (assuming they exist and are settable in .d.ts) |
57
|
|
|
// sitemapper.timeout = 10000; |
58
|
|
|
// console.log(`New timeout: ${sitemapper.timeout}`); |
59
|
|
|
} catch (error) { |
60
|
|
|
console.error('An error occurred:', error); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
testTypes(); |
65
|
|
|
|