Skip to content

Commit

Permalink
🧑‍💻 Slightly nicer output for test reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Jan 11, 2024
1 parent 230f368 commit dbab2ad
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"prettier": "^3.0.3",
"prettier-plugin-organize-imports": "^3.2.3",
"prettier-plugin-svelte": "^3.0.3",
"tap-spec": "^5.0.0",
"turbo": "^1.11.2",
"typescript": "^5.2.2"
},
Expand Down
113 changes: 113 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions scripts/scripts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare module 'tap-spec' {
import { Transform } from 'stream'

declare type SpecOptions = {
padding?: string
}

function tapSpec(spec?: SpecOptions): Transform
export default tapSpec
}
26 changes: 12 additions & 14 deletions scripts/unit-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/// <reference path="./scripts.d.ts" />
import { App } from '@tinyhttp/app'
import { type ExecaChildProcess, execa } from 'execa'
import { writeFileSync } from 'node:fs'
import { createWriteStream } from 'node:fs'
import { argv, exit } from 'node:process'
import tapSpec from 'tap-spec'

// If you update this port, you should update the port in the test runner
const TEST_PORT = 3948
Expand All @@ -17,21 +19,17 @@ let testProcess: ExecaChildProcess<string>
new App()
.get('/config', (_, res) => void res.send({ shouldWatch }))
.post('/results', (req, res) => {
let result = ''
req.on('data', (chunk: Buffer) => {
// eslint-disable-next-line no-console
console.log(chunk.toString())
result += chunk.toString() + '\n'
})
req.on('close', () => {
res.send('ok')
// Provide a nice reporter to the console
req.pipe(tapSpec()).pipe(process.stdout)

if (!shouldWatch) {
writeFileSync('./.store/units.tap', result)
testProcess?.kill()
if (!shouldWatch) {
req.pipe(createWriteStream('./.store/units.tap')).on('close', () => {
testProcess.kill()
exit()
}
})
})
}

req.on('close', () => res.send('ok'))
})
.listen(TEST_PORT)

Expand Down

0 comments on commit dbab2ad

Please sign in to comment.