Skip to content

Commit

Permalink
Switch to new cliArgvUtil.readFolder() for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Aug 18, 2023
1 parent 9fd6b5a commit 2a0801d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -132,6 +132,7 @@ See the **TypeScript Declarations** at the top of [run-scripts.ts](run-scripts.t
- 馃帇 [add-dist-header](https://github.com/center-key/add-dist-header):  _Prepend a one-line banner comment (with license notice) to distribution files_
- 馃搫 [copy-file-util](https://github.com/center-key/copy-file-util):  _Copy or rename a file with optional package version number_
- 馃搨 [copy-folder-util](https://github.com/center-key/copy-folder-util):  _Recursively copy files from one folder to another folder_
- 馃 [recursive-exec](https://github.com/center-key/recursive-exec):  _Run a command on each file in a folder and its subfolders_
- 馃攳 [replacer-util](https://github.com/center-key/replacer-util):  _Find and replace strings or template outputs in text files_
- 馃敘 [rev-web-assets](https://github.com/center-key/rev-web-assets):  _Revision web asset filenames with cache busting content hash fingerprints_
- 馃殕 [run-scripts-util](https://github.com/center-key/run-scripts-util):  _Organize npm scripts into named groups of easy to manage commands_
Expand Down
4 changes: 2 additions & 2 deletions bin/cli.js
Expand Up @@ -22,8 +22,8 @@
// },
//
// Usage from command line:
// $ npm install --global run-scripts-util
// $ run-scripts compile --quiet
// $ npm install --save-dev run-scripts-util
// $ npx run-scripts compile --quiet
//
// For contributors working on this project:
// $ npm run dev
Expand Down
11 changes: 5 additions & 6 deletions package.json
Expand Up @@ -111,18 +111,17 @@
},
"devDependencies": {
"@types/fancy-log": "~2.0",
"@types/node": "~20.4",
"@typescript-eslint/eslint-plugin": "~6.1",
"@typescript-eslint/parser": "~6.1",
"add-dist-header": "~1.1",
"@types/node": "~20.5",
"@typescript-eslint/eslint-plugin": "~6.4",
"@typescript-eslint/parser": "~6.4",
"add-dist-header": "~1.2",
"assert-deep-strict-equal": "~1.1",
"copy-file-util": "~1.1",
"copy-folder-util": "~1.1",
"eslint": "~8.45",
"eslint": "~8.47",
"jshint": "~2.13",
"mocha": "~10.2",
"npm-run-all2": "~6.0",
"rev-web-assets": "~1.2",
"rimraf": "~5.0",
"typescript": "~5.1"
}
Expand Down
2 changes: 2 additions & 0 deletions run-scripts.ts
@@ -1,10 +1,12 @@
// run-scripts-util ~~ MIT License

// Imports
import { spawn, spawnSync } from 'node:child_process';
import chalk from 'chalk';
import fs from 'fs';
import log from 'fancy-log';

// Types
export type Settings = {
only: number | null, //execute just one command in the group (starts with 1)
quiet: boolean, //suppress informational messages
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/target/a/cli.js
Expand Up @@ -22,8 +22,8 @@
// },
//
// Usage from command line:
// $ npm install --global run-scripts-util
// $ run-scripts compile --quiet
// $ npm install --save-dev run-scripts-util
// $ npx run-scripts compile --quiet
//
// For contributors working on this project:
// $ npm run dev
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/target/a/cli2.js
Expand Up @@ -22,8 +22,8 @@
// },
//
// Usage from command line:
// $ npm install --global run-scripts-util
// $ run-scripts compile --quiet
// $ npm install --save-dev run-scripts-util
// $ npx run-scripts compile --quiet
//
// For contributors working on this project:
// $ npm run dev
Expand Down
38 changes: 20 additions & 18 deletions spec/mocha.spec.js
Expand Up @@ -4,7 +4,6 @@
// Imports
import { assertDeepStrictEqual } from 'assert-deep-strict-equal';
import { cliArgvUtil } from 'cli-argv-util';
import { revWebAssets } from 'rev-web-assets';
import assert from 'assert';
import fs from 'fs';

Expand All @@ -16,10 +15,10 @@ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
describe('The "dist" folder', () => {

it('contains the correct files', () => {
const actual = revWebAssets.readFolderRecursive('dist');
const actual = fs.readdirSync('dist');
const expected = [
'dist/run-scripts.d.ts',
'dist/run-scripts.js',
'run-scripts.d.ts',
'run-scripts.js',
];
assertDeepStrictEqual(actual, expected);
});
Expand Down Expand Up @@ -49,12 +48,12 @@ describe('Calling runScripts.exec()', () => {
it('correctly executes a group of commands', () => {
const options = { quiet: false, verbose: false };
runScripts.exec('spec-a', options);
const actual = revWebAssets.readFolderRecursive('spec/fixtures/target/a');
const actual = fs.readdirSync('spec/fixtures/target/a');
const expected = [
'spec/fixtures/target/a/cli.js',
'spec/fixtures/target/a/cli2.js',
'spec/fixtures/target/a/release-on-vtag.yaml',
'spec/fixtures/target/a/run-spec-on-push.yaml',
'cli.js',
'cli2.js',
'release-on-vtag.yaml',
'run-spec-on-push.yaml',
];
assertDeepStrictEqual(actual, expected);
});
Expand All @@ -80,23 +79,26 @@ describe('Executing the CLI', () => {
// Handy script:
// "devp": "tsc && add-dist-header build dist && rimraf spec/fixtures/target/b && mocha spec/*.spec.js --grep parallel --timeout 7000",
run('run-scripts spec-b1 spec-b2 --parallel --verbose');
const actual = revWebAssets.readFolderRecursive('spec/fixtures/target/b');
const actual = cliArgvUtil.readFolder('spec/fixtures/target/b');
const expected = [
'spec/fixtures/target/b/1/w.json',
'spec/fixtures/target/b/1/x.json',
'spec/fixtures/target/b/1/y.json',
'spec/fixtures/target/b/1/z.json',
'spec/fixtures/target/b/2/w.json',
'spec/fixtures/target/b/2/x.json',
'1',
'1/w.json',
'1/x.json',
'1/y.json',
'1/z.json',
'2',
'2/w.json',
'2/x.json',
];
assertDeepStrictEqual(actual, expected);
});

it('with two command groups correctly runs them in serial', () => {
run('run-scripts spec-c1 spec-c2 --note=hello --quiet');
const actual = revWebAssets.readFolderRecursive('spec/fixtures/target/c');
const actual = cliArgvUtil.readFolder('spec/fixtures/target/c');
const expected = [
'spec/fixtures/target/c/2/last.txt',
'2',
'2/last.txt',
];
assertDeepStrictEqual(actual, expected);
});
Expand Down

0 comments on commit 2a0801d

Please sign in to comment.