Skip to content

Commit

Permalink
Merge pull request #14 from homer0/homer0_update
Browse files Browse the repository at this point in the history
Update project
  • Loading branch information
homer0 committed Oct 22, 2022
2 parents a1087ae + 1d5c510 commit 2d93ec8
Show file tree
Hide file tree
Showing 23 changed files with 2,833 additions and 3,299 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -2,3 +2,4 @@
coverage/*
node_modules/*
docs/*
esm.js
40 changes: 40 additions & 0 deletions .github/workflows/results.yml
@@ -0,0 +1,40 @@
name: Write results file

on:
push:
branches:
- main

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# pulls all commits (needed for lerna / semantic release to correctly version)
fetch-depth: "0"
- name: Read .nvmrc
run: echo "::set-output name=NVMRC::$(cat .nvmrc)"
id: nvm
- uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- name: Install dependencies
env:
HUSKY_SKIP_INSTALL: 1
run: yarn --frozen-lockfile
- run: yarn results
- name: Configure Git User
run: |
git config --global user.name '@homer0'
git config --global user.email 'homer0@users.noreply.github.com'
- name: Commit results
run: |
git add RESULTS.md
git commit -m "publish: update results [skip ci]"
- name: Push results
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '12', '14' ]
node: [ '16', '18' ]
name: Run jest and ESLint (Node ${{ matrix.node }})
steps:
- uses: actions/checkout@v2
Expand All @@ -18,7 +18,7 @@ jobs:
- run: yarn lint:all
- run: yarn test
- name: Coveralls
if: ${{ matrix.node == '12' }}
if: ${{ matrix.node == '16' }}
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .jestrc.js
Expand Up @@ -3,6 +3,6 @@ module.exports = {
collectCoverage: true,
testPathIgnorePatterns: ['/node_modules/', '/utils/scripts/'],
unmockedModulePathPatterns: ['/node_modules/', 'mocks/'],
coveragePathIgnorePatterns: ['mocks/'],
coveragePathIgnorePatterns: ['mocks/', 'esm.js'],
testEnvironment: 'node',
};
2 changes: 1 addition & 1 deletion .nvmrc
@@ -1 +1 @@
12
16
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
# HTTP Speed Meter

[![Build Status](https://travis-ci.org/homer0/http-speed-meter.svg?branch=master)](https://travis-ci.org/homer0/http-speed-meter) [![Coverage Status](https://coveralls.io/repos/homer0/http-speed-meter/badge.svg?branch=master&service=github)](https://coveralls.io/github/homer0/http-speed-meter?branch=master) [![Dependencies status](https://david-dm.org/homer0/http-speed-meter.svg)](https://david-dm.org/homer0/http-speed-meter) [![Dev dependencies status](https://david-dm.org/homer0/http-speed-meter/dev-status.svg)](https://david-dm.org/homer0/http-speed-meter#info=devDependencies)
[![GitHub Workflow Status (main)](https://img.shields.io/github/workflow/status/homer0/http-speed-meter/Test/main?style=flat-square)](https://github.com/homer0/http-speed-meter/actions?query=workflow%3ATest) [![Coverage Status](https://coveralls.io/repos/homer0/http-speed-meter/badge.svg?branch=master&service=github)](https://coveralls.io/github/homer0/http-speed-meter?branch=master)

This is very simple, I wanted to know which was the fastest HTTP client for Javascript. I went to Google and searched for something like _"Compare HTTP clients for Javascript"_ and I found [this page](https://npmcompare.com/compare/axios,got,request,reqwest,superagent). Pretty useful information about the projects, but nothing on performance and/or speed, but I took the list of _competitors_ and bookmarked it to get back later, after I run my tests.

Expand Down Expand Up @@ -89,4 +89,4 @@ First of all, install all the dependencies (if you haven't done it yet) and run
- **If you want to add a new test:** Create a new file on `/src/tests` and follow the example of the other tests: The `test` and `testJSON` methods, the name getter and `.run()` your file at the end of the file. Don't forget to add the dependency on the `package.json`!.
- **If you want to modify the output/reporter:** There's an NPM task called `mock`, good to the `package.json` and take a look. It starts the process but with mocked results, so you don't have to make real requests while changing rainbow of output you are writing.

Finally, and I didn't mentioned earlier because the hooks are there for a reason, you have the `npm run link` and `npm test` for the linting and the unit tests.
Finally, and I didn't mentioned earlier because the hooks are there for a reason, you have the `npm run link` and `npm test` for the linting and the unit tests.
29 changes: 29 additions & 0 deletions RESULTS.md
@@ -0,0 +1,29 @@
# Latest results

```
HTTP Speed Meter - Average Results
Target URL: https://pokeapi.co/api/v2/pokemon/lugia
Iterations: 1
Test: JSON
axios@1.1.3 ████████████████████████████████████████████ 497ms
got@12.5.2 ████████████████████████████████████████████ 509ms
node-fetch@3.2.10 ████████████████████████████████████████████ 506ms
request@2.88.2 ████████████████████████████████████████████████████████████████████████████████ 900ms
request-promise@4.2.6 ██████████████████████████████████████████████████████████████████ 751ms
reqwest@2.0.5 ████████████████████████████████████████████████████████ 630ms
superagent@8.0.2 ████████████████████████████████████████████ 498ms
Test: Text
axios@1.1.3 ████████████████████████████████████████████ 504ms
got@12.5.2 ████████████████████████████████████████████ 508ms
node-fetch@3.2.10 ████████████████████████████████████████████ 511ms
request@2.88.2 ███████████████████████████████████████████████████████████████ 711ms
request-promise@4.2.6 █████████████████████████████████████████████████████████████████████████████ 881ms
reqwest@2.0.5 ███████████████████████████████████████████████████████████ 669ms
superagent@8.0.2 ████████████████████████████████████████████ 502ms
```
45 changes: 23 additions & 22 deletions package.json
Expand Up @@ -12,41 +12,41 @@
"meter"
],
"dependencies": {
"chalk": "^4.1.0",
"yargs": "^16.2.0",
"shelljs": "0.8.4",
"pretty-ms": "^7.0.1",
"chalk": "^5.1.2",
"yargs": "^17.6.0",
"shelljs": "0.8.5",
"pretty-ms": "^8.0.0",
"cli-spinner": "0.2.10",

"request": "2.88.2",
"request-promise": "4.2.6",
"node-fetch": "2.6.1",
"axios": "0.21.1",
"got": "11.8.2",
"superagent": "6.1.0",
"node-fetch": "3.2.10",
"axios": "1.1.3",
"got": "12.5.2",
"superagent": "8.0.2",

"reqwest": "2.0.5",
"xhr2": "0.2.1"
},
"devDependencies": {
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@homer0/eslint-plugin": "^7.0.0",
"@homer0/prettier-config": "^1.1.1",
"@homer0/prettier-plugin-jsdoc": "^4.0.0",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@homer0/eslint-plugin": "^9.1.3",
"@homer0/prettier-config": "^1.1.2",
"@homer0/prettier-plugin-jsdoc": "^5.1.5",
"docdash": "homer0/docdash#semver:^2.1.0",
"eslint": "^7.24.0",
"husky": "^6.0.0",
"is-ci": "^3.0.0",
"jest": "^26.6.3",
"jsdoc": "^3.6.6",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"eslint": "^8.26.0",
"husky": "^8.0.1",
"is-ci": "^3.0.1",
"jest": "^29.2.1",
"jsdoc": "^3.6.11",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"yarn-or-npm": "^3.0.1"
},
"engine-strict": true,
"engines": {
"node": ">=12.0.0"
"node": ">=16.0.0"
},
"main": "src/index.js",
"lint-staged": {
Expand All @@ -66,6 +66,7 @@
"test": "./utils/scripts/test",
"lint": "./utils/scripts/lint",
"lint:all": "./utils/scripts/lint-all",
"docs": "./utils/scripts/docs"
"docs": "./utils/scripts/docs",
"results": "./utils/scripts/write-results"
}
}
2 changes: 2 additions & 0 deletions src/index.js
@@ -1,7 +1,9 @@
const HsmTester = require('./lib/hsmTester');
const HsmTest = require('./lib/hsmTest');
const { getLib } = require('./lib/esm');

module.exports = {
HsmTester,
HsmTest,
getLib,
};
11 changes: 11 additions & 0 deletions src/lib/esm.js
@@ -0,0 +1,11 @@
module.exports.LIBS = ['pretty-ms', 'chalk', 'node-fetch', 'got'];
const libsModules = {};

module.exports.loadESMLibs = () =>
Promise.all(
module.exports.LIBS.map(async (lib) => {
libsModules[lib] = await import(lib);
}),
);

module.exports.getLib = (lib) => libsModules[lib];
20 changes: 12 additions & 8 deletions src/lib/hsmTest.js
@@ -1,5 +1,6 @@
/* eslint-disable no-console */
const { argv } = require('yargs');
const { loadESMLibs } = require('./esm');

