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 May 7, 2021
1 parent 08b3cf7 commit 0352868
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 47 deletions.
4 changes: 0 additions & 4 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
10 changes: 5 additions & 5 deletions api.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
/* eslint-env browser */
const {isDeepStrictEqual} = require('util');
const puppeteer = require('puppeteer');
const Observable = require('zen-observable');
const equals = require('deep-equal'); // TODO: Use `util.isDeepStrictEqual` when targeting Node.js 10
const delay = require('delay');

async function init(browser, page, observer, options) {
let prevResult;
let previousResult;

/* eslint-disable no-constant-condition, no-await-in-loop */
while (true) {
Expand All @@ -24,7 +24,7 @@ async function init(browser, page, observer, options) {
};
});

if (result.downloadSpeed > 0 && !equals(result, prevResult)) {
if (result.downloadSpeed > 0 && !isDeepStrictEqual(result, previousResult)) {
observer.next(result);
}

Expand All @@ -34,7 +34,7 @@ async function init(browser, page, observer, options) {
return;
}

prevResult = result;
previousResult = result;

await delay(100);
}
Expand All @@ -49,6 +49,6 @@ module.exports = options => (
const page = await browser.newPage();
await page.goto('https://fast.com');
await init(browser, page, observer, options);
})().catch(observer.error.bind(observer));
})().catch(observer.error.bind(observer)); // eslint-disable-line promise/prefer-await-to-then
})
);
2 changes: 2 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const importJsx = require('import-jsx');
const React = require('react');
const {render} = require('ink');

// Note to self: This cannot be ESM until https://github.com/vadimdemedes/import-jsx/issues/15 is fixed.

const ui = importJsx('./ui');

const cli = meow(`
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
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Test your download and upload speed using fast.com",
"license": "MIT",
"repository": "sindresorhus/fast-cli",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
Expand All @@ -13,7 +14,7 @@
"fast": "cli.js"
},
"engines": {
"node": ">=8"
"node": ">=12.20"
},
"scripts": {
"test": "xo && ava"
Expand Down Expand Up @@ -43,23 +44,23 @@
"mbps"
],
"dependencies": {
"deep-equal": "^1.0.1",
"delay": "^4.1.0",
"delay": "^5.0.0",
"import-jsx": "^4.0.0",
"ink": "^3.0.8",
"ink-spinner": "^4.0.1",
"meow": "^5.0.0",
"puppeteer": "^1.12.1",
"react": "^17.0.1",
"zen-observable": "^0.8.13"
"ink-spinner": "^4.0.2",
"meow": "^9.0.0",
"puppeteer": "^9.1.1",
"react": "^16.8.0",
"zen-observable": "^0.8.15"
},
"devDependencies": {
"ava": "^1.2.1",
"eslint-config-xo-react": "^0.23.0",
"eslint-plugin-react": "^7.21.5",
"ava": "^2.4.0",
"eslint-config-xo-react": "^0.25.0",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"execa": "^1.0.0",
"xo": "^0.24.0"
"execa": "^5.0.0",
"p-event": "^4.2.0",
"xo": "^0.39.1"
},
"xo": {
"extends": [
Expand Down
17 changes: 6 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import childProcess from 'child_process';
import execa from 'execa';
import pEvent from 'p-event';
import test from 'ava';

test.cb('default', t => {
// TODO: Use `execa` here when the `spawn` API is done
const cp = childProcess.spawn('./cli.js', {stdio: 'inherit'});

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

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

test('non-tty', async t => {
t.regex(await execa.stdout('./cli.js'), /^\d+(?:\.\d+)? \w+$/i);
const {stdout} = await execa('./cli.js');
t.regex(stdout, /\d+(?:\.\d+)? \w+/i);
});
22 changes: 12 additions & 10 deletions ui.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';
const dns = require('dns');
const {promises: dns} = require('dns');
const React = require('react');
const {useState, useEffect} = require('react');
const {Box, Text, Newline, useApp} = require('ink');
const Spinner = require('ink-spinner').default;

const api = require('./api');
const api = require('./api.js');

const FixedSpacer = ({size}) => (
<>{' '.repeat(size)}</>
Expand Down Expand Up @@ -82,8 +81,10 @@ const Fast = ({singleLine, upload}) => {
const {exit} = useApp();

useEffect(() => {
dns.lookup('fast.com', error => {
if (error) {
(async () => {
try {
await dns.lookup('fast.com');
} catch (error) {
setError(error.code === 'ENOTFOUND' ?
'Please check your internet connection' :
`Something happened ${JSON.stringify(error)}`
Expand All @@ -92,14 +93,15 @@ const Fast = ({singleLine, upload}) => {
return;
}

// eslint-disable-next-line unicorn/no-array-for-each
api({measureUpload: upload}).forEach(result => {
setData(result);
}).catch(error2 => {
setError(error2.message);
}).catch(error_ => { // eslint-disable-line promise/prefer-await-to-then
setError(error_.message);
exit();
});
});
}, []);
})();
}, [exit, upload]);

useEffect(() => {
if (data.isDone || (!upload && data.uploadSpeed)) {
Expand Down Expand Up @@ -129,7 +131,7 @@ const Fast = ({singleLine, upload}) => {
</>
)}
{isDone && <Text><FixedSpacer size={4}/></Text>}
{Object.keys(data).length !== 0 && <Speed upload={upload} data={data}/>}
{Object.keys(data).length > 0 && <Speed upload={upload} data={data}/>}
</Box>
<Spacer singleLine={singleLine}/>
</>
Expand Down

0 comments on commit 0352868

Please sign in to comment.