From da381687a5c0608222b47a39fd4ad424807a2fce Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 21 Aug 2023 10:38:25 +0200 Subject: [PATCH] debug --- .github/workflows/main.yml | 24 +- test/index.js | 1491 ++++++++++++++++++------------------ 2 files changed, 757 insertions(+), 758 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 546f9c9..c2a3398 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,8 +4,8 @@ on: - push jobs: main: - name: ${{matrix.node}} - runs-on: ubuntu-latest + name: '${{matrix.node}} on ${{matrix.os}}' + runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -16,21 +16,9 @@ jobs: - uses: codecov/codecov-action@v3 strategy: matrix: + os: + - ubuntu-latest + # - windows-latest node: - - lts/gallium - - node - windows: - name: ${{matrix.node}} - runs-on: windows-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: ${{matrix.node}} - - run: npm install - - run: npm run test-api - strategy: - matrix: - node: - - lts/gallium + # - lts/gallium - node diff --git a/test/index.js b/test/index.js index fb00b4a..e943e48 100644 --- a/test/index.js +++ b/test/index.js @@ -17,14 +17,14 @@ import assert from 'node:assert/strict' import {exec as execCb} from 'node:child_process' import fs from 'node:fs/promises' -import {sep} from 'node:path' -import {platform} from 'node:process' +// . import {sep} from 'node:path' +// . import {platform} from 'node:process' import test from 'node:test' import {fileURLToPath} from 'node:url' -import {promisify} from 'node:util' +// . import {promisify} from 'node:util' import stripAnsi from 'strip-ansi' -const exec = promisify(execCb) +// . const exec = promisify(execCb) const base = new URL('fixtures/example/', import.meta.url) const bin = new URL('fixtures/example/cli.js', import.meta.url) @@ -36,646 +36,647 @@ 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') - - 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') - - await t.test('should fail on missing files', async function () { - try { - await exec(binPath + ' missing.txt', {cwd: base}) - assert.fail() - } catch (error) { - const result = /** @type {ExecException} */ (error) - assert.deepEqual( - [result.code, cleanError(result.stderr)], - [ - 1, - [ - 'missing.txt', - ' error No such file or folder', - ' [cause]:', - ' Error: ENOENT:…', - '', - '✖ 1 error', - '' - ].join('\n') - ] - ) - } - }) - - 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"') - - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['', 'one.txt: no issues found\ntwo.txt: no issues found\n'] - ) - }) - - 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 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] - ) - } - }) - - 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, 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) - - assert.deepEqual( - [result.code, cleanError(result.stderr, 26) + '\n'], - [1, longFlag] - ) - } - }) - - 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 `--color`', async function () { - const result = await exec(binPath + ' --color one.txt') - - assert.deepEqual( - [result.stdout, result.stderr], - [ - 'one\n', - '\u001B[4m\u001B[32mone.txt\u001B[39m\u001B[24m: no issues found\n' - ] - ) - }) - - await t.test('should support `--no-color`', async function () { - const result = await exec(binPath + ' --no-color one.txt') - - assert.deepEqual( - [result.stdout, result.stderr], - ['one\n', 'one.txt: no issues found\n'] - ) - }) - - await extFlag('-e') - await extFlag('--ext') - - /** - * @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, 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 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' - ] - ) - } - } - ) - - await t.test( - 'should allow an extra `-e` after `' + flag + '`', - async function () { - const result = await exec(binPath + ' . ' + flag + ' text -e') - - 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) - ) - - 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'] - ) - }) - } - - 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\\""' - ) - - 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) - ) - - const result = await exec(binPath + ' . --no-setting ') - - 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) - ) - - 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'] - ) - }) - - 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'] - ) - } - } - ) - - 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}"' - ) - - 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\\""' - ) - - 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) - - 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') - - 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') - - 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') - - 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') - - 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.*"' - ) - - 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' - ) - - 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' - ) - - 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' - ) - - 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) - - 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) - - 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' - ) - - assert.deepEqual( - [result.stdout, cleanError(result.stderr)], - ['', 'two.txt: no issues found\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') + + // await t.test('should fail on missing files', async function () { + // try { + // await exec(binPath + ' missing.txt', {cwd: base}) + // assert.fail() + // } catch (error) { + // const result = /** @type {ExecException} */ (error) + // assert.deepEqual( + // [result.code, cleanError(result.stderr)], + // [ + // 1, + // [ + // 'missing.txt', + // ' error No such file or folder', + // ' [cause]:', + // ' Error: ENOENT:…', + // '', + // '✖ 1 error', + // '' + // ].join('\n') + // ] + // ) + // } + // }) + + // 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"') + + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['', 'one.txt: no issues found\ntwo.txt: no issues found\n'] + // ) + // }) + + // 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 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] + // ) + // } + // }) + + // 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, 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) + + // assert.deepEqual( + // [result.code, cleanError(result.stderr, 26) + '\n'], + // [1, longFlag] + // ) + // } + // }) + + // 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 `--color`', async function () { + // const result = await exec(binPath + ' --color one.txt') + + // assert.deepEqual( + // [result.stdout, result.stderr], + // [ + // 'one\n', + // '\u001B[4m\u001B[32mone.txt\u001B[39m\u001B[24m: no issues found\n' + // ] + // ) + // }) + + // await t.test('should support `--no-color`', async function () { + // const result = await exec(binPath + ' --no-color one.txt') + + // assert.deepEqual( + // [result.stdout, result.stderr], + // ['one\n', 'one.txt: no issues found\n'] + // ) + // }) + + // await extFlag('-e') + // await extFlag('--ext') + + // /** + // * @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, 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 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' + // ] + // ) + // } + // } + // ) + + // await t.test( + // 'should allow an extra `-e` after `' + flag + '`', + // async function () { + // const result = await exec(binPath + ' . ' + flag + ' text -e') + + // 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) + // ) + + // 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'] + // ) + // }) + // } + + // 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\\""' + // ) + + // 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) + // ) + + // const result = await exec(binPath + ' . --no-setting ') + + // 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) + // ) + + // 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'] + // ) + // }) + + // 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'] + // ) + // } + // } + // ) + + // 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}"' + // ) + + // 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\\""' + // ) + + // 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) + + // 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') + + // 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') + + // 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') + + // 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') + + // 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.*"' + // ) + + // 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' + // ) + + // 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' + // ) + + // 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' + // ) + + // 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) + + // 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) + + // 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' + // ) + + // assert.deepEqual( + // [result.stdout, cleanError(result.stderr)], + // ['', 'two.txt: no issues found\n'] + // ) + // }) await t.test('should support `--watch`', async function () { const url = new URL('watch.txt', base) @@ -685,9 +686,11 @@ test('args', async function (t) { const delay = 3000 let resolved = false - const proc = execCb(binPath + ' watch.txt -w', onsuccess) - + console.log('x1') setTimeout(seeYouLaterAlligator, delay) + console.log('x2') + const proc = execCb(binPath + ' watch.txt -w', onsuccess) + console.log('x3') /** * Callback. @@ -702,9 +705,10 @@ test('args', async function (t) { * Nothing. */ async function onsuccess(error, stdout, stderr) { + console.log('s1') resolved = true await fs.unlink(url) - + console.log('s2') assert.deepEqual( [error, stdout, cleanError(stderr)], [ @@ -718,115 +722,122 @@ test('args', async function (t) { ].join('\n') ] ) - + console.log('s3') resolve(undefined) + console.log('s4') } async function seeYouLaterAlligator() { + console.log('y1') assert.equal(resolved, false) await fs.writeFile(url, 'bravo') + console.log('y2') setTimeout(afterAWhileCrocodile, delay) + console.log('y3') } function afterAWhileCrocodile() { + console.log('z1') assert.equal(resolved, false) + console.log('z2') proc.kill('SIGINT') } }) }) - 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' - ] - - // Windows immediatly quits. - // Other OSes support cleaning up things. - if (platform !== 'win32') { - lines.push('', 'watch.txt: written') - } - - assert.deepEqual( - [error, stdout, cleanError(stderr)], - [null, '', lines.join('\n') + '\n'] - ) - - resolve(undefined) - } - - async function seeYouLaterAlligator() { - assert.equal(resolved, false) - await fs.writeFile(url, 'bravo') - setTimeout(afterAWhileCrocodile, delay) - } - - function afterAWhileCrocodile() { - assert.equal(resolved, false) - proc.kill('SIGINT') - } - }) - }) - - 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, 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'] - ) - } - }) + // . + // 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' + // ] + + // // Windows immediatly quits. + // // Other OSes support cleaning up things. + // if (platform !== 'win32') { + // lines.push('', 'watch.txt: written') + // } + + // assert.deepEqual( + // [error, stdout, cleanError(stderr)], + // [null, '', lines.join('\n') + '\n'] + // ) + + // resolve(undefined) + // } + + // async function seeYouLaterAlligator() { + // assert.equal(resolved, false) + // await fs.writeFile(url, 'bravo') + // setTimeout(afterAWhileCrocodile, delay) + // } + + // function afterAWhileCrocodile() { + // assert.equal(resolved, false) + // proc.kill('SIGINT') + // } + // }) + // }) + + // 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, 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'] + // ) + // } + // }) }) /**