10000 chore: Updated dependencies, code and tools. · ShogunPanda/cronometro@e6813e5 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit e6813e5

Browse files
committed
chore: Updated dependencies, code and tools.
1 parent adbd688 commit e6813e5

20 files changed

+109
-75
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ jobs:
66
runs-on: ubuntu-latest
77
steps:
88
- name: Checkout
9-
uses: actions/checkout@v1
9+
uses: actions/checkout@v2
1010
- name: Use Node.js LTS
11-
uses: actions/setup-node@v1
11+
uses: actions/setup-node@v2
1212
with:
1313
node-version: 12.x
1414
- name: Restore cached dependencies
15-
uses: actions/cache@v1
15+
uses: actions/cache@v2
1616
with:
1717
path: node_modules
1818
key: node-modules-${{ hashFiles('package.json') }}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Package Version](https://img.shields.io/npm/v/cronometro.svg)](https://npm.im/cronometro)
44
[![Dependency Status](https://img.shields.io/david/ShogunPanda/cronometro)](https://david-dm.org/ShogunPanda/cronometro)
55
[![Build](https://github.com/ShogunPanda/cronometro/workflows/CI/badge.svg)](https://github.com/ShogunPanda/cronometro/actions?query=workflow%3ACI)
6-
[![Code Coverage](https://img.shields.io/codecov/c/gh/ShogunPanda/cronometro?token=d0ae1643f35c4c4f9714a357f796d05d)](https://codecov.io/gh/ShogunPanda/cronometro)
6+
[![Code Coverage](https://img.shields.io/codecov/c/gh/ShogunPanda/cronometro?token=LhUiSgWHoI)](https://codecov.io/gh/ShogunPanda/cronometro)
77

88
Simple benchmarking suite powered by HDR histograms.
99

@@ -129,7 +129,7 @@ const subject = '123123123123123123123123123123123123123123123123'
129129
const results = cronometro(
130130
{
131131
single() {
132-
subject.replace(pattern, (m) => replacements[m])
132+
subject.replace(pattern, m => replacements[m])
133133
},
134134
multiple() {
135135
subject.replace(/1/g, 'a').replace(/2/g, 'b').replace(/3/g, 'c')

lib/index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
'use strict';
2-
function __export(m) {
3-
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4-
}
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5+
}) : (function(o, m, k, k2) {
6+
if (k2 === undefined) k2 = k;
7+
o[k2] = m[k];
8+
}));
9+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
10+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11+
};
512
Object.defineProperty(exports, "__esModule", { value: true });
13+
exports.cronometro = void 0;
614
const path_1 = require("path");
715
const worker_threads_1 = require("worker_threads");
816
const models_1 = require("./models");
917
const print_1 = require("./print");
10-
__export(require("./models"));
18+
__exportStar(require("./models"), exports);
1119
function scheduleNextTest(context) {
1220
// We still have work to do
1321
if (context.current < context.tests.length) {
@@ -56,7 +64,9 @@ function run(context) {
5664
scheduleNextTest(context);
5765
});
5866
}
59-
function cronometro(tests, options, cb) {
67+
function cronometro(tests, options, cb
68+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
69+
) {
6070
/* istanbul ignore next */
6171
if (!worker_threads_1.isMainThread) {
6272
worker_threads_1.workerData.tests = Object.entries(tests);

lib/models.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.percentiles = exports.defaultOptions = void 0;
34
exports.defaultOptions = {
45
iterations: 1e4,
56
warmup: true,

lib/print.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.printResults = exports.setLogger = void 0;
34
const acquerello_1 = require("acquerello");
45
const table_1 = require("table");
56
const styles = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray'];

lib/runner.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if (worker_threads_1.isMainThread) {
99
if (worker_threads_1.workerData.path.endsWith('.ts')) {
1010
const instance = Symbol.for('ts-node.register.instance');
1111
if (!(instance in process)) {
12+
// eslint-disable-next-line @typescript-eslint/no-var-requires
1213
require('ts-node').register({ project: process.env.TS_NODE_PROJECT });
1314
}
1415
}

lib/worker.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.runWorker = void 0;
34
const hdr_histogram_js_1 = require("hdr-histogram-js");
45
const models_1 = require("./models");
56
/* istanbul ignore next */
@@ -38,21 +39,21 @@ function handleTestIteration(context, error) {
3839
const completedPercentage = Math.floor((executed / total) * 10000);
3940
// Check if abort the test earlier. It is checked every 5% after 10% of the iterations
4041
if (completedPercentage >= 1000 && completedPercentage % 500 === 0) {
41-
const standardErrorPercentage = histogram.getStdDeviation() / Math.sqrt(executed) / histogram.getMean();
42+
const standardErrorPercentage = histogram.stdDeviation / Math.sqrt(executed) / histogram.mean;
4243
if (standardErrorPercentage < errorThreshold) {
4344
stop = true;
4445
}
4546
}
4647
}
4748
// If the test is over
4849
if (stop || executed > total) {
49-
const stdDev = histogram.getStdDeviation();
50+
const stdDev = histogram.stdDeviation;
5051
return context.callback({
5152
success: true,
5253
size: executed,
5354
min: histogram.minNonZeroValue,
5455
max: histogram.maxValue,
55-
mean: histogram.getMean(),
56+
mean: histogram.mean,
5657
stddev: stdDev,
5758
percentiles: models_1.percentiles.reduce((accu, percentile) => {
5859
accu[percentile] = histogram.getValueAtPercentile(percentile);

package.json

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,30 @@
2626
"types": "types/index.d.ts",
2727
"scripts": {
2828
"lint": "eslint src/*.ts test/*.ts",
29-
"ci": "yarn lint && tap --timeout=60 --no-color --reporter=spec --coverage-report=json --coverage-report=text --branches 90 --functions 90 --lines 90 --statements 90 test/*.spec.ts",
30-
"test": "tap --timeout=60 --reporter=spec --coverage-report=html --coverage-report=text --no-browser test/*.spec.ts",
29+
"test": "tap --reporter=spec --coverage-report=html --coverage-report=text --no-browser test/*.test.ts",
30+
"test:ci": "tap --no-color --reporter=spec --coverage-report=json --coverage-report=text --branches 90 --functions 90 --lines 90 --statements 90 test/*.test.ts",
31+
"ci": "yarn lint && yarn test:ci",
3132
"prebuild": "rm -rf lib/* types/* && yarn lint",
3233
"build": "tsc -p .",
3334
"prepublishOnly": "yarn ci",
3435
"postpublish": "git push origin && git push origin -f --tags"
3536
},
3637
"dependencies": {
3738
"acquerello": "^0.1.2",
38-
"hdr-histogram-js": "^1.2.0",
39-
"table": "^5.4.6"
39+
"hdr-histogram-js": "^2.0.1",
40+
"table": "^6.0.6"
4041
},
4142
"devDependencies": {
42-
"@cowtech/eslint-config": "^6.8.5",
43-
"@types/node": "^13.13.1",
44-
"@types/sinon": "^9.0.0",
45-
"@types/table": "^5.0.0",
46-
"prettier": "^2.0.4",
43+
"@cowtech/eslint-config": "^7.10.1",
44+
"@types/node": "^14.14.19",
45+
"@types/sinon": "^9.0.10",
46+
"@types/table": "^6.0.0",
47+
"@types/tap": "^14.10.1",
48+
"prettier": "^2.2.1",
4749
"proxyquire": "^2.1.3",
48-
"sinon": "^9.0.2",
49-
"tap": "^14.10.7",
50-
"typescript": "^3.7.5"
51-
},
52-
"peerDependencies": {
53-
"ts-node": "^8.9.0",
54-
"typescript": "^3.8.3"
50+
"sinon": "^9.2.2",
51+
"tap": "^14.11.0",
52+
"typescript": "^4.1.3"
5553
},
5654
"engines": {
5755
"node": ">=12.15.0"

prettier.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ module.exports = {
33
semi: false,
44
singleQuote: true,
55
bracketSpacing: true,
6-
trailingComma: 'none'
6+
trailingComma: 'none',
7+
arrowParens: 'avoid'
78
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function run(context: Context): void {
6969
})
7070
}
7171

72+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
7273
export function cronometro(tests: Tests): Promise<Results> | void
7374
export function cronometro(tests: Tests, options: Partial<Options>): Promise<Results>
7475
export function cronometro(tests: Tests, options: Partial<Options>, cb: Callback): undefined
@@ -77,6 +78,7 @@ export function cronometro(
7778
tests: Tests,
7879
options?: Partial<Options> | Callback,
7980
cb?: Callback
81+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
8082
): Promise<Results> | void {
8183
/* istanbul ignore next */
8284
if (!isMainThread) {

src/models.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { AbstractHistogram } from 'hdr-histogram-js'
1+
import { Histogram } from 'hdr-histogram-js'
22

33
export interface PrintOptions {
44
colors?: boolean
55
compare?: boolean
66
compareMode?: 'base' | 'previous'
77
}
88

9+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
910
export type SetupFunction = (cb: (err?: Error | null) => void) => Promise<any> | void
1011

1112
export interface Options {
@@ -79,11 +80,11 @@ export interface TestContext {
7980
errorThreshold: number
8081
total: number
8182
executed: number
82-
histogram: AbstractHistogram
83+
histogram: Histogram
8384
start: bigint
84-
handler(error?: Error | null): void
85-
notifier(value: any): void
86-
callback(result: Result): void
85+
handler: (error?: Error | null) => void
86+
notifier: (value: any) => void
87+
callback: (result: Result) => void
8788
}
8889

8990
export const defaultOptions = {

src/runner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ if (workerData.path.endsWith('.ts')) {
1010
const instance = Symbol.for('ts-node.register.instance')
1111

1212
if (!(instance in process)) {
13+
// eslint-disable-next-line @typescript-eslint/no-var-requires
1314
require('ts-node').register({ project: process.env.TS_NODE_PROJECT })
1415
}
1516
}

src/worker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function handleTestIteration(context: TestContext, error?: Error | null): void {
4545

4646
// Check if abort the test earlier. It is checked every 5% after 10% of the iterations
4747
if (completedPercentage >= 1000 && completedPercentage % 500 === 0) {
48-
const standardErrorPercentage = histogram.getStdDeviation() / Math.sqrt(executed) / histogram.getMean()
48+
const standardErrorPercentage = histogram.stdDeviation / Math.sqrt(executed) / histogram.mean
4949

5050
if (standardErrorPercentage < errorThreshold) {
5151
stop = true
@@ -55,14 +55,14 @@ function handleTestIteration(context: TestContext, error?: Error | null): void {
5555

5656
// If the test is over
5757
if (stop || executed > total) {
58-
const stdDev = histogram.getStdDeviation()
58+
const stdDev = histogram.stdDeviation
5959

6060
return context.callback({
6161
success: true,
6262
size: executed,
6363
min: histogram.minNonZeroValue,
6464
max: histogram.maxValue,
65-
mean: histogram.getMean(),
65+
mean: histogram.mean,
6666
stddev: stdDev,
6767
percentiles: percentiles.reduce((accu: Percentiles, percentile: number) => {
6868
accu[percentile] = histogram.getValueAtPercentile(percentile)

test/errorHandling.spec.ts renamed to test/errorHandling.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
// @ts-ignore
1+
/* eslint-disable @typescript-eslint/no-floating-promises */
2+
23
import t from 'tap'
34
import { isMainThread } from 'worker_threads'
45
import { cronometro, percentiles } from '../src'
56

7+
type Test = typeof t
8+
69
if (!isMainThread) {
710
cronometro(
811
{
@@ -20,7 +23,7 @@ if (!isMainThread) {
2023
() => false
2124
)
2225
} else {
23-
t.test('Errored tests handling', async (t: any) => {
26+
t.test('Errored tests handling', async (t: Test) => {
2427
const results = await cronometro(
2528
{
2629
single() {

test/optionsValidation.spec.ts renamed to test/optionsValidation.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
// @ts-ignore
1+
/* eslint-disable @typescript-eslint/no-floating-promises */
2+
23
import t from 'tap'
34
import { cronometro } from '../src'
45

5-
t.test('Options validation', async (t: any) => {
6+
type Test = typeof t
7+
8+
t.test('Options validation', async (t: Test) => {
69
await t.rejects(
710
() =>
811
cronometro(
@@ -17,7 +20,7 @@ t.test('Options validation', async (t: any) => {
1720
},
1821
{ iterations: -1 }
1922
),
20-
{ message: 'The iterations option must be a positive number.' }
23+
new Error('The iterations option must be a positive number.')
2124
)
2225

2326
cronometro(

test/print.spec.ts renamed to test/print.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
/* eslint-disable @typescript-eslint/no-floating-promises */
2+
13
import { spy } from 'sinon'
2-
// @ts-ignore
34
import t from 'tap'
45
import { isMainThread } from 'worker_threads'
56
import { cronometro, defaultOptions, percentiles, Results } from '../src'
67
import { setLogger } from '../src/print'
78

9+
type Test = typeof t
10+
811
function removeStyle(source: string): string {
912
// eslint-disable-next-line no-control-regex
1013
return source.replace(/\x1b\[\d+m/g, '')
@@ -35,7 +38,7 @@ if (!isMainThread) {
3538
done()
3639
})
3740

38-
t.test('Printing - Default options', (t: any) => {
41+
t.test('Printing - Default options', (t: Test) => {
3942
cronometro(
4043
{
4144
single() {
@@ -89,7 +92,7 @@ if (!isMainThread) {
8992
)
9093
})
9194

92-
t.test('Printing - No colors', (t: any) => {
95+
t.test('Printing - No colors', (t: Test) => {
9396
cronometro(
9497
{
9598
single() {
@@ -116,7 +119,7 @@ if (!isMainThread) {
116119
)
117120
})
118121

119-
t.test('Printing - Base compare', (t: any) => {
122+
t.test('Printing - Base compare', (t: Test) => {
120123
cronometro(
121124
{
122125
single() {
@@ -147,7 +150,7 @@ if (!isMainThread) {
147150
)
148151
})
149152

150-
t.test('Printi E732 ng - Previous compare', (t: any) => {
153+
t.test('Printing - Previous compare', (t: Test) => {
151154
cronometro(
152155
{
153156
single() {

test/success.spec.ts renamed to test/success.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
// @ts-ignore
1+
/* eslint-disable @typescript-eslint/no-floating-promises */
2+
23
import t from 'tap'
34
import { isMainThread } from 'worker_threads'
45
import { cronometro, percentiles } from '../src'
56

7+
type Test = typeof t
8+
69
if (!isMainThread) {
710
cronometro(
811
{
@@ -17,7 +20,7 @@ if (!isMainThread) {
1720
() => false
1821
)
1922
} else {
20-
t.test('Collecting results', async (t: any) => {
23+
t.only('Collecting results', async (t: Test) => {
2124
const results = await cronometro(
2225
{
2326
single() {

0 commit comments

Comments
 (0)
0