|
1 | 1 | // run-scripts-util |
2 | | -// Mocha Specification Suite |
| 2 | +// CLI Specification Suite |
3 | 3 |
|
4 | 4 | // Imports |
5 | 5 | import { assertDeepStrictEqual } from 'assert-deep-strict-equal'; |
6 | 6 | import { cliArgvUtil } from 'cli-argv-util'; |
7 | 7 | import assert from 'assert'; |
8 | 8 | import fs from 'fs'; |
9 | 9 |
|
10 | | -// Setup |
| 10 | +// Setup and Utilities |
11 | 11 | import { runScripts } from '../dist/run-scripts.js'; |
12 | 12 | const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')); |
13 | | - |
14 | | -//////////////////////////////////////////////////////////////////////////////// |
15 | | -describe('The "dist" folder', () => { |
16 | | - |
17 | | - it('contains the correct files', () => { |
18 | | - const actual = fs.readdirSync('dist'); |
19 | | - const expected = [ |
20 | | - 'run-scripts.d.ts', |
21 | | - 'run-scripts.js', |
22 | | - ]; |
23 | | - assertDeepStrictEqual(actual, expected); |
24 | | - }); |
25 | | - |
26 | | - }); |
27 | | - |
28 | | -//////////////////////////////////////////////////////////////////////////////// |
29 | | -describe('Library module', () => { |
30 | | - |
31 | | - it('is an object', () => { |
32 | | - const actual = { constructor: runScripts.constructor.name }; |
33 | | - const expected = { constructor: 'Object' }; |
34 | | - assertDeepStrictEqual(actual, expected); |
35 | | - }); |
36 | | - |
37 | | - it('has functions named assert(), cli(), exec(), and execParallel()', () => { |
38 | | - const module = runScripts; |
39 | | - const actual = Object.keys(module).sort().map(key => [key, typeof module[key]]); |
40 | | - const expected = [ |
41 | | - ['assert', 'function'], |
42 | | - ['cli', 'function'], |
43 | | - ['exec', 'function'], |
44 | | - ['execParallel', 'function'], |
45 | | - ]; |
46 | | - assertDeepStrictEqual(actual, expected); |
47 | | - }); |
48 | | - |
49 | | - }); |
50 | | - |
51 | | -//////////////////////////////////////////////////////////////////////////////// |
52 | | -describe('Calling runScripts.exec()', () => { |
53 | | - |
54 | | - it('correctly executes a group of commands', () => { |
55 | | - const options = { quiet: false, verbose: false }; |
56 | | - runScripts.exec('spec-a', options); |
57 | | - const actual = fs.readdirSync('spec/target/a'); |
58 | | - const expected = [ |
59 | | - 'cli.js', |
60 | | - 'cli2.js', |
61 | | - 'release-on-vtag.yaml', |
62 | | - 'run-spec-on-push.yaml', |
63 | | - ]; |
64 | | - assertDeepStrictEqual(actual, expected); |
65 | | - }); |
66 | | - |
67 | | - }); |
68 | | - |
69 | | -//////////////////////////////////////////////////////////////////////////////// |
70 | | -describe('Correct error is thrown', () => { |
71 | | - |
72 | | - it('when a nonexistent command group is supplied', () => { |
73 | | - const makeBogusCall = () => runScripts.exec('bogus'); |
74 | | - const exception = { message: '[run-scripts-util] Cannot find commands: bogus' }; |
75 | | - assert.throws(makeBogusCall, exception); |
76 | | - }); |
77 | | - |
78 | | - }); |
| 13 | +const run = (posix) => cliArgvUtil.run(pkg, posix); |
79 | 14 |
|
80 | 15 | //////////////////////////////////////////////////////////////////////////////// |
81 | 16 | describe('Executing the CLI', () => { |
82 | | - const run = (posix) => cliArgvUtil.run(pkg, posix); |
83 | 17 |
|
84 | 18 | it('correctly runs parallel commands', () => { |
85 | 19 | // Handy script: |
@@ -123,7 +57,6 @@ describe('Executing the CLI', () => { |
123 | 57 |
|
124 | 58 | //////////////////////////////////////////////////////////////////////////////// |
125 | 59 | describe('A task that fails due to an invalid option', () => { |
126 | | - const run = (posix) => cliArgvUtil.run(pkg, posix); |
127 | 60 |
|
128 | 61 | it('does not throw an exception when the CLI flag --continue-on-error is set', () => { |
129 | 62 | run('run-scripts spec-e --continue-on-error'); |
|
0 commit comments