Skip to content

Commit

Permalink
Require Node.js 12.20
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 21, 2021
1 parent d71d8ad commit 61548ab
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 73 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
56 changes: 27 additions & 29 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env node
'use strict';
const {URL} = require('url');
const meow = require('meow');
const speedtest = require('speedtest-net');
const updateNotifier = require('update-notifier');
const roundTo = require('round-to');
const chalk = require('chalk');
const logUpdate = require('log-update');
const logSymbols = require('log-symbols');
const Ora = require('ora');
import process from 'node:process';
import {URL} from 'node:url';
import meow from 'meow';
import speedtest from 'speedtest-net';
import {roundTo} from 'round-to';
import chalk from 'chalk';
import logUpdate from 'log-update';
import logSymbols from 'log-symbols';
import Ora from 'ora';

const cli = meow(`
Usage
Expand All @@ -19,28 +18,27 @@ const cli = meow(`
--bytes -b Output the result in megabytes per second (MBps)
--verbose -v Output more detailed information
`, {
importMeta: import.meta,
flags: {
json: {
type: 'boolean',
alias: 'j'
alias: 'j',
},
bytes: {
type: 'boolean',
alias: 'b'
alias: 'b',
},
verbose: {
type: 'boolean',
alias: 'v'
}
}
alias: 'v',
},
},
});

updateNotifier({pkg: cli.pkg}).notify();

const stats = {
ping: '',
download: '',
upload: ''
upload: '',
};

let state = 'ping';
Expand Down Expand Up @@ -74,7 +72,7 @@ function render() {
'',
' Server ' + (stats.data === undefined ? '' : chalk.cyan(stats.data.server.host)),
' Location ' + (stats.data === undefined ? '' : chalk.cyan(stats.data.server.location + chalk.dim(' (' + stats.data.server.country + ')'))),
' Distance ' + (stats.data === undefined ? '' : chalk.cyan(roundTo(stats.data.server.distance, 1) + chalk.dim(' km')))
' Distance ' + (stats.data === undefined ? '' : chalk.cyan(roundTo(stats.data.server.distance, 1) + chalk.dim(' km'))),
].join('\n');
}

Expand All @@ -96,16 +94,16 @@ function map(server) {
return server;
}

const st = speedtest({maxTime: 20000});
const speedTest = speedtest({maxTime: 20_000});

if (!cli.flags.json) {
setInterval(render, 50);
}

st.once('testserver', server => {
speedTest.once('testserver', server => {
if (cli.flags.verbose) {
stats.data = {
server: map(server)
server: map(server),
};
}

Expand All @@ -114,50 +112,50 @@ st.once('testserver', server => {
stats.ping = cli.flags.json ? ping : chalk.cyan(ping + chalk.dim(' ms'));
});

st.on('downloadspeedprogress', speed => {
speedTest.on('downloadspeedprogress', speed => {
if (state === 'download' && cli.flags.json !== true) {
speed *= multiplier;
const download = roundTo(speed, speed >= 10 ? 0 : 1);
stats.download = chalk.yellow(`${download} ${chalk.dim(unit)}`);
}
});

st.on('uploadspeedprogress', speed => {
speedTest.on('uploadspeedprogress', speed => {
if (state === 'upload' && cli.flags.json !== true) {
speed *= multiplier;
const upload = roundTo(speed, speed >= 10 ? 0 : 1);
stats.upload = chalk.yellow(`${upload} ${chalk.dim(unit)}`);
}
});

st.once('downloadspeed', speed => {
speedTest.once('downloadspeed', speed => {
setState('upload');
speed *= multiplier;
const download = roundTo(speed, speed >= 10 && !cli.flags.json ? 0 : 1);
stats.download = cli.flags.json ? download : chalk.cyan(download + ' ' + chalk.dim(unit));
});

st.once('uploadspeed', speed => {
speedTest.once('uploadspeed', speed => {
setState('');
speed *= multiplier;
const upload = roundTo(speed, speed >= 10 && !cli.flags.json ? 0 : 1);
stats.upload = cli.flags.json ? upload : chalk.cyan(upload + ' ' + chalk.dim(unit));
});

st.on('data', data => {
speedTest.on('data', data => {
if (cli.flags.verbose) {
stats.data = data;
}

render();
});

st.on('done', () => {
speedTest.on('done', () => {
console.log();
process.exit();
});

st.on('error', error => {
speedTest.on('error', error => {
if (error.code === 'ENOTFOUND') {
logError('Please check your internet connection');
} else {
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
"description": "Test your internet connection speed and ping using speedtest.net from the CLI",
"license": "MIT",
"repository": "sindresorhus/speed-test",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"bin": "cli.js",
"type": "module",
"bin": "./cli.js",
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -35,18 +37,18 @@
"check"
],
"dependencies": {
"chalk": "^2.3.0",
"log-symbols": "^2.2.0",
"log-update": "^2.3.0",
"meow": "^5.0.0",
"ora": "^3.1.0",
"round-to": "^3.0.0",
"speedtest-net": "^1.2.4",
"update-notifier": "^2.3.0"
"chalk": "^4.1.2",
"log-symbols": "^5.0.0",
"log-update": "^5.0.0",
"meow": "^10.1.2",
"ora": "^6.0.1",
"round-to": "^6.0.0",
"speedtest-net": "^1.6.2"
},
"devDependencies": {
"ava": "^1.2.1",
"execa": "^1.0.0",
"xo": "^0.24.0"
"ava": "^3.15.0",
"execa": "^6.0.0",
"p-event": "^5.0.1",
"xo": "^0.46.4"
}
}
15 changes: 3 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
<img src="screenshot.gif" width="404">


## Install

Ensure you have [Node.js](https://nodejs.org) version 8+ installed. Then run the following:
Ensure you have [Node.js](https://nodejs.org) version 12+ installed. Then run the following:

```
$ npm install --global speed-test
```sh
npm install --global speed-test
```


## Usage

```
Expand All @@ -28,17 +26,10 @@ $ speed-test --help
--verbose -v Output more detailed information
```


## Links

- [Product Hunt post](https://www.producthunt.com/posts/speed-test-cli)


## Related

- [fast-cli](https://github.com/sindresorhus/fast-cli) - Test your download speed using fast.com


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
17 changes: 6 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import childProcess from 'child_process';
import childProcess from 'node:child_process';
import test from 'ava';
import execa from 'execa';
import {execa} from 'execa';
import {pEvent} from 'p-event';

test.cb('main', t => {
const cp = childProcess.spawn('./cli.js', {stdio: 'inherit'});

cp.on('error', t.fail);

cp.on('close', code => {
t.is(code, 0);
t.end();
});
test('main', async t => {
const subProcess = childProcess.spawn('./cli.js', {stdio: 'inherit'});
t.is(await pEvent(subProcess, 'close'), 0);
});

test('--json', async t => {
Expand Down

0 comments on commit 61548ab

Please sign in to comment.