|
| 1 | +// recursive-exec |
| 2 | +// CLI Specification Suite |
| 3 | + |
| 4 | +// Imports |
| 5 | +import { assertDeepStrictEqual, fixEolGitDiff } from 'assert-deep-strict-equal'; |
| 6 | +import { cliArgvUtil } from 'cli-argv-util'; |
| 7 | +import fs from 'fs'; |
| 8 | + |
| 9 | +// Setup |
| 10 | +const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')); |
| 11 | +const run = (posix) => cliArgvUtil.run(pkg, posix); |
| 12 | + |
| 13 | +//////////////////////////////////////////////////////////////////////////////// |
| 14 | +describe('Executing the CLI', () => { |
| 15 | + |
| 16 | + it('to compile LESS files to CSS preserves the source folder structure', () => { |
| 17 | + run("recursive-exec spec/fixtures --ext=.less 'lessc {{file}} spec/target/css/{{basename}}.css'"); |
| 18 | + const actual = cliArgvUtil.readFolder('spec/target/css'); |
| 19 | + const expected = [ |
| 20 | + 'mock-file1.css', |
| 21 | + 'subfolder', |
| 22 | + 'subfolder/mock-file2.css', |
| 23 | + ]; |
| 24 | + assertDeepStrictEqual(actual, expected); |
| 25 | + fixEolGitDiff('spec/target/css/mock-file1.css'); |
| 26 | + fixEolGitDiff('spec/target/css/subfolder/mock-file2.css'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('to optimize CSS files preserves the source folder structure', () => { |
| 30 | + run("recursive-exec spec/fixtures --ext=.js 'make-dir spec/target/css-min/{{path}}' --quiet"); |
| 31 | + run("recursive-exec spec/target/css 'csso {{file}} --output spec/target/css-min/{{basename}}.min.css'"); |
| 32 | + const actual = cliArgvUtil.readFolder('spec/target/css-min'); |
| 33 | + const expected = [ |
| 34 | + 'mock-file1.min.css', |
| 35 | + 'subfolder', |
| 36 | + 'subfolder/mock-file2.min.css', |
| 37 | + ]; |
| 38 | + assertDeepStrictEqual(actual, expected); |
| 39 | + }); |
| 40 | + |
| 41 | + it('to minimize JS files preserves the source folder structure', () => { |
| 42 | + run("recursive-exec spec/fixtures --ext=.js --quiet 'make-dir spec/target/js/{{path}}'"); |
| 43 | + run("recursive-exec spec/fixtures --ext=.js 'uglifyjs {{file}} --output spec/target/js/{{basename}}.min.js'"); |
| 44 | + const actual = cliArgvUtil.readFolder('spec/target/js'); |
| 45 | + const expected = [ |
| 46 | + 'mock-file1.min.js', |
| 47 | + 'subfolder', |
| 48 | + 'subfolder/mock-file2.min.js', |
| 49 | + ]; |
| 50 | + assertDeepStrictEqual(actual, expected); |
| 51 | + }); |
| 52 | + |
| 53 | + it('with a package.json command macro for the previous specification produces the same result', () => { |
| 54 | + run("recursive-exec spec/fixtures --ext=.js --quiet {{command:make-dir}}"); |
| 55 | + run("recursive-exec spec/fixtures --ext=.js {{command:uglifyjs}}"); |
| 56 | + const actual = cliArgvUtil.readFolder('spec/target/js-macro'); |
| 57 | + const expected = [ |
| 58 | + 'mock-file1.min.js', |
| 59 | + 'subfolder', |
| 60 | + 'subfolder/mock-file2.min.js', |
| 61 | + ]; |
| 62 | + assertDeepStrictEqual(actual, expected); |
| 63 | + }); |
| 64 | + |
| 65 | + it('to rename copies of files with camel case names preserves the source folder structure', () => { |
| 66 | + const template = 'copy-file {{file}} spec/target/html/{{path}}/{{name}}.{{nameCamelCase}}.html'; |
| 67 | + run(`recursive-exec spec/fixtures --ext=.html --echo '${template}'`); |
| 68 | + run(`recursive-exec spec/fixtures --ext=.html '${template}'`); |
| 69 | + const actual = cliArgvUtil.readFolder('spec/target/html'); |
| 70 | + const expected = [ |
| 71 | + 'mock-file1.mockFile1.html', |
| 72 | + 'subfolder', |
| 73 | + 'subfolder/mock-file2.mockFile2.html', |
| 74 | + ]; |
| 75 | + assertDeepStrictEqual(actual, expected); |
| 76 | + }); |
| 77 | + |
| 78 | + it('with the --exclude flag skips over the excluded files', () => { |
| 79 | + const template = 'copy-file {{file}} spec/target/exclude/{{filename}}'; |
| 80 | + run(`recursive-exec spec/fixtures --exclude=file1,html '${template}'`); |
| 81 | + const actual = cliArgvUtil.readFolder('spec/target/exclude'); |
| 82 | + const expected = [ |
| 83 | + 'subfolder', |
| 84 | + 'subfolder/mock-file2.js', |
| 85 | + 'subfolder/mock-file2.less', |
| 86 | + ]; |
| 87 | + assertDeepStrictEqual(actual, expected); |
| 88 | + }); |
| 89 | + |
| 90 | + }); |
0 commit comments