Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 21, 2023
1 parent 61dc1ed commit 288dc7c
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 107 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ on:
- pull_request
- push
jobs:
# unix:
# name: '${{matrix.node}} on ${{matrix.os}}'
# runs-on: ${{matrix.os}}
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: ${{matrix.node}}
# - run: npm install
# - run: npm run test-api
# # - uses: codecov/codecov-action@v3
# strategy:
# matrix:
# os:
# - ubuntu-latest
# node:
# - lts/gallium
# - node
unix:
name: '${{matrix.node}} on ${{matrix.os}}'
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm run test-api
# - uses: codecov/codecov-action@v3
strategy:
matrix:
os:
- ubuntu-latest
node:
- lts/gallium
# - node
# Just run quick tests on windows.
windows:
name: '${{matrix.node}} on ${{matrix.os}}'
Expand All @@ -37,5 +37,5 @@ jobs:
os:
- windows-latest
node:
# - lts/gallium
- node
- lts/gallium
# - node
171 changes: 84 additions & 87 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {import('node:child_process').ExecException} ExecExceptionBasic
* @typedef {import('execa').ExecaError<string>} ExecaError
* @typedef {import('execa').ExecaError<string>} ExecaException
* To do: rename.
*/

/**
Expand Down Expand Up @@ -40,17 +40,15 @@ 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 shortFlag = String(
// await fs.readFile(new URL('SHORT_FLAG', base))
// ).replace(/\r\n/g, '\n')
const help = String(await fs.readFile(new URL('HELP', base)))
.replace(/\r\n/g, '\n')
.trimEnd()
const longFlag = String(await fs.readFile(new URL('LONG_FLAG', base)))
.replace(/\r\n/g, '\n')
.trimEnd()
const shortFlag = String(await fs.readFile(new URL('SHORT_FLAG', base)))
.replace(/\r\n/g, '\n')
.trimEnd()

await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('../index.js')).sort(), ['args'])
Expand All @@ -61,7 +59,7 @@ test('args', async function (t) {
await execa(binPath, ['missing.txt'])
assert.fail()
} catch (error) {
const result = /** @type {ExecaError} */ (error)
const result = /** @type {ExecaException} */ (error)
assert.deepEqual(
[result.exitCode, cleanError(result.stderr)],
[
Expand Down Expand Up @@ -105,90 +103,89 @@ test('args', async function (t) {
)
})

// .
// await t.test('should accept a glob to files', async function () {
// const result = await exec(binPath + ' "*.txt"')
await t.test('should accept a glob to files', async function () {
const result = await execa(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)],
['', 'one.txt: no issues found\ntwo.txt: no issues found']
)
})

// 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 a directory', async function () {
const result = await execa(binPath, ['thr+(e)'])

// 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)],
[
'',
[
'three' + sep + 'five.txt: no issues found',
'three' + sep + 'four.txt: no issues found'
].join('\n')
]
)
})

// assert.deepEqual(
// [result.code, cleanError(result.stderr, 14) + '\n'],
// [1, shortFlag]
// )
// }
// })
await t.test('should fail on a bad short flag', async function () {
try {
await execa(binPath, ['-n'])
assert.fail()
} catch (error) {
const result = /** @type {ExecaException} */ (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.exitCode, cleanError(result.stderr, 14)],
[1, shortFlag]
)
}
})

// 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 execa(binPath, ['-on'])
assert.fail()
} catch (error) {
const result = /** @type {ExecaException} */ (error)

// 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.exitCode, cleanError(result.stderr, 14)],
[1, shortFlag]
)
}
})

// assert.deepEqual(
// [result.code, cleanError(result.stderr, 26) + '\n'],
// [1, longFlag]
// )
// }
// })
await t.test('should fail on a bad long flag', async function () {
try {
await execa(binPath, ['--no'])
assert.fail()
} catch (error) {
const result = /** @type {ExecaException} */ (error)

// await helpFlag('-h')
// await helpFlag('--help')
assert.deepEqual(
[result.exitCode, cleanError(result.stderr, 26)],
[1, longFlag]
)
}
})

// /**
// * @param {string} flag
// * Flag.
// * @returns {Promise<undefined>}
// * 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 helpFlag('-h')
await helpFlag('--help')

/**
* @param {string} flag
* Flag.
* @returns {Promise<undefined>}
* Nothing.
*/
async function helpFlag(flag) {
await t.test('should show help on `' + flag + '`', async function () {
const result = await execa(binPath, [flag])
assert.deepEqual([result.stdout, result.stderr], [help, ''])
})
}

// .
// await versionFlag('-v')
// await versionFlag('--version')

Expand Down

0 comments on commit 288dc7c

Please sign in to comment.