diff --git a/test/index.js b/test/index.js index a873549..73a0f35 100644 --- a/test/index.js +++ b/test/index.js @@ -17,7 +17,7 @@ import assert from 'node:assert/strict' import {exec as execCb, spawn} from 'node:child_process' import fs from 'node:fs/promises' -import {sep} from 'node:path' +// . import {sep} from 'node:path' import {platform} from 'node:process' import test from 'node:test' import {fileURLToPath} from 'node:url' @@ -37,20 +37,21 @@ test('args', async function (t) { await fs.unlink(new URL('watch.txt', base)) } catch {} - const help = String(await fs.readFile(new URL('HELP', base))).replace( - /\r\n/g, - '\n' - ) - const longFlag = String( - await fs.readFile(new URL('LONG_FLAG', base)) - ).replace(/\r\n/g, '\n') + // . + // const help = String(await fs.readFile(new URL('HELP', base))).replace( + // /\r\n/g, + // '\n' + // ) + // const longFlag = String( + // await fs.readFile(new URL('LONG_FLAG', base)) + // ).replace(/\r\n/g, '\n') await t.test('should expose the public api', async function () { assert.deepEqual(Object.keys(await import('../index.js')).sort(), ['args']) }) - const shortFlag = String( - await fs.readFile(new URL('SHORT_FLAG', base)) - ).replace(/\r\n/g, '\n') + // . const shortFlag = String( + // await fs.readFile(new URL('SHORT_FLAG', base)) + // ).replace(/\r\n/g, '\n') await t.test('should fail on missing files', async function () { try { @@ -76,611 +77,613 @@ test('args', async function (t) { } }) - await t.test('should accept a path to a file', async function () { - const result = await exec(binPath + ' one.txt') - - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['one\n', 'one.txt: no issues found\n'] - ) - }) - - await t.test('should accept a path to a directory', async function () { - const result = await exec(binPath + ' .') - - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '', - [ - 'one.txt: no issues found', - 'three' + sep + 'five.txt: no issues found', - 'three' + sep + 'four.txt: no issues found', - 'two.txt: no issues found', - '' - ].join('\n') - ] - ) - }) - - await t.test('should accept a glob to files', async function () { - const result = await exec(binPath + ' "*.txt"') + // . + // await t.test('should accept a path to a file', async function () { + // const result = await exec(binPath + ' one.txt') - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['', 'one.txt: no issues found\ntwo.txt: no issues found\n'] - ) - }) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['one\n', 'one.txt: no issues found\n'] + // ) + // }) - await t.test('should accept a glob to a directory', async function () { - const result = await exec(binPath + ' "thr+(e)"') + // await t.test('should accept a path to a directory', async function () { + // const result = await exec(binPath + ' .') + + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '', + // [ + // 'one.txt: no issues found', + // 'three' + sep + 'five.txt: no issues found', + // 'three' + sep + 'four.txt: no issues found', + // 'two.txt: no issues found', + // '' + // ].join('\n') + // ] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '', - [ - 'three' + sep + 'five.txt: no issues found', - 'three' + sep + 'four.txt: no issues found', - '' - ].join('\n') - ] - ) - }) + // await t.test('should accept a glob to files', async function () { + // const result = await exec(binPath + ' "*.txt"') - await t.test('should fail on a bad short flag', async function () { - try { - await exec(binPath + ' -n') - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['', 'one.txt: no issues found\ntwo.txt: no issues found\n'] + // ) + // }) - assert.deepEqual( - [result.code, cleanError(result.stderr, 14) + '\n'], - [1, shortFlag] - ) - } - }) + // await t.test('should accept a glob to a directory', async function () { + // const result = await exec(binPath + ' "thr+(e)"') + + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '', + // [ + // 'three' + sep + 'five.txt: no issues found', + // 'three' + sep + 'four.txt: no issues found', + // '' + // ].join('\n') + // ] + // ) + // }) - await t.test('should fail on a bad grouped short flag', async function () { - try { - await exec(binPath + ' -on') - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) + // await t.test('should fail on a bad short flag', async function () { + // try { + // await exec(binPath + ' -n') + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) - assert.deepEqual( - [result.code, cleanError(result.stderr, 14) + '\n'], - [1, shortFlag] - ) - } - }) + // assert.deepEqual( + // [result.code, cleanError(result.stderr, 14) + '\n'], + // [1, shortFlag] + // ) + // } + // }) - await t.test('should fail on a bad long flag', async function () { - try { - await exec(binPath + ' --no') - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) + // await t.test('should fail on a bad grouped short flag', async function () { + // try { + // await exec(binPath + ' -on') + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) - assert.deepEqual( - [result.code, cleanError(result.stderr, 26) + '\n'], - [1, longFlag] - ) - } - }) + // assert.deepEqual( + // [result.code, cleanError(result.stderr, 14) + '\n'], + // [1, shortFlag] + // ) + // } + // }) - await helpFlag('-h') - await helpFlag('--help') - - /** - * @param {string} flag - * Flag. - * @returns {Promise} - * Nothing. - */ - async function helpFlag(flag) { - await t.test('should show help on `' + flag + '`', async function () { - const result = await exec(binPath + ' ' + flag) - assert.deepEqual([result.stdout, result.stderr], [help, '']) - }) - } - - await versionFlag('-v') - await versionFlag('--version') - - /** - * @param {string} flag - * Flag. - * @returns {Promise} - * Nothing. - */ - async function versionFlag(flag) { - await t.test('should show version on `' + flag + '`', async function () { - const result = await exec(binPath + ' ' + flag) - - assert.deepEqual([result.stdout, result.stderr], ['0.0.0\n', '']) - }) - } + // await t.test('should fail on a bad long flag', async function () { + // try { + // await exec(binPath + ' --no') + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) - await t.test('should support `--color`', async function () { - const result = await exec(binPath + ' --color one.txt') + // assert.deepEqual( + // [result.code, cleanError(result.stderr, 26) + '\n'], + // [1, longFlag] + // ) + // } + // }) - assert.deepEqual( - [result.stdout, result.stderr], - [ - 'one\n', - '\u001B[4m\u001B[32mone.txt\u001B[39m\u001B[24m: no issues found\n' - ] - ) - }) + // await helpFlag('-h') + // await helpFlag('--help') + + // /** + // * @param {string} flag + // * Flag. + // * @returns {Promise} + // * Nothing. + // */ + // async function helpFlag(flag) { + // await t.test('should show help on `' + flag + '`', async function () { + // const result = await exec(binPath + ' ' + flag) + // assert.deepEqual([result.stdout, result.stderr], [help, '']) + // }) + // } + + // await versionFlag('-v') + // await versionFlag('--version') + + // /** + // * @param {string} flag + // * Flag. + // * @returns {Promise} + // * Nothing. + // */ + // async function versionFlag(flag) { + // await t.test('should show version on `' + flag + '`', async function () { + // const result = await exec(binPath + ' ' + flag) + + // assert.deepEqual([result.stdout, result.stderr], ['0.0.0\n', '']) + // }) + // } - await t.test('should support `--no-color`', async function () { - const result = await exec(binPath + ' --no-color one.txt') + // await t.test('should support `--color`', async function () { + // const result = await exec(binPath + ' --color one.txt') - assert.deepEqual( - [result.stdout, result.stderr], - ['one\n', 'one.txt: no issues found\n'] - ) - }) + // assert.deepEqual( + // [result.stdout, result.stderr], + // [ + // 'one\n', + // '\u001B[4m\u001B[32mone.txt\u001B[39m\u001B[24m: no issues found\n' + // ] + // ) + // }) - await extFlag('-e') - await extFlag('--ext') + // await t.test('should support `--no-color`', async function () { + // const result = await exec(binPath + ' --no-color one.txt') - /** - * @param {string} flag - * Flag. - * @returns {Promise} - * Nothing. - */ - async function extFlag(flag) { - await t.test('should support `' + flag + '`', async function () { - const result = await exec(binPath + ' . ' + flag + ' text') + // assert.deepEqual( + // [result.stdout, result.stderr], + // ['one\n', 'one.txt: no issues found\n'] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '', - [ - 'alpha.text: no issues found', - 'bravo.text: no issues found', - 'charlie' + sep + 'delta.text: no issues found', - 'charlie' + sep + 'echo.text: no issues found', - 'delta.text: no issues found', - '' - ].join('\n') - ] - ) - }) + // await extFlag('-e') + // await extFlag('--ext') - await t.test( - 'should fail on `' + flag + '` without value', - async function () { - try { - await exec(binPath + ' . ' + flag) - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) + // /** + // * @param {string} flag + // * Flag. + // * @returns {Promise} + // * Nothing. + // */ + // async function extFlag(flag) { + // await t.test('should support `' + flag + '`', async function () { + // const result = await exec(binPath + ' . ' + flag + ' text') - assert.deepEqual( - [result.code, cleanError(result.stderr, 1)], - [ - 1, - 'Error: Missing value: -e --ext specify extensions' - ] - ) - } - } - ) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '', + // [ + // 'alpha.text: no issues found', + // 'bravo.text: no issues found', + // 'charlie' + sep + 'delta.text: no issues found', + // 'charlie' + sep + 'echo.text: no issues found', + // 'delta.text: no issues found', + // '' + // ].join('\n') + // ] + // ) + // }) - await t.test( - 'should allow an extra `-e` after `' + flag + '`', - async function () { - const result = await exec(binPath + ' . ' + flag + ' text -e') + // await t.test( + // 'should fail on `' + flag + '` without value', + // async function () { + // try { + // await exec(binPath + ' . ' + flag) + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) + + // assert.deepEqual( + // [result.code, cleanError(result.stderr, 1)], + // [ + // 1, + // 'Error: Missing value: -e --ext specify extensions' + // ] + // ) + // } + // } + // ) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '', - [ - 'alpha.text: no issues found', - 'bravo.text: no issues found', - 'charlie' + sep + 'delta.text: no issues found', - 'charlie' + sep + 'echo.text: no issues found', - 'delta.text: no issues found', - '' - ].join('\n') - ] - ) - } - ) - } - - await settingsFlag('-s') - await settingsFlag('--setting') - - /** - * @param {string} flag - * Flag. - * @returns {Promise} - * Nothing. - */ - async function settingsFlag(flag) { - await t.test( - 'should catch syntax errors in `' + flag + '`', - async function () { - try { - // Should be quoted. - await exec(binPath + ' . ' + flag + ' foo:bar') - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) + // await t.test( + // 'should allow an extra `-e` after `' + flag + '`', + // async function () { + // const result = await exec(binPath + ' . ' + flag + ' text -e') - assert.deepEqual( - [result.code, cleanError(result.stderr, 1)], - [1, 'Error: Cannot parse `foo:bar` as JSON'] - ) - } - } - ) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '', + // [ + // 'alpha.text: no issues found', + // 'bravo.text: no issues found', + // 'charlie' + sep + 'delta.text: no issues found', + // 'charlie' + sep + 'echo.text: no issues found', + // 'delta.text: no issues found', + // '' + // ].join('\n') + // ] + // ) + // } + // ) + // } + + // await settingsFlag('-s') + // await settingsFlag('--setting') + + // /** + // * @param {string} flag + // * Flag. + // * @returns {Promise} + // * Nothing. + // */ + // async function settingsFlag(flag) { + // await t.test( + // 'should catch syntax errors in `' + flag + '`', + // async function () { + // try { + // // Should be quoted. + // await exec(binPath + ' . ' + flag + ' foo:bar') + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) + + // assert.deepEqual( + // [result.code, cleanError(result.stderr, 1)], + // [1, 'Error: Cannot parse `foo:bar` as JSON'] + // ) + // } + // } + // ) - await t.test('should support `' + flag + '`', async function () { - const binPath = fileURLToPath( - new URL('fixtures/settings/cli.js', import.meta.url) - ) + // await t.test('should support `' + flag + '`', async function () { + // const binPath = fileURLToPath( + // new URL('fixtures/settings/cli.js', import.meta.url) + // ) - const result = await exec( - binPath + ' one.txt ' + flag + ' "\\"foo-bar\\":\\"baz\\""' - ) + // const result = await exec( + // binPath + ' one.txt ' + flag + ' "\\"foo-bar\\":\\"baz\\""' + // ) - // Parser and Compiler both log stringified settings. - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['{"fooBar":"baz"}\none\n', 'one.txt: no issues found\n'] - ) - }) - } + // // Parser and Compiler both log stringified settings. + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['{"fooBar":"baz"}\none\n', 'one.txt: no issues found\n'] + // ) + // }) + // } - await t.test('should not fail on property-like settings', async function () { - const binPath = fileURLToPath( - new URL('fixtures/settings/cli.js', import.meta.url) - ) + // await t.test('should not fail on property-like settings', async function () { + // const binPath = fileURLToPath( + // new URL('fixtures/settings/cli.js', import.meta.url) + // ) - const result = await exec( - binPath + ' . --setting "foo:\\"https://example.com\\""' - ) + // const result = await exec( + // binPath + ' . --setting "foo:\\"https://example.com\\""' + // ) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['{"foo":"https://example.com"}\n', 'one.txt: no issues found\n'] - ) - }) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['{"foo":"https://example.com"}\n', 'one.txt: no issues found\n'] + // ) + // }) - await t.test('should ignore boolean settings', async function () { - const binPath = fileURLToPath( - new URL('fixtures/settings/cli.js', import.meta.url) - ) + // await t.test('should ignore boolean settings', async function () { + // const binPath = fileURLToPath( + // new URL('fixtures/settings/cli.js', import.meta.url) + // ) - const result = await exec(binPath + ' . --no-setting ') + // const result = await exec(binPath + ' . --no-setting ') - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['{}\n', 'one.txt: no issues found\n'] - ) - }) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['{}\n', 'one.txt: no issues found\n'] + // ) + // }) - await useFlag('-u') - await useFlag('--use') - - /** - * @param {string} flag - * Flag. - * @returns {Promise} - * Nothing. - */ - async function useFlag(flag) { - await t.test('should load a plugin with `' + flag + '`', async function () { - const binPath = fileURLToPath( - new URL('fixtures/plugins/cli.js', import.meta.url) - ) + // await useFlag('-u') + // await useFlag('--use') + + // /** + // * @param {string} flag + // * Flag. + // * @returns {Promise} + // * Nothing. + // */ + // async function useFlag(flag) { + // await t.test('should load a plugin with `' + flag + '`', async function () { + // const binPath = fileURLToPath( + // new URL('fixtures/plugins/cli.js', import.meta.url) + // ) - const result = await exec(binPath + ' one.txt ' + flag + ' ./plugin.js') + // const result = await exec(binPath + ' one.txt ' + flag + ' ./plugin.js') - // Attacher logs options, which are `undefined`. - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['undefined\none\n', 'one.txt: no issues found\n'] - ) - }) + // // Attacher logs options, which are `undefined`. + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['undefined\none\n', 'one.txt: no issues found\n'] + // ) + // }) - await t.test( - 'should catch syntax errors in `' + flag + '`', - async function () { - // Should be quoted. - try { - await exec(binPath + ' . ' + flag + ' ./plugin.js=foo:bar') - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) + // await t.test( + // 'should catch syntax errors in `' + flag + '`', + // async function () { + // // Should be quoted. + // try { + // await exec(binPath + ' . ' + flag + ' ./plugin.js=foo:bar') + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) + + // assert.deepEqual( + // [result.code, cleanError(result.stderr, 1)], + // [1, 'Error: Cannot parse `foo:bar` as JSON'] + // ) + // } + // } + // ) - assert.deepEqual( - [result.code, cleanError(result.stderr, 1)], - [1, 'Error: Cannot parse `foo:bar` as JSON'] - ) - } - } - ) + // await t.test('should support `' + flag + '`', async function () { + // const binPath = fileURLToPath( + // new URL('fixtures/plugins/cli.js', import.meta.url) + // ) - await t.test('should support `' + flag + '`', async function () { - const binPath = fileURLToPath( - new URL('fixtures/plugins/cli.js', import.meta.url) - ) + // const result = await exec( + // binPath + + // ' one.txt ' + + // flag + + // ' "./plugin.js=foo:{bar:\\"baz\\",qux:1,quux:true}"' + // ) - const result = await exec( - binPath + - ' one.txt ' + - flag + - ' "./plugin.js=foo:{bar:\\"baz\\",qux:1,quux:true}"' - ) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '{"foo":{"bar":"baz","qux":1,"quux":true}}\none\n', + // 'one.txt: no issues found\n' + // ] + // ) + // }) + // } + + // await t.test('should support `--report`', async function () { + // const result = await exec(binPath + ' alpha.text --report json') + + // assert.deepEqual( + // [result.stdout, result.stderr], + // [ + // 'alpha\n', + // JSON.stringify([ + // { + // path: 'alpha.text', + // cwd: 'test/fixtures/example', + // history: ['alpha.text'], + // messages: [] + // } + // ]) + '\n' + // ] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '{"foo":{"bar":"baz","qux":1,"quux":true}}\none\n', - 'one.txt: no issues found\n' - ] - ) - }) - } - - await t.test('should support `--report`', async function () { - const result = await exec(binPath + ' alpha.text --report json') - - assert.deepEqual( - [result.stdout, result.stderr], - [ - 'alpha\n', - JSON.stringify([ - { - path: 'alpha.text', - cwd: 'test/fixtures/example', - history: ['alpha.text'], - messages: [] - } - ]) + '\n' - ] - ) - }) + // await t.test('should support `--report` with options', async function () { + // const result = await exec( + // binPath + ' alpha.text --report "json=pretty:\\"\\t\\""' + // ) - await t.test('should support `--report` with options', async function () { - const result = await exec( - binPath + ' alpha.text --report "json=pretty:\\"\\t\\""' - ) + // assert.deepEqual( + // [result.stdout, result.stderr], + // [ + // 'alpha\n', + // JSON.stringify( + // [ + // { + // path: 'alpha.text', + // cwd: 'test/fixtures/example', + // history: ['alpha.text'], + // messages: [] + // } + // ], + // undefined, + // '\t' + // ) + '\n' + // ] + // ) + // }) - assert.deepEqual( - [result.stdout, result.stderr], - [ - 'alpha\n', - JSON.stringify( - [ - { - path: 'alpha.text', - cwd: 'test/fixtures/example', - history: ['alpha.text'], - messages: [] - } - ], - undefined, - '\t' - ) + '\n' - ] - ) - }) + // await t.test('should fail on `--report` without value', async function () { + // try { + // await exec(binPath + ' . --report') + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) - await t.test('should fail on `--report` without value', async function () { - try { - await exec(binPath + ' . --report') - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) + // assert.deepEqual( + // [result.code, cleanError(result.stderr, 1)], + // [1, 'Error: Missing value: --report specify reporter'] + // ) + // } + // }) - assert.deepEqual( - [result.code, cleanError(result.stderr, 1)], - [1, 'Error: Missing value: --report specify reporter'] - ) - } - }) + // await t.test('should support `--no-stdout`', async function () { + // const result = await exec(binPath + ' one.txt --no-stdout') - await t.test('should support `--no-stdout`', async function () { - const result = await exec(binPath + ' one.txt --no-stdout') + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['', 'one.txt: no issues found\n'] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['', 'one.txt: no issues found\n'] - ) - }) + // await t.test('should support `--tree-in`', async function () { + // const result = await exec(binPath + ' tree.json --tree-in') - await t.test('should support `--tree-in`', async function () { - const result = await exec(binPath + ' tree.json --tree-in') + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['hi!', 'tree.json: no issues found\n'] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['hi!', 'tree.json: no issues found\n'] - ) - }) + // await t.test('should support `--tree-out`', async function () { + // const result = await exec(binPath + ' one.txt --tree-out') - await t.test('should support `--tree-out`', async function () { - const result = await exec(binPath + ' one.txt --tree-out') + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '{\n "type": "text",\n "value": "one\\n"\n}\n', + // 'one.txt: no issues found\n' + // ] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '{\n "type": "text",\n "value": "one\\n"\n}\n', - 'one.txt: no issues found\n' - ] - ) - }) + // await t.test('should support `--tree`', async function () { + // const result = await exec(binPath + ' tree.json --tree') - await t.test('should support `--tree`', async function () { - const result = await exec(binPath + ' tree.json --tree') + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '{\n "type": "text",\n "value": "hi!"\n}\n', + // 'tree.json: no issues found\n' + // ] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '{\n "type": "text",\n "value": "hi!"\n}\n', - 'tree.json: no issues found\n' - ] - ) - }) + // await t.test('should support `--ignore-pattern`', async function () { + // const result = await exec( + // binPath + + // ' . --ext txt,text --ignore-pattern "charlie/*,three/*.txt,delta.*"' + // ) - await t.test('should support `--ignore-pattern`', async function () { - const result = await exec( - binPath + - ' . --ext txt,text --ignore-pattern "charlie/*,three/*.txt,delta.*"' - ) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '', + // [ + // 'alpha.text: no issues found', + // 'bravo.text: no issues found', + // 'one.txt: no issues found', + // 'two.txt: no issues found', + // '' + // ].join('\n') + // ] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '', - [ - 'alpha.text: no issues found', - 'bravo.text: no issues found', - 'one.txt: no issues found', - 'two.txt: no issues found', - '' - ].join('\n') - ] - ) - }) + // await t.test('should support `--ignore-path`', async function () { + // const result = await exec( + // binPath + ' . --ext text --ignore-path charlie' + sep + 'ignore' + // ) - await t.test('should support `--ignore-path`', async function () { - const result = await exec( - binPath + ' . --ext text --ignore-path charlie' + sep + 'ignore' - ) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '', + // [ + // 'alpha.text: no issues found', + // 'bravo.text: no issues found', + // 'charlie' + sep + 'echo.text: no issues found', + // 'delta.text: no issues found', + // '' + // ].join('\n') + // ] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '', - [ - 'alpha.text: no issues found', - 'bravo.text: no issues found', - 'charlie' + sep + 'echo.text: no issues found', - 'delta.text: no issues found', - '' - ].join('\n') - ] - ) - }) + // await t.test('should ignore non-last `--ignore-path`s', async function () { + // const result = await exec( + // binPath + + // ' . --ext text --ignore-path missing --ignore-path charlie' + + // sep + + // 'ignore' + // ) - await t.test('should ignore non-last `--ignore-path`s', async function () { - const result = await exec( - binPath + - ' . --ext text --ignore-path missing --ignore-path charlie' + - sep + - 'ignore' - ) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '', + // [ + // 'alpha.text: no issues found', + // 'bravo.text: no issues found', + // 'charlie' + sep + 'echo.text: no issues found', + // 'delta.text: no issues found', + // '' + // ].join('\n') + // ] + // ) + // }) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '', - [ - 'alpha.text: no issues found', - 'bravo.text: no issues found', - 'charlie' + sep + 'echo.text: no issues found', - 'delta.text: no issues found', - '' - ].join('\n') - ] - ) - }) + // await t.test( + // 'should support `--ignore-path-resolve-from cwd`', + // async function () { + // const result = await exec( + // binPath + + // ' . --ext text --ignore-path charlie' + + // sep + + // 'ignore --ignore-path-resolve-from cwd' + // ) - await t.test( - 'should support `--ignore-path-resolve-from cwd`', - async function () { - const result = await exec( - binPath + - ' . --ext text --ignore-path charlie' + - sep + - 'ignore --ignore-path-resolve-from cwd' - ) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // [ + // '', + // [ + // 'alpha.text: no issues found', + // 'bravo.text: no issues found', + // 'charlie' + sep + 'echo.text: no issues found', + // '' + // ].join('\n') + // ] + // ) + // } + // ) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - [ - '', - [ - 'alpha.text: no issues found', - 'bravo.text: no issues found', - 'charlie' + sep + 'echo.text: no issues found', - '' - ].join('\n') - ] - ) - } - ) + // await t.test('should fail when given an ignored path', async function () { + // try { + // await exec(binPath + ' one.txt two.txt --ignore-pattern one.txt') + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) - await t.test('should fail when given an ignored path', async function () { - try { - await exec(binPath + ' one.txt two.txt --ignore-pattern one.txt') - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) + // assert.deepEqual( + // [result.code, cleanError(result.stderr)], + // [ + // 1, + // [ + // 'one.txt', + // ' error Cannot process specified file: it’s ignored', + // '', + // 'two.txt: no issues found', + // '', + // '✖ 1 error', + // '' + // ].join('\n') + // ] + // ) + // } + // }) - assert.deepEqual( - [result.code, cleanError(result.stderr)], - [ - 1, - [ - 'one.txt', - ' error Cannot process specified file: it’s ignored', - '', - 'two.txt: no issues found', - '', - '✖ 1 error', - '' - ].join('\n') - ] - ) - } - }) + // await t.test( + // 'should fail when given an incorrect `ignore-path-resolve-from`', + // async function () { + // try { + // await exec(binPath + ' one.txt --ignore-path-resolve-from xyz') + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) - await t.test( - 'should fail when given an incorrect `ignore-path-resolve-from`', - async function () { - try { - await exec(binPath + ' one.txt --ignore-path-resolve-from xyz') - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) - - assert.deepEqual( - [result.code, cleanError(result.stderr, 1)], - [ - 1, - "Error: Expected `'cwd'` or `'dir'` for `ignore-path-resolve-from`, not: `xyz`" - ] - ) - } - } - ) + // assert.deepEqual( + // [result.code, cleanError(result.stderr, 1)], + // [ + // 1, + // "Error: Expected `'cwd'` or `'dir'` for `ignore-path-resolve-from`, not: `xyz`" + // ] + // ) + // } + // } + // ) - await t.test('should support `--silently-ignore`', async function () { - const result = await exec( - binPath + ' one.txt two.txt --ignore-pattern one.txt --silently-ignore' - ) + // await t.test('should support `--silently-ignore`', async function () { + // const result = await exec( + // binPath + ' one.txt two.txt --ignore-pattern one.txt --silently-ignore' + // ) - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['', 'two.txt: no issues found\n'] - ) - }) + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['', 'two.txt: no issues found\n'] + // ) + // }) await t.test('should support `--watch`', async function () { // Ignore checking watch mode on Windows. if (platform === 'win32') { + console.warn('Not checking watch mode on windows…') return } @@ -690,10 +693,10 @@ test('args', async function (t) { await new Promise(function (resolve) { const delay = 500 - setTimeout(seeYouLaterAlligator, delay) - const proc = spawn(binPath, ['watch.txt', '-w']) + setTimeout(seeYouLaterAlligator, delay) + proc.on('close', async function (code) { assert.equal(code, 0) await fs.unlink(url) @@ -730,99 +733,93 @@ test('args', async function (t) { }) }) - // . - // await t.test('should not regenerate when watching', async function () { - // const url = new URL('watch.txt', base) - // await fs.writeFile(url, 'alpha') - - // await new Promise(function (resolve) { - // let resolved = false - // const delay = 3000 - - // const proc = execCb(binPath + ' watch.txt -w -o', onsuccess) - - // setTimeout(seeYouLaterAlligator, delay) - - // /** - // * Callback. - // * - // * @param {ExecExceptionBasic | null} error - // * Error. - // * @param {string} stdout - // * Output. - // * @param {string} stderr - // * Error. - // * @returns {Promise} - // * Nothing. - // */ - // async function onsuccess(error, stdout, stderr) { - // resolved = true - // await fs.unlink(url) - // const lines = [ - // 'Watching... (press CTRL+C to exit)', - // 'Note: Ignoring `--output` until exit.', - // 'watch.txt: no issues found', - // 'watch.txt: no issues found' - // ] + await t.test('should not regenerate when watching', async function () { + // Ignore checking watch mode on Windows. + if (platform === 'win32') { + console.warn('Not checking watch mode on windows…') + return + } - // // Windows immediatly quits. - // // Other OSes support cleaning up things. - // if (platform !== 'win32') { - // lines.push('', 'watch.txt: written') - // } + const url = new URL('watch.txt', base) + await fs.writeFile(url, 'alpha') - // assert.deepEqual( - // [error, stdout, cleanError(stderr)], - // [null, '', lines.join('\n') + '\n'] - // ) + await new Promise(function (resolve) { + const delay = 500 - // resolve(undefined) - // } + const proc = spawn(binPath, ['watch.txt', '-w', '-o']) - // async function seeYouLaterAlligator() { - // assert.equal(resolved, false) - // await fs.writeFile(url, 'bravo') - // setTimeout(afterAWhileCrocodile, delay) - // } + setTimeout(seeYouLaterAlligator, delay) - // function afterAWhileCrocodile() { - // assert.equal(resolved, false) - // proc.kill('SIGINT') - // } - // }) - // }) + proc.on('close', async function (code) { + assert.equal(code, 0) + await fs.unlink(url) + resolve(undefined) + }) - // await t.test('should exit on fatal errors when watching', async function () { - // try { - // await exec(binPath + ' -w') - // assert.fail() - // } catch (error) { - // const result = /** @type {ExecException} */ (error) + proc.stdout.pipe( + concatStream(function (d) { + assert.deepEqual(String(d), '') + }) + ) + proc.stderr.pipe( + concatStream(function (d) { + assert.deepEqual( + cleanError(String(d)), + [ + 'Watching... (press CTRL+C to exit)', + 'Note: Ignoring `--output` until exit.', + 'watch.txt: no issues found', + 'watch.txt: no issues found', + '', + 'watch.txt: written', + '' + ].join('\n') + ) + }) + ) - // assert.deepEqual( - // [result.code, cleanError(result.stderr, 2)], - // [1, 'Watching... (press CTRL+C to exit)\nError: No input'] - // ) - // } - // }) + async function seeYouLaterAlligator() { + await fs.writeFile(url, 'bravo') + setTimeout(afterAWhileCrocodile, delay) + } - // await t.test('should report uncaught exceptions', async function () { - // const binPath = fileURLToPath( - // new URL('fixtures/uncaught-errors/cli.js', import.meta.url) - // ) + function afterAWhileCrocodile() { + proc.kill('SIGINT') + } + }) + }) - // try { - // await exec(binPath + ' . -u ./plugin.js') - // assert.fail() - // } catch (error) { - // const result = /** @type {ExecException} */ (error) + await t.test('should exit on fatal errors when watching', async function () { + try { + await exec(binPath + ' -w') + assert.fail() + } catch (error) { + const result = /** @type {ExecException} */ (error) - // assert.deepEqual( - // [result.code, cleanError(result.stderr)], - // [1, 'one.txt: no issues found\nfoo\n'] - // ) - // } - // }) + assert.deepEqual( + [result.code, cleanError(result.stderr, 2)], + [1, 'Watching... (press CTRL+C to exit)\nError: No input'] + ) + } + }) + + await t.test('should report uncaught exceptions', async function () { + const binPath = fileURLToPath( + new URL('fixtures/uncaught-errors/cli.js', import.meta.url) + ) + + try { + await exec(binPath + ' . -u ./plugin.js') + assert.fail() + } catch (error) { + const result = /** @type {ExecException} */ (error) + + assert.deepEqual( + [result.code, cleanError(result.stderr)], + [1, 'one.txt: no issues found\nfoo\n'] + ) + } + }) }) /**