UNPKG

2.19 kBJavaScriptView Raw
1'use strict'
2
3const test = require('tap').test
4const issueCategory = require('../analysis/issue-category.js')
5
6test('Analysis - issue category', function (t) {
7 const testQueries = [
8 // cpu memory delay handles category
9 ' perf perf perf perf -> unknown',
10 ' perf perf perf .... -> unknown',
11 ' perf perf .... perf -> unknown',
12 ' perf perf .... .... -> unknown',
13 ' perf .... perf perf -> unknown',
14 ' perf .... perf .... -> unknown',
15 ' perf .... .... perf -> io',
16 ' perf .... .... .... -> io',
17 // cpu memory delay handles category
18 ' .... perf perf perf -> unknown',
19 ' .... perf perf .... -> gc',
20 ' .... perf .... perf -> unknown',
21 ' .... perf .... .... -> gc',
22 ' .... .... perf perf -> unknown',
23 ' .... .... perf .... -> event-loop',
24 ' .... .... .... perf -> io',
25 ' .... .... .... .... -> none',
26 // cpu memory delay handles category
27 ' data .... .... .... -> data',
28 ' .... data .... .... -> data',
29 ' .... .... data .... -> data',
30 ' .... .... .... data -> data'
31 ]
32
33 const queryParser = new RegExp([
34 /^ {2}/.source,
35 /(perf|data|\.{4}) {3}/.source,
36 /(perf|data|\.{4}) {3}/.source,
37 /(perf|data|\.{4}) {3}/.source,
38 /(perf|data|\.{4}) {3}/.source,
39 / -> (data|gc|event-loop|io|none|unknown)$/.source
40 ].join(''))
41
42 const shortToLong = {
43 perf: 'performance',
44 data: 'data',
45 '....': 'none'
46 }
47
48 for (const testQuery of testQueries) {
49 const parsed = testQuery.match(queryParser)
50 if (parsed === null) {
51 t.fail(`could not parse "${testQuery}"`)
52 }
53
54 const issues = {
55 cpu: shortToLong[parsed[1]],
56 memory: {
57 external: 'none',
58 rss: 'none',
59 heapTotal: 'none',
60 heapUsed: shortToLong[parsed[2]]
61 },
62 delay: shortToLong[parsed[3]],
63 handles: shortToLong[parsed[4]]
64 }
65 const expected = parsed[5]
66
67 t.strictEqual(issueCategory(issues), expected, testQuery)
68 }
69
70 t.end()
71})