From dbab2ad890eca66548ea3cf1ac3efb188159d9a0 Mon Sep 17 00:00:00 2001
From: trickypr <23250792+trickypr@users.noreply.github.com>
Date: Thu, 11 Jan 2024 13:17:12 +1100
Subject: [PATCH] :technologist: Slightly nicer output for test reporter
---
package.json | 1 +
pnpm-lock.yaml | 113 +++++++++++++++++++++++++++++++++++++++++++
scripts/scripts.d.ts | 10 ++++
scripts/unit-test.ts | 26 +++++-----
4 files changed, 136 insertions(+), 14 deletions(-)
create mode 100644 scripts/scripts.d.ts
diff --git a/package.json b/package.json
index 094d919..44d8350 100644
--- a/package.json
+++ b/package.json
@@ -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"
},
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 46b750d..591274b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -67,6 +67,9 @@ importers:
prettier-plugin-svelte:
specifier: ^3.0.3
version: 3.0.3(prettier@3.0.3)(svelte@4.2.8)
+ tap-spec:
+ specifier: ^5.0.0
+ version: 5.0.0
turbo:
specifier: ^1.11.2
version: 1.11.2
@@ -2830,6 +2833,10 @@ packages:
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
dev: true
+ /buffer-shims@1.0.0:
+ resolution: {integrity: sha512-Zy8ZXMyxIT6RMTeY7OP/bDndfj6bwCan7SS98CEndS6deHwWPpseeHlwarNcBim+etXnF9HBc1non5JgDaJU1g==}
+ dev: true
+
/builtin-modules@3.3.0:
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
engines: {node: '>=6'}
@@ -4602,6 +4609,11 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
+ /is-finite@1.1.0:
+ resolution: {integrity: sha512-cdyMtqX/BOqqNBBiKlIVkytNHm49MtMlYyn1zxzvJKWmFMlGzm+ry5BBfYyeY9YmNKbRSo/o7OX9w9ale0wg3w==}
+ engines: {node: '>=0.10.0'}
+ dev: true
+
/is-fullwidth-code-point@3.0.0:
resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
engines: {node: '>=8'}
@@ -5467,6 +5479,11 @@ packages:
lines-and-columns: 1.2.4
dev: true
+ /parse-ms@1.0.1:
+ resolution: {integrity: sha512-LpH1Cf5EYuVjkBvCDBYvkUPh+iv2bk3FHflxHkpCYT0/FZ1d3N3uJaLiHr4yGuMcFUhv6eAivitTvWZI4B/chg==}
+ engines: {node: '>=0.10.0'}
+ dev: true
+
/parseurl@1.3.3:
resolution: {integrity: sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==}
engines: {node: '>= 0.8'}
@@ -5540,6 +5557,11 @@ packages:
find-up: 4.1.0
dev: true
+ /plur@1.0.0:
+ resolution: {integrity: sha512-qSnKBSZeDY8ApxwhfVIwKwF36KVJqb1/9nzYYq3j3vdwocULCXT8f8fQGkiw1Nk9BGfxiDagEe/pwakA+bOBqw==}
+ engines: {node: '>=0.10.0'}
+ dev: true
+
/postcss-calc@8.2.4(postcss@8.4.31):
resolution: {integrity: sha512-SmWMSJmB8MRnnULldx0lQIyhSNvuDl9HfrZkaqqE/WHAhToYsAvDq+yAsA/kIyINDszOp3Rh0GFoNuH5Ypsm3Q==}
peerDependencies:
@@ -5990,6 +6012,19 @@ packages:
renderkid: 3.0.0
dev: true
+ /pretty-ms@2.1.0:
+ resolution: {integrity: sha512-H2enpsxzDhuzRl3zeSQpQMirn8dB0Z/gxW96j06tMfTviUWvX14gjKb7qd1gtkUyYhDPuoNe00K5PqNvy2oQNg==}
+ engines: {node: '>=0.10.0'}
+ dependencies:
+ is-finite: 1.1.0
+ parse-ms: 1.0.1
+ plur: 1.0.0
+ dev: true
+
+ /process-nextick-args@1.0.7:
+ resolution: {integrity: sha512-yN0WQmuCX63LP/TMvAg31nvT6m4vDqJEiiv2CAZqWOGNWutc9DfDk1NPYYmKUFmaVM2UwDowH4u5AHWYP/jxKw==}
+ dev: true
+
/process-nextick-args@2.0.1:
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
dev: true
@@ -6044,6 +6079,22 @@ packages:
unpipe: 1.0.0
dev: true
+ /re-emitter@1.1.3:
+ resolution: {integrity: sha512-bHJul9CWcocrS+w5e5QrKYXV9NkbSA9hxSEyhYuctwm6keY9NXR2Xt/4A0vbMP0QvuwyfEyb4bkowYXv1ziEbg==}
+ dev: true
+
+ /readable-stream@2.2.9:
+ resolution: {integrity: sha512-iuxqX7b7FYt08AriYECxUsK9KTXE3A/FenxIa3IPmvANHxaTP/wGIwwf+IidvvIDk/MsCp/oEV6A8CXo4SDcCg==}
+ dependencies:
+ buffer-shims: 1.0.0
+ core-util-is: 1.0.3
+ inherits: 2.0.4
+ isarray: 1.0.0
+ process-nextick-args: 1.0.7
+ string_decoder: 1.0.3
+ util-deprecate: 1.0.2
+ dev: true
+
/readable-stream@2.3.8:
resolution: {integrity: sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==}
dependencies:
@@ -6152,6 +6203,11 @@ packages:
strip-ansi: 6.0.1
dev: true
+ /repeat-string@1.6.1:
+ resolution: {integrity: sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==}
+ engines: {node: '>=0.10'}
+ dev: true
+
/require-directory@2.1.1:
resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==}
engines: {node: '>=0.10.0'}
@@ -6662,6 +6718,12 @@ packages:
- supports-color
dev: true
+ /split@1.0.0:
+ resolution: {integrity: sha512-3SVfJe2A0WZg3D+ZEtXqYkvpSGAVaZ1MgufNCeHioBESCqQFsuT1VcQufiopBfJZqh92ZwQ6ddL378iUSbqVNQ==}
+ dependencies:
+ through: 2.3.8
+ dev: true
+
/stable@0.1.8:
resolution: {integrity: sha512-ji9qxRnOVfcuLDySj9qzhGSEFVobyt1kIOSkj1qZzYLzq7Tos/oUUWvotUPQLlrsidqsK6tBH89Bc9kL5zHA6w==}
deprecated: 'Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility'
@@ -6729,6 +6791,12 @@ packages:
es-abstract: 1.22.3
dev: true
+ /string_decoder@1.0.3:
+ resolution: {integrity: sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==}
+ dependencies:
+ safe-buffer: 5.1.2
+ dev: true
+
/string_decoder@1.1.1:
resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==}
dependencies:
@@ -6948,6 +7016,30 @@ packages:
/tabbable@6.2.0:
resolution: {integrity: sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==}
+ /tap-out@2.1.0:
+ resolution: {integrity: sha512-LJE+TBoVbOWhwdz4+FQk40nmbIuxJLqaGvj3WauQw3NYYU5TdjoV3C0x/yq37YAvVyi+oeBXmWnxWSjJ7IEyUw==}
+ hasBin: true
+ dependencies:
+ re-emitter: 1.1.3
+ readable-stream: 2.2.9
+ split: 1.0.0
+ trim: 0.0.1
+ dev: true
+
+ /tap-spec@5.0.0:
+ resolution: {integrity: sha512-zMDVJiE5I6Y4XGjlueGXJIX2YIkbDN44broZlnypT38Hj/czfOXrszHNNJBF/DXR8n+x6gbfSx68x04kIEHdrw==}
+ hasBin: true
+ dependencies:
+ chalk: 1.1.3
+ duplexer: 0.1.2
+ figures: 1.7.0
+ lodash: 4.17.21
+ pretty-ms: 2.1.0
+ repeat-string: 1.6.1
+ tap-out: 2.1.0
+ through2: 2.0.5
+ dev: true
+
/tapable@2.2.1:
resolution: {integrity: sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==}
engines: {node: '>=6'}
@@ -6992,6 +7084,17 @@ packages:
resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==}
dev: true
+ /through2@2.0.5:
+ resolution: {integrity: sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==}
+ dependencies:
+ readable-stream: 2.3.8
+ xtend: 4.0.2
+ dev: true
+
+ /through@2.3.8:
+ resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==}
+ dev: true
+
/thunky@1.1.0:
resolution: {integrity: sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==}
dev: true
@@ -7025,6 +7128,11 @@ packages:
hasBin: true
dev: true
+ /trim@0.0.1:
+ resolution: {integrity: sha512-YzQV+TZg4AxpKxaTHK3c3D+kRDCGVEE7LemdlQZoQXn0iennk10RsIoY6ikzAqJTc9Xjl9C1/waHom/J86ziAQ==}
+ deprecated: Use String.prototype.trim() instead
+ dev: true
+
/truncate-utf8-bytes@1.0.2:
resolution: {integrity: sha512-95Pu1QXQvruGEhv62XCMO3Mm90GscOCClvrIUwCM0PYOXK3kaF3l3sIHxx71ThJfcbM2O5Au6SO3AWCSEfW4mQ==}
dependencies:
@@ -7553,6 +7661,11 @@ packages:
optional: true
dev: true
+ /xtend@4.0.2:
+ resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==}
+ engines: {node: '>=0.4'}
+ dev: true
+
/y18n@5.0.8:
resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
engines: {node: '>=10'}
diff --git a/scripts/scripts.d.ts b/scripts/scripts.d.ts
new file mode 100644
index 0000000..542ffb4
--- /dev/null
+++ b/scripts/scripts.d.ts
@@ -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
+}
diff --git a/scripts/unit-test.ts b/scripts/unit-test.ts
index 2defa60..a6f8345 100644
--- a/scripts/unit-test.ts
+++ b/scripts/unit-test.ts
@@ -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/. */
+///
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
@@ -17,21 +19,17 @@ let testProcess: ExecaChildProcess
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)