-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_readme.js
More file actions
69 lines (61 loc) · 3.15 KB
/
Copy pathupdate_readme.js
File metadata and controls
69 lines (61 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const fs = require('fs');
const libraries = {
'react-redux': '<a href="https://react-redux.js.org">react-redux</a>',
'react-tracked': '<a href="https://react-tracked.js.org">react-tracked</a>',
constate: '<a href="https://github.com/diegohaz/constate">constate</a>',
zustand: '<a href="https://github.com/pmndrs/zustand">zustand</a>',
'react-hooks-global-state': '<a href="https://github.com/dai-shi/react-hooks-global-state">react-hooks-global-state</a>',
'use-context-selector': '<a href="https://github.com/dai-shi/use-context-selector">use-context-selector</a> (w/ useReducer)',
'use-subscription': '<a href="https://github.com/facebook/react/tree/master/packages/use-subscription">use-subscription</a> (w/ redux)',
simplux: '<a href="https://github.com/MrWolfZ/simplux">simplux</a>',
'apollo-client': '<a href="https://github.com/apollographql/apollo-client">apollo-client</a>',
recoil: '<a href="https://recoiljs.org">recoil</a>',
jotai: '<a href="https://github.com/pmndrs/jotai">jotai</a>',
effector: '<a href="https://github.com/zerobias/effector">effector</a>',
'react-rxjs': '<a href="https://react-rxjs.org">react-rxjs</a>',
valtio: '<a href="https://github.com/pmndrs/valtio">valtio</a>',
};
function wrap(content, tag) { return `<${tag}>${content}</${tag}>`; }
function check(status) { return status === 'failed' ? ':x:' : ':white_check_mark:'; }
// Get results into an array of test with a 2nd dimension by test/fail
const results = JSON.parse(fs.readFileSync('./outfile.json', 'utf8'));
const testResults = [];
results.testResults[0].assertionResults.forEach((result, ix) => {
const testNumber = Math.floor(ix / 6);
testResults[testNumber] = testResults[testNumber] || [];
testResults[testNumber][ix % 6] = { status: result.status, title: result.ancestorTitles[0] };
});
// Format table for substitution in outfile
let sub = '';
testResults.forEach((result) => {
if (!libraries[result[0].title]) {
console.info('no library entry for', result[0].title);
return;
}
const th = wrap(libraries[result[0].title], 'th');
const tds = result.map((test) => `\t\t${wrap(check(test.status), 'td')}\n`).join('');
sub += `\t<tr>\n\t\t${th}\n${tds}\t</tr>\n`;
});
// Find first and last line of raw results
let first = 0;
let last = 0;
function note(line, ix) {
if (line.match(/[✓✕]/)) {
if (!first) first = ix - 6;
last = ix;
}
// eslint-disable-next-line no-control-regex
return line.replace(/..\r/g, '').replace(/\[.../g, '').substr(5);
}
// Read and process raw results
const resultsRaw = fs.readFileSync('./outfile_raw.txt', 'utf8');
let lines = resultsRaw.split(/\n\r|\n/).map((l, i) => note(l.substr(0), i));
lines = lines.slice(first, last + 1);
lines = lines.filter((line, ix) => ix % 3 === 0);
// Update readme
let readme = fs.readFileSync('./README.md', 'utf8');
readme = readme.replace(/<table>([\s\S]*?)<\/table>/,
`<table>\n<tr><th>Test</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th></tr>\n${sub}\n</table>`);
readme = readme.replace(/<details>([\s\S]*?)<\/details>/,
`<details>\n<summary>Raw Output</summary>\n\n\`\`\`\n${lines.join('\n')}\n\n\`\`\`\n</details>`);
fs.writeFileSync('./README.md', readme);