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 e0abc13 commit eadfe05
Showing 1 changed file with 47 additions and 63 deletions.
110 changes: 47 additions & 63 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import assert from 'node:assert/strict'
// . exec as execCb
import fs from 'node:fs/promises'
import {sep} from 'node:path'
import {EOL} from 'node:os'
// . import {platform} from 'node:process'
import test from 'node:test'
import {fileURLToPath} from 'node:url'
Expand Down Expand Up @@ -424,7 +425,7 @@ test('args', async function (t) {
JSON.stringify([
{
path: 'alpha.text',
cwd: 'test/fixtures/example',
cwd: 'test' + sep + 'fixtures' + sep + 'example',
history: ['alpha.text'],
messages: []
}
Expand All @@ -448,7 +449,7 @@ test('args', async function (t) {
[
{
path: 'alpha.text',
cwd: 'test/fixtures/example',
cwd: 'test' + sep + 'fixtures' + sep + 'example',
history: ['alpha.text'],
messages: []
}
Expand Down Expand Up @@ -498,7 +499,7 @@ test('args', async function (t) {
assert.deepEqual(
[result.stdout, cleanError(result.stderr)],
[
'{\n "type": "text",\n "value": "one\\n"\n}',
JSON.stringify({type: 'text', value: 'one' + EOL}, undefined, 2),
'one.txt: no issues found'
]
)
Expand Down Expand Up @@ -679,20 +680,21 @@ test('args', async function (t) {
})

await t.test('should support `--watch`', async function () {
// On Windows, `SIGINT` results in an error, as it has to be forced.
// Hence `reject: false` and `exitCode`.
const delay = 500
const url = new URL('watch.txt', base)
await fs.writeFile(url, 'alpha')

const delay = 500
await fs.writeFile(url, 'alpha')

const proc = execa(binPath, ['watch.txt', '-w'])
const proc = execa(binPath, ['watch.txt', '-w'], {reject: false})

setTimeout(seeYouLaterAlligator, delay)

const result = await proc

await fs.unlink(url)

assert.equal(result.exitCode, 0)
assert.equal(result.stdout, '')
assert.equal(
cleanError(result.stderr),
Expand All @@ -704,6 +706,7 @@ test('args', async function (t) {
''
].join('\n')
)
assert.equal(result.exitCode, 0)

async function seeYouLaterAlligator() {
await fs.writeFile(url, 'bravo')
Expand All @@ -715,62 +718,43 @@ test('args', async function (t) {
}
})

// .
// 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
// }

// const url = new URL('watch.txt', base)
// await fs.writeFile(url, 'alpha')

// await new Promise(function (resolve) {
// const delay = 500

// const proc = spawn(binPath, ['watch.txt', '-w', '-o'])

// setTimeout(seeYouLaterAlligator, delay)

// proc.on('close', async function (code) {
// assert.equal(code, 0)
// await fs.unlink(url)
// resolve(undefined)
// })

// 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')
// )
// })
// )

// async function seeYouLaterAlligator() {
// await fs.writeFile(url, 'bravo')
// setTimeout(afterAWhileCrocodile, delay)
// }

// function afterAWhileCrocodile() {
// proc.kill('SIGINT')
// }
// })
// })
await t.test('should not regenerate when watching', async function () {
const delay = 500
const url = new URL('watch.txt', base)

await fs.writeFile(url, 'alpha')

const proc = execa(binPath, ['watch.txt', '-w', '-o'], {reject: false})

setTimeout(seeYouLaterAlligator, delay)

const result = await proc

await fs.unlink(url)

assert.equal(result.stdout, '')
assert.equal(
cleanError(result.stderr),
[
'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.equal(result.exitCode, 0)

async function seeYouLaterAlligator() {
await fs.writeFile(url, 'bravo')
setTimeout(afterAWhileCrocodile, delay)
}

function afterAWhileCrocodile() {
proc.kill('SIGINT')
}
})

await t.test('should exit on fatal errors when watching', async function () {
try {
Expand Down

0 comments on commit eadfe05

Please sign in to comment.