Skip to content

Commit

Permalink
reuse bft styling
Browse files Browse the repository at this point in the history
respect NO_COLOR
  • Loading branch information
balazs4 committed Jul 11, 2022
1 parent 23785a8 commit 21c778d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
38 changes: 25 additions & 13 deletions check.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,41 @@ const report = (tests) => {
const failed = tests.filter((t) => t.conclusion === 'failed').length;

if (process.env.ALOLA_REPORT === 'json') {
process.stderr.write(JSON.stringify(tests) + "\n");
process.stderr.write(JSON.stringify(tests) + '\n');
return;
}

const color = (conclusion) => (txt) => {
if (conclusion === 'passed') return `\u001b[32m${txt}\u001b[39m`;
if (conclusion === 'failed')
return `\u001b[41m\u001b[97m${txt}\u001b[39m\u001b[49m`;
if (conclusion === 'skipped') return `\u001b[93m${txt}\u001b[39m`;
return txt;
const redgreenyellow = (txt) => {
return process.stdout.hasColors && process.stdout.hasColors() === true
? txt
.replace(/^PASSED/, '\x1b[32mPASSED\x1b[0m')
.replace(/^FAILED/, '\x1b[31mFAILED\x1b[0m')
.replace(/^SKIPPED/, '\x1b[33mSKIPPED\x1b[0m')
: txt;
};

const gray = (txt) => {
return process.stdout.hasColors && process.stdout.hasColors() === true
? `\x1b[2m${txt}\x1b[0m`
: txt;
};

const bold = (txt) => {
return process.stdout.hasColors && process.stdout.hasColors() === true
? `\x1b[1m${txt}\x1b[0m`
: txt;
};

tests.forEach((t) => {
const c = color(t.conclusion);
const line = [
c(t.conclusion),
t.conclusion === 'failed' ? '<-o-<' : '>-o->',
t.assertion,
t.reason,
redgreenyellow(t.conclusion.toUpperCase()),
t.conclusion === 'failed' ? bold(' vvv ') : gray(' >>> '),
t.conclusion === 'failed' ? bold(t.assertion) : t.assertion,
t.reason ? `\n${bold(t.reason)}` : null,
]
.filter((x) => x)
.join('\t');

process.stderr.write(`${line}\n`);
});

Expand Down Expand Up @@ -128,7 +141,6 @@ const verify = (json) => (assertion) => {
return {
conclusion: 'skipped',
assertion,
reason: 'unknown assertion',
};
}

Expand Down
6 changes: 3 additions & 3 deletions parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ module.exports = (block) => {

result['body'] =
result.rawbody && result.rawbody.join
? jsonOrNull(result.rawbody.join(''))
? jsonOrShitInShitOut(result.rawbody.join(''))
: null;

delete result.rawbody;

return result;
};

const jsonOrNull = (text) => {
const jsonOrShitInShitOut = (text) => {
try {
return JSON.parse(text);
} catch (e) {
} catch (_) {
return text;
}
};
Expand Down

0 comments on commit 21c778d

Please sign in to comment.