@reporters/slow 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/index.js +47 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@reporters/slow)  [](https://codecov.io/gh/MoLow/reporters)
|
|
2
|
+
|
|
3
|
+
# Slow tests Reporter
|
|
4
|
+
A Slow tests reporter for `node:test`.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install --save-dev @reporters/slow
|
|
10
|
+
```
|
|
11
|
+
or
|
|
12
|
+
```bash
|
|
13
|
+
yarn add --dev @reporters/slow
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
node --test --test-reporter=@reporters/slow
|
|
20
|
+
```
|
|
21
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable camelcase */
|
|
4
|
+
/* eslint-disable no-continue */
|
|
5
|
+
const ms = require('ms');
|
|
6
|
+
|
|
7
|
+
const GRAY = '\x1b[38;5;8m';
|
|
8
|
+
const CLEAR = '\x1b[0m';
|
|
9
|
+
const THRESHOLDS = [
|
|
10
|
+
[250, CLEAR],
|
|
11
|
+
[600, '\x1b[33m'],
|
|
12
|
+
[900, '\x1b[38;5;215m'],
|
|
13
|
+
[Infinity, '\x1b[31m'],
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const COLORED_CWD = `${GRAY}${process.cwd()}${CLEAR}`;
|
|
17
|
+
|
|
18
|
+
module.exports = async function* slowTestsReporter(source) {
|
|
19
|
+
const files = new Map();
|
|
20
|
+
for await (const event of source) {
|
|
21
|
+
if (event.type !== 'test:pass' && event.type !== 'test:fail') continue;
|
|
22
|
+
const {
|
|
23
|
+
data: {
|
|
24
|
+
details: { type, duration_ms }, name, file, column, line,
|
|
25
|
+
},
|
|
26
|
+
} = event;
|
|
27
|
+
if (duration_ms < THRESHOLDS[0][0] || type === 'suite') continue;
|
|
28
|
+
const slowTests = files.get(file) || [];
|
|
29
|
+
slowTests.push({
|
|
30
|
+
duration_ms, name, file, column, line,
|
|
31
|
+
});
|
|
32
|
+
files.set(file, slowTests);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (const [file, slowTests] of files) {
|
|
36
|
+
const colord_file = file.replace(process.cwd(), COLORED_CWD);
|
|
37
|
+
yield `file: ${colord_file} has slow tests:\n`;
|
|
38
|
+
slowTests.sort((a, b) => b.duration_ms - a.duration_ms);
|
|
39
|
+
for (const {
|
|
40
|
+
duration_ms, name, column, line,
|
|
41
|
+
} of slowTests) {
|
|
42
|
+
const [, color] = THRESHOLDS
|
|
43
|
+
.find(([threshold]) => duration_ms < threshold) || THRESHOLDS[THRESHOLDS.length - 1];
|
|
44
|
+
yield ` ${color}-${CLEAR} ${name} [${color}${ms(duration_ms)}${CLEAR}] (${CLEAR}${colord_file}:${line}:${column})\n`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reporters/slow",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A slow tests reporter for `node:test`",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"node:test",
|
|
8
|
+
"test",
|
|
9
|
+
"reporter",
|
|
10
|
+
"reporters"
|
|
11
|
+
],
|
|
12
|
+
"files": [
|
|
13
|
+
"./index.js"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=../github/index.js --test-reporter-destination=stdout --test"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/MoLow/reporters/issues"
|
|
20
|
+
},
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"homepage": "https://github.com/MoLow/reporters/tree/main/packages/slow",
|
|
23
|
+
"repository": "https://github.com/MoLow/reporters.git",
|
|
24
|
+
"author": "Moshe Atlow",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"ms": "^2.1.3"
|
|
28
|
+
}
|
|
29
|
+
}
|