summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSindre Sorhus <sindresorhus@gmail.com>2021-11-21 18:39:15 +0700
committerSindre Sorhus <sindresorhus@gmail.com>2021-11-21 18:39:15 +0700
commit61548ab0f8af53b12deda00e783d721530857fdb (patch)
treeabd746d52dc12caf0444665307b4d5ff5538fdbc
parentd71d8ada1de8a7cbf5f865bda178205575a10ab2 (diff)
Require Node.js 12.20
-rw-r--r--.github/funding.yml3
-rw-r--r--.github/workflows/main.yml5
-rwxr-xr-xcli.js56
-rw-r--r--license2
-rw-r--r--package.json30
-rw-r--r--readme.md15
-rw-r--r--test.js17
7 files changed, 55 insertions, 73 deletions
diff --git a/.github/funding.yml b/.github/funding.yml
deleted file mode 100644
index 1a630e9..0000000
--- a/.github/funding.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-github: sindresorhus
-open_collective: sindresorhus
-custom: https://sindresorhus.com/donate
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 18531b3..3b8aa86 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -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
diff --git a/cli.js b/cli.js
index b94fa97..bc38fdd 100755
--- a/cli.js
+++ b/cli.js
@@ -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
@@ -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';
@@ -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');
}
@@ -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),
};
}
@@ -114,7 +112,7 @@ 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);
@@ -122,7 +120,7 @@ st.on('downloadspeedprogress', speed => {
}
});
-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);
@@ -130,21 +128,21 @@ st.on('uploadspeedprogress', speed => {
}
});
-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;
}
@@ -152,12 +150,12 @@ st.on('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 {
diff --git a/license b/license
index e7af2f7..fa7ceba 100644
--- a/license
+++ b/license
@@ -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:
diff --git a/package.json b/package.json
index 167fed1..32512d4 100644
--- a/package.json
+++ b/package.json
@@ -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"
@@ -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"
}
}
diff --git a/readme.md b/readme.md
index bac987f..a33c7ae 100644
--- a/readme.md
+++ b/readme.md
@@ -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
```
@@ -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)
diff --git a/test.js b/test.js
index 82ad9be..44cb500 100644
--- a/test.js
+++ b/test.js
@@ -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 => {