Skip to content

Commit 6f9796e

Browse files
committed
Refactor test cases into more granular files
1 parent 8e16a49 commit 6f9796e

4 files changed

Lines changed: 95 additions & 70 deletions

File tree

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,19 @@
11
// run-scripts-util
2-
// Mocha Specification Suite
2+
// CLI Specification Suite
33

44
// Imports
55
import { assertDeepStrictEqual } from 'assert-deep-strict-equal';
66
import { cliArgvUtil } from 'cli-argv-util';
77
import assert from 'assert';
88
import fs from 'fs';
99

10-
// Setup
10+
// Setup and Utilities
1111
import { runScripts } from '../dist/run-scripts.js';
1212
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);
7914

8015
////////////////////////////////////////////////////////////////////////////////
8116
describe('Executing the CLI', () => {
82-
const run = (posix) => cliArgvUtil.run(pkg, posix);
8317

8418
it('correctly runs parallel commands', () => {
8519
// Handy script:
@@ -123,7 +57,6 @@ describe('Executing the CLI', () => {
12357

12458
////////////////////////////////////////////////////////////////////////////////
12559
describe('A task that fails due to an invalid option', () => {
126-
const run = (posix) => cliArgvUtil.run(pkg, posix);
12760

12861
it('does not throw an exception when the CLI flag --continue-on-error is set', () => {
12962
run('run-scripts spec-e --continue-on-error');

spec/errors.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-scripts-util
2+
// Error Handling Specification Suite
3+
4+
// Imports
5+
import assert from 'assert';
6+
7+
// Setup
8+
import { runScripts } from '../dist/run-scripts.js';
9+
10+
////////////////////////////////////////////////////////////////////////////////
11+
describe('Correct error is thrown', () => {
12+
13+
it('when a nonexistent command group is supplied', () => {
14+
const makeBogusCall = () => runScripts.exec('bogus');
15+
const exception = { message: '[run-scripts-util] Cannot find commands: bogus' };
16+
assert.throws(makeBogusCall, exception);
17+
});
18+
19+
});

spec/exec.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// run-scripts-util
2+
// Function exec() Specification Suite
3+
4+
// Imports
5+
import { assertDeepStrictEqual } from 'assert-deep-strict-equal';
6+
import fs from 'fs';
7+
8+
// Setup
9+
import { runScripts } from '../dist/run-scripts.js';
10+
11+
////////////////////////////////////////////////////////////////////////////////
12+
describe('Calling runScripts.exec()', () => {
13+
14+
it('correctly executes a group of commands', () => {
15+
const options = { quiet: false, verbose: false };
16+
runScripts.exec('spec-a', options);
17+
const actual = fs.readdirSync('spec/target/a');
18+
const expected = [
19+
'cli.js',
20+
'cli2.js',
21+
'release-on-vtag.yaml',
22+
'run-spec-on-push.yaml',
23+
];
24+
assertDeepStrictEqual(actual, expected);
25+
});
26+
27+
});

spec/package.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// run-scripts-util
2+
// Package Specification Suite
3+
4+
// Imports
5+
import { assertDeepStrictEqual } from 'assert-deep-strict-equal';
6+
import fs from 'fs';
7+
8+
// Setup
9+
import { runScripts } from '../dist/run-scripts.js';
10+
11+
////////////////////////////////////////////////////////////////////////////////
12+
describe('The "dist" folder', () => {
13+
14+
it('contains the correct files', () => {
15+
const actual = fs.readdirSync('dist');
16+
const expected = [
17+
'run-scripts.d.ts',
18+
'run-scripts.js',
19+
];
20+
assertDeepStrictEqual(actual, expected);
21+
});
22+
23+
});
24+
25+
////////////////////////////////////////////////////////////////////////////////
26+
describe('Library module', () => {
27+
28+
it('is an object', () => {
29+
const actual = { constructor: runScripts.constructor.name };
30+
const expected = { constructor: 'Object' };
31+
assertDeepStrictEqual(actual, expected);
32+
});
33+
34+
it('has functions named assert(), cli(), exec(), and execParallel()', () => {
35+
const module = runScripts;
36+
const actual = Object.keys(module).sort().map(key => [key, typeof module[key]]);
37+
const expected = [
38+
['assert', 'function'],
39+
['cli', 'function'],
40+
['exec', 'function'],
41+
['execParallel', 'function'],
42+
];
43+
assertDeepStrictEqual(actual, expected);
44+
});
45+
46+
});

0 commit comments

Comments
 (0)