// eslint-disable-next-line no-process-env
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
Expand Down Expand Up @@ -47,14 +48,17 @@ class HsmTest {
* to log the error message.
*/
run() {
return Promise.all([this._runTest(this.test), this._runTest(this.testJSON)])
.then(([raw, json]) =>
console.log(
JSON.stringify({
test: this.name,
raw,
json,
}),
return loadESMLibs()
.then(() =>
Promise.all([this._runTest(this.test), this._runTest(this.testJSON)]).then(
([raw, json]) =>
console.log(
JSON.stringify({
test: this.name,
raw,
json,
}),
),
),
)
.catch((error) => {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/hsmTester.js
@@ -1,10 +1,9 @@
const path = require('path');
const fs = require('fs');
const shell = require('shelljs');
const prettyMs = require('pretty-ms');
const chalk = require('chalk');
const { Spinner } = require('cli-spinner');
const { dependencies } = require('../../package.json');
const { getLib } = require('./esm');

const DEFAULT_MAX_COLUMN = 80;
/**
Expand Down Expand Up @@ -278,6 +277,7 @@ class HsmTester {
const total = 100;
const percentage = Math.floor((value * total) / highest);
const width = Math.floor((this.maxColumns / total) * percentage);
const prettyMs = getLib('pretty-ms').default;
return {
width,
title: this.normalizedNames[name],
Expand Down Expand Up @@ -344,6 +344,7 @@ class HsmTester {
* @ignore
*/
_output(results) {
const chalk = getLib('chalk').default;
// Let's sort the tests name.
const testNames = Object.keys(results).sort();
// Because `\t` takes too much space :P.
Expand Down Expand Up @@ -443,6 +444,7 @@ class HsmTester {
);
}

const chalk = getLib('chalk').default;
// Turn on the spinner.
const spinner = new Spinner({
text: 'Making the requests %s',
Expand Down
13 changes: 8 additions & 5 deletions src/start.js
@@ -1,14 +1,17 @@
const { argv } = require('yargs');
const { loadESMLibs } = require('./lib/esm');
const { HsmTester } = require('.');

const defaultURL = 'https://pokeapi.co/api/v2/pokemon/lugia';
const targetURL = argv.url || defaultURL;

new HsmTester(targetURL, './src/tests', {
iterations: argv.iterations ? Number(argv.iterations) : 1,
mock: argv.mock,
})
.run(argv.test || '')
loadESMLibs()
.then(() =>
new HsmTester(targetURL, './src/tests', {
iterations: argv.iterations ? Number(argv.iterations) : 1,
mock: argv.mock,
}).run(argv.test || ''),
)
.then((tester) => tester.showResults())
.catch((error) => {
// eslint-disable-next-line no-console
Expand Down
5 changes: 3 additions & 2 deletions src/tests/got.js
@@ -1,9 +1,9 @@
const got = require('got');
const { HsmTest } = require('..');
const { HsmTest, getLib } = require('..');

class GotTest extends HsmTest {
test(start, finish, reject) {
start();
const got = getLib('got').default;
got(this.url, {
headers: {
'User-Agent': this.userAgent,
Expand All @@ -15,6 +15,7 @@ class GotTest extends HsmTest {

testJSON(start, finish, reject) {
start();
const got = getLib('got').default;
got(this.url, {
responseType: 'json',
headers: {
Expand Down
5 changes: 3 additions & 2 deletions src/tests/nodeFetch.js
@@ -1,9 +1,9 @@
const fetch = require('node-fetch');
const { HsmTest } = require('..');
const { HsmTest, getLib } = require('..');

class NodeFetchTest extends HsmTest {
test(start, finish, reject) {
start();
const fetch = getLib('node-fetch').default;
fetch(this.url, {
headers: {
'User-Agent': this.userAgent,
Expand All @@ -16,6 +16,7 @@ class NodeFetchTest extends HsmTest {

testJSON(start, finish, reject) {
start();
const fetch = getLib('node-fetch').default;
fetch(this.url, {
headers: {
'User-Agent': this.userAgent,
Expand Down
5 changes: 5 additions & 0 deletions tests/jsconfig.json
@@ -0,0 +1,5 @@
{
"typeAcquisition": {
"include": ["jest"]
}
}

0 comments on commit 2d93ec8

Please sign in to comment.