Skip to content

Commit

Permalink
fix: error output is undefined and drop tools
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Oct 24, 2024
1 parent 536f436 commit 743c60f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@types/unzipper": "^0.10.10",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"cli-progress": "^3.12.0",
"esbuild": "^0.24.0",
"esbuild-register": "^3.6.0",
"eslint": "^8.50.0",
Expand All @@ -62,7 +61,6 @@
"eslint-plugin-import": "^2.28.1",
"json-stable-stringify": "^1.0.1",
"lint-staged": "^10.5.4",
"log-update": "4.0.0",
"prettier": "^3.0.3",
"release-it": "^16.2.1",
"rimraf": "^3.0.2",
Expand Down
47 changes: 21 additions & 26 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

const path = require('path');
const pc = require('picocolors');
const cliProgress = require('cli-progress');
const logUpdate = require('log-update');
const { globSync } = require('tinyglobby');
const utils = require('./utils.js');
const { spawn } = require('child_process');
Expand Down Expand Up @@ -122,17 +120,22 @@ function runTest(file) {
}
};

const output = [];

const rejectWithError = (error) => {
error.logOutput = `${error.message}\n${output.join('')}`;
reject(error);
};

process.on('close', (code) => {
removeProcess();
if (code !== 0) {
reject(new Error(`Process exited with code ${code}`));
rejectWithError(new Error(`Process exited with code ${code}`));
} else {
resolve();
}
});

const output = [];

process.stdout.on('data', (data) => {
output.push(data.toString());
});
Expand All @@ -143,40 +146,37 @@ function runTest(file) {

process.on('error', (error) => {
removeProcess();
error.logOutput = `${error.message}\n${output.join('')}`;
reject(error);
rejectWithError(error);
});
});
}

async function run() {
const progressBar = new cliProgress.SingleBar(
{},
cliProgress.Presets.shades_classic,
);
progressBar.start(files.length, 0);
const clearLastLine = () => {
process.stdout.moveCursor(0, -1); // up one line
process.stdout.clearLine(1); // from cursor to end
};

async function run() {
const logs = [];

Check failure on line 160 in test/test.js

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-latest)

'logs' is assigned a value but never used
let done = 0;
let ok = 0;
let failed = [];
const start = Date.now();

function addLog(log, isError = false) {
if (!isCI) {
logs.push(log);
logUpdate(logs.join('\n'));
} else if (isError) {
clearLastLine();
if (isError) {
console.error(log);
} else {
console.log(log);
}
}

const promises = files.sort().map(async (file) => {
const promises = files.sort().map((file) => async () => {
file = path.resolve(file);
const startTest = Date.now();
try {
console.log(pc.gray(`⏳ ${file} - ${done}/${files.length}`));
await runTest(file);
ok++;
addLog(
Expand All @@ -192,24 +192,19 @@ async function run() {
});
addLog(
pc.red(
`✖ ${file} FAILED (in ${target}) - ${msToHumanDuration(Date.now() - startTest)}`,
`✖ ${file} FAILED (in ${target}) - ${msToHumanDuration(Date.now() - startTest)}\n${error.message}`,
),
true,
);
addLog(pc.red(error.message), true);
}

done++;
progressBar.increment();
});

for (let i = 0; i < promises.length; i++) {
await promises[i];
await promises[i]();
}

progressBar.stop();
logUpdate.done();

const end = Date.now();

console.log('');
Expand All @@ -224,7 +219,7 @@ async function run() {
// print failed tests
for (const { file, error, output } of failed) {
console.log('');
console.log(pc.red(file));
console.log(`--- ${file} ---`);
console.log(pc.red(error));
console.log(pc.red(output));
}
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1249,13 +1249,6 @@ cli-cursor@^4.0.0:
dependencies:
restore-cursor "^4.0.0"

cli-progress@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/cli-progress/-/cli-progress-3.12.0.tgz#807ee14b66bcc086258e444ad0f19e7d42577942"
integrity sha512-tRkV3HJ1ASwm19THiiLIXLO7Im7wlTuKnvkYaTkyoAPefqjNg7W7DHKUlGRxy9vxDvbyCYQkQozvptuMkGCg8A==
dependencies:
string-width "^4.2.3"

cli-spinners@^2.5.0, cli-spinners@^2.9.0:
version "2.9.2"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.9.2.tgz#1773a8f4b9c4d6ac31563df53b3fc1d79462fe41"
Expand Down Expand Up @@ -3389,7 +3382,7 @@ log-symbols@^5.1.0:
chalk "^5.0.0"
is-unicode-supported "^1.1.0"

log-update@4.0.0, log-update@^4.0.0:
log-update@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/log-update/-/log-update-4.0.0.tgz#589ecd352471f2a1c0c570287543a64dfd20e0a1"
integrity sha512-9fkkDevMefjg0mmzWFBW8YkFP91OrizzkW3diF7CpG+S2EYdy4+TVfGwz1zeF8x7hCx1ovSPTOE9Ngib74qqUg==
Expand Down

0 comments on commit 743c60f

Please sign in to comment.