Passed
Push — master ( fc1840...758c7e )
by
unknown
02:44
created

src/tests/cli.test.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 39
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 28
mnd 1
bc 1
fnc 0
dl 0
loc 39
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { execFile } from 'child_process';
2
import * as path from 'path';
3
import * as assert from 'assert';
4
import { describe, it } from 'mocha';
5
6
describe('CLI: sitemapper', function (this: Mocha.Suite) {
7
  this.timeout(10000); // Allow up to 10 seconds for network
8
9
  it('should print URLs from the sitemap', function (done: Mocha.Done) {
10
    const cliPath: string = path.resolve(__dirname, '../../bin/sitemapper.js');
11
    const sitemapUrl: string = 'https://wp.seantburke.com/sitemap.xml';
12
13
    // @ts-ignore - TypeScript has trouble with Node.js execFile overloads
14
    execFile('node', [cliPath, sitemapUrl], (error, stdout, stderr) => {
15
      assert.strictEqual(error, null, `CLI errored: ${stderr}`);
16
      // Check that output contains at least one expected URL
17
      const urls: string[] = stdout.split(/\s+/).filter((line: string) => {
18
        try {
19
          const parsedUrl = new URL(line);
20
          return parsedUrl.hostname === 'wp.seantburke.com';
21
        } catch (e) {
22
          console.error(e);
23
          return false;
24
        }
25
      });
26
      assert(
27
        urls.length > 0,
28
        'Output should contain at least one URL with the expected hostname.'
29
      );
30
      // Optionally, check for the "Found URLs:" header
31
      assert(
32
        stdout.includes('Found URLs:'),
33
        'Output should contain the "Found URLs:" header.'
34
      );
35
      done();
36
    });
37
  });
38
});
39