Passed
Branch master (200a29)
by Sean
04:58 queued 02:16
created

src/tests/type-check.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 65
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 48
mnd 1
bc 1
fnc 1
dl 0
loc 65
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A type-check.ts ➔ testTypes 0 44 2
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