github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/triage/script_test.js (about) 1 const assert = require('assert'); 2 const model = require('./model'); 3 const render = require('./render'); 4 5 describe('makeBuckets', () => { 6 function expect(name, expected, ...args) { 7 it(name, function() { 8 assert.deepEqual(render.makeBuckets(...args), expected); 9 }); 10 } 11 expect('makes a histogram', [[0, 3], [4, 2]], [0, 1, 2, 4, 5], 4, 0, 4) 12 expect('expands to fill range', [[0, 0], [4, 0], [8, 0], [12, 0]], [], 4, 0, 12); 13 expect('shifts start to match width', [[0, 1], [4, 1]], [2, 6], 4, 2, 6); 14 }); 15 16 describe('sparkLinePath', () => { 17 function expect(name, expected, ...args) { 18 it(name, function() { 19 assert.deepEqual(render.sparkLinePath(...args), expected); 20 }); 21 } 22 expect('draws a zero graph', 'M0,9h5', [0,0,0,0,0], 1, 9); 23 expect('draws a spikey graph', 'M0,9h1V0h1V9h1', [0,1,0], 1, 9); 24 expect('combines adjacents spans', 'M0,9h1V4h2V0h1V9h1', [0,1,1,2,0], 1, 9); 25 expect('handles scaling', 'M0,8h0V7h2V6h1V4h1V0h1V8', [2,4,8,16,32], 1, 8); 26 }) 27 28 describe('Clusters', () => { 29 describe('refilter', () => { 30 function expect(name, expected, clustered, opts) { 31 it(name, function() { 32 var c = new model.Clusters(clustered); 33 assert.deepEqual(c.refilter(opts).data, expected); 34 }); 35 } 36 let ham = {text: 'ham', key: 'ham', id: '1234', owner: 'node', tests: [ 37 {name: 'volume', jobs: [{name: 'cure', builds: [1, 2]}]}, 38 ]}; 39 let spam = {text: 'spam', key: 'spam', id: '5678', owner: 'ui', tests: [ 40 {name: 'networking', jobs: [{name: 'g', builds: [2]}]}, 41 ]}; 42 let pr = {text: 'bam', key: 'bam', id: '9abc', tests: [ 43 {name: 'new', jobs: [{name: 'pr:verify', builds: [3]}]}, 44 ]}; 45 let first = {text: 'afirst', key: 'afirst', id: 'def0', tests: [ 46 {name: 'something', jobs: [{name: 'firstjob', builds: [5, 6]}]}, 47 ]}; 48 expect('filters by text', [ham], [ham, spam], {reText: /ham/im, ci: true}); 49 expect('filters by test', [ham], [ham, spam], {reTest: /volume/im, ci: true}); 50 expect('filters by job', [ham], [ham, spam], {reJob: /cure/im, ci: true}); 51 expect('filters by sig', [ham], [ham, spam], {sig: ['node'], ci: true}); 52 expect('shows PRs when demanded', [pr], [ham, spam, pr], {pr: true}); 53 expect('hides PRs otherwise', [ham, spam], [ham, spam, pr], {ci: true}); 54 expect('can hide everything', [], [ham, spam, pr], {}); 55 expect('sorts results by build count', [ham, spam], [spam, ham], {ci: true, sort: 'total'}); 56 expect('sorts results by message', [first, ham, spam], [ham, spam, first], {ci: true, sort: 'message'}); 57 }); 58 });