| Total Complexity | 5 |
| Complexity/F | 1.25 |
| Lines of Code | 35 |
| Function Count | 4 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 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); |
||
|
|
|||
| 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 |
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.