Passed
Pull Request — master (#166)
by Sean
02:31
created

src/tests/cli.test.js   A

Complexity

Total Complexity 5
Complexity/F 1.25

Size

Lines of Code 35
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 23
mnd 1
bc 1
fnc 4
dl 0
loc 35
rs 10
bpm 0.25
cpm 1.25
noi 1
c 0
b 0
f 0
1
const { execFile } = require('child_process');
2
const path = require('path');
3
const assert = require('assert');
4
5
describe('CLI: sitemapper', function () {
6
  this.timeout(10000); // Allow up to 10 seconds for network
7
8
  it('should print URLs from the sitemap', function (done) {
9
    const cliPath = path.resolve(__dirname, '../../bin/sitemapper.js');
10
    const sitemapUrl = 'https://wp.seantburke.com/sitemap.xml';
11
12
    execFile('node', [cliPath, sitemapUrl], (error, stdout, stderr) => {
13
      assert.strictEqual(error, null, `CLI errored: ${stderr}`);
14
      // Check that output contains at least one expected URL
15
      const urls = stdout.split(/\s+/).filter(line => {
16
        try {
17
          const parsedUrl = new URL(line);
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
18
          return parsedUrl.hostname === 'wp.seantburke.com';
19
        } catch (e) {
20
          return false;
21
        }
22
      });
23
      assert(
24
        urls.length > 0,
25
        'Output should contain at least one URL with the expected hostname.'
26
      );
27
      // Optionally, check for the "Found URLs:" header
28
      assert(
29
        stdout.includes('Found URLs:'),
30
        'Output should contain the "Found URLs:" header.'
31
      );
32
      done();
33
    });
34
  });
35
});
36