Remove Tape dependencies.
This remove the Tape dependency and change how we write Tap: * Always write both success and failures. * Skip the error trace since it do not add any extra information.
This commit is contained in:
parent
c592349bc3
commit
5efbe64b62
|
|
@ -1,36 +1,44 @@
|
|||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import { EOL } from 'node:os';
|
||||
import tap from 'tape';
|
||||
import { getLogger } from '@sitespeed.io/log';
|
||||
|
||||
const log = getLogger('sitespeedio.plugin.budget');
|
||||
|
||||
export function writeTap(results, dir) {
|
||||
const file = path.join(dir, 'budget.tap');
|
||||
log.info('Write budget to %s', path.resolve(file));
|
||||
const tapOutput = fs.createWriteStream(file);
|
||||
tap.createStream().pipe(tapOutput);
|
||||
|
||||
const lines = [];
|
||||
lines.push('TAP version 13');
|
||||
let testCount = 0;
|
||||
|
||||
// Iterate over each result group (e.g. "passing" and "failing")
|
||||
for (const resultType of Object.keys(results)) {
|
||||
const urls = Object.keys(results.failing);
|
||||
|
||||
const group = results[resultType];
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
const urls = Object.keys(group);
|
||||
for (const url of urls) {
|
||||
for (const result of results.failing[url]) {
|
||||
tap(result.type + '.' + result.metric + ' ' + url, function (t) {
|
||||
let extra = '';
|
||||
if (resultType === 'failing') {
|
||||
extra =
|
||||
' limit ' + result.limitType + ' ' + result.friendlyLimit ||
|
||||
result.limit + EOL;
|
||||
}
|
||||
t.ok(
|
||||
resultType === 'failing' ? false : true,
|
||||
result.type + '.' + result.metric + ' ' + result.friendlyValue ||
|
||||
result.value + ' ' + extra + ' ' + url
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
for (const result of group[url]) {
|
||||
testCount += 1;
|
||||
const testTitle = `${result.type}.${result.metric} ${url}`;
|
||||
let extra = '';
|
||||
if (resultType === 'failing') {
|
||||
extra = ` limit ${result.limitType} ${result.friendlyLimit || result.limit}`;
|
||||
}
|
||||
const valueDisplay = result.friendlyValue || result.value;
|
||||
|
||||
lines.push(`# ${testTitle}`);
|
||||
const status = resultType === 'failing' ? 'not ok' : 'ok';
|
||||
lines.push(
|
||||
`${status} ${testCount} ${testTitle} ${valueDisplay}${extra ? ` ${extra}` : ''}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lines.push(`1..${testCount}`);
|
||||
fs.writeFileSync(file, lines.join(EOL) + EOL);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -105,7 +105,6 @@
|
|||
"ora": "8.0.1",
|
||||
"pug": "3.0.3",
|
||||
"simplecrawler": "1.1.9",
|
||||
"tape": "5.8.1",
|
||||
"yargs": "17.7.2"
|
||||
},
|
||||
"overrides": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue