|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const { test } = require('tap') |
| 4 | +const { spawn } = require('child_process') |
| 5 | +const subsystems = require('../lib/rules/subsystem') |
| 6 | + |
| 7 | +test('Test cli flags', (t) => { |
| 8 | + t.test('test list-subsystems', (tt) => { |
| 9 | + const ls = spawn('./bin/cmd.js', ['--list-subsystems']) |
| 10 | + let compiledData = '' |
| 11 | + ls.stdout.on('data', (data) => { |
| 12 | + compiledData += data |
| 13 | + }) |
| 14 | + |
| 15 | + ls.stderr.on('data', (data) => { |
| 16 | + tt.fail('This should not happen') |
| 17 | + }) |
| 18 | + |
| 19 | + ls.on('close', (code) => { |
| 20 | + // Get the list of subsytems as an Array. |
| 21 | + // Need to match words that also have the "-" in them |
| 22 | + const subsystemsFromOutput = compiledData.match(/[\w'-]+/g) |
| 23 | + const defaultSubsystems = subsystems.defaults.subsystems |
| 24 | + |
| 25 | + tt.equal(subsystemsFromOutput.length, |
| 26 | + defaultSubsystems.length, |
| 27 | + 'Should have the same length') |
| 28 | + |
| 29 | + // Loop through the output list and compare with the real list |
| 30 | + // to make sure they are all there |
| 31 | + const missing = [] |
| 32 | + subsystemsFromOutput.forEach((sub) => { |
| 33 | + if (!defaultSubsystems.find((x) => {return x === sub})) { |
| 34 | + missing.push(sub) |
| 35 | + } |
| 36 | + }) |
| 37 | + |
| 38 | + tt.equal(missing.length, 0, 'Should have no missing subsystems') |
| 39 | + tt.end() |
| 40 | + }) |
| 41 | + }) |
| 42 | + |
| 43 | + t.end() |
| 44 | +}) |
0 commit comments