diff --git a/.eslintrc.json b/.eslintrc.json index bd51367..9cff826 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,6 +23,9 @@ "bin/*.js" ], "rules": { + // Executable scripts are not expected to have exports + "import/no-unused-modules": "off", + // Executable scripts should have a shebang "node/shebang": "off" } diff --git a/bin/hub-ci-status.js b/bin/hub-ci-status.js index 7c811af..987f27f 100755 --- a/bin/hub-ci-status.js +++ b/bin/hub-ci-status.js @@ -4,9 +4,7 @@ * @license MIT */ -'use strict'; - -const main = require('../cli.js'); +import main from '../cli.js'; // This file was invoked directly. // Note: Could pass process.exit as callback to force immediate exit. diff --git a/cli.js b/cli.js index 180168c..1b09f7b 100644 --- a/cli.js +++ b/cli.js @@ -4,16 +4,14 @@ * @module hub-ci-status/cli.js */ -'use strict'; - -const { +import { Command, InvalidOptionArgumentError, Option, -} = require('commander'); +} from 'commander'; -const hubCiStatus = require('.'); -const getPackageJson = require('./lib/get-package-json.js'); +import getPackageJson from './lib/get-package-json.js'; +import hubCiStatus from './index.js'; // Same --color options as hub(1) const colorOptions = ['always', 'never', 'auto']; @@ -72,7 +70,7 @@ function countOption(optarg, previous) { * @returns {!Promise} Promise for exit code. Only rejected for * arguments with invalid type (or args.length < 2). */ -async function hubCiStatusMain(args, options) { +export default async function hubCiStatusMain(args, options) { if (!Array.isArray(args) || args.length < 2) { throw new TypeError('args must be an Array with at least 2 items'); } @@ -169,5 +167,3 @@ async function hubCiStatusMain(args, options) { return 1; } } - -module.exports = hubCiStatusMain; diff --git a/index.js b/index.js index 0973174..4383eb9 100644 --- a/index.js +++ b/index.js @@ -4,16 +4,14 @@ * @module hub-ci-status */ -'use strict'; - -const fetchCiStatus = require('./lib/fetch-ci-status.js'); -const { resolveCommit } = require('./lib/git-utils.js'); -const { getProjectName } = require('./lib/github-utils.js'); -const { +import fetchCiStatus from './lib/fetch-ci-status.js'; +import { resolveCommit } from './lib/git-utils.js'; +import { getProjectName } from './lib/github-utils.js'; +import { fetchCiStatusMockSymbol, getProjectNameMockSymbol, resolveCommitMockSymbol, -} = require('./lib/symbols.js'); +} from './lib/symbols.js'; // Use same "severity" as hub(1) for determining state // https://github.com/github/hub/blob/v2.14.2/commands/ci_status.go#L60-L69 @@ -164,8 +162,7 @@ function checkRunToStatus(checkRun) { * printed. 0 if the status was printed, non-zero if the status could not * be determined. */ -module.exports = -async function hubCiStatus( +export default async function hubCiStatus( rev = 'HEAD', { [fetchCiStatusMockSymbol]: fetchCiStatusMock, @@ -218,4 +215,4 @@ async function hubCiStatus( } return stateToExitCode(state); -}; +} diff --git a/lib/exec-file-out.js b/lib/exec-file-out.js index afd7b07..ccace06 100644 --- a/lib/exec-file-out.js +++ b/lib/exec-file-out.js @@ -3,9 +3,7 @@ * @license MIT */ -'use strict'; - -const { execFile } = require('child_process'); +import { execFile } from 'child_process'; /** Promisified execFile wrapper which only provides access to * stdout and fails if stderr is non-empty. @@ -19,7 +17,7 @@ const { execFile } = require('child_process'); * non-whitespace characters. * @private */ -function execFileOut(file, args, options) { +export default function execFileOut(file, args, options) { return new Promise((resolve, reject) => { const child = execFile(file, args, options, (err, stdout, stderr) => { if (err) { @@ -47,5 +45,3 @@ function execFileOut(file, args, options) { child.stdin.end(); }); } - -module.exports = execFileOut; diff --git a/lib/fetch-ci-status.js b/lib/fetch-ci-status.js index 405786c..dbe7e12 100644 --- a/lib/fetch-ci-status.js +++ b/lib/fetch-ci-status.js @@ -3,27 +3,24 @@ * @license MIT */ -'use strict'; - -const { Octokit } = require('@octokit/rest'); -const { Agent: HttpAgent } = require('http'); -const { Agent: HttpsAgent } = require('https'); -const timers = require('timers'); -const { promisify } = require('util'); - -const getPackageJson = require('./get-package-json.js'); -const retryAsync = require('./retry-async.js'); -const { +import { Octokit } from '@octokit/rest'; +import { Agent as HttpAgent } from 'http'; +import { Agent as HttpsAgent } from 'https'; +import timers from 'timers'; +import { promisify } from 'util'; + +import getPackageJson from './get-package-json.js'; +import retryAsync from './retry-async.js'; +import { HttpAgentMockSymbol, HttpsAgentMockSymbol, OctokitMockSymbol, -} = require('./symbols.js'); +} from './symbols.js'; // TODO [engine:node@>=15]: import { setTimeout } from 'timers/promises'; const setTimeoutP = promisify(timers.setTimeout); -module.exports = -async function fetchCiStatus(apiArgs, options = {}) { +export default async function fetchCiStatus(apiArgs, options = {}) { let agent; let { octokit } = options; if (octokit === undefined) { @@ -157,4 +154,4 @@ async function fetchCiStatus(apiArgs, options = {}) { agent.destroy(); } } -}; +} diff --git a/lib/get-package-json.js b/lib/get-package-json.js index 2dca941..ff2f153 100644 --- a/lib/get-package-json.js +++ b/lib/get-package-json.js @@ -7,11 +7,10 @@ // once JSON modules are supported non-experimentally: // https://github.com/nodejs/node/issues/37141 -'use strict'; - -const { readFile } = require('fs').promises; -const path = require('path'); +// TODO [engine:node@>=14]: Use readFile from 'fs/promises' +import { promises as fsPromises } from 'fs'; +const { readFile } = fsPromises; let packageJsonP; async function readJson(pathOrUrl, options) { @@ -23,11 +22,10 @@ async function readJson(pathOrUrl, options) { * * @returns {!Promise} Parsed content of package.json. */ -module.exports = -function getPackageJson() { +export default function getPackageJson() { if (!packageJsonP) { - packageJsonP = readJson(path.join(__dirname, '..', 'package.json')); + packageJsonP = readJson(new URL('../package.json', import.meta.url)); } return packageJsonP; -}; +} diff --git a/lib/git-utils.js b/lib/git-utils.js index 4dad9ad..4afbb91 100644 --- a/lib/git-utils.js +++ b/lib/git-utils.js @@ -3,10 +3,8 @@ * @license MIT */ -'use strict'; - -const { pathToFileURL } = require('url'); -const execFileOut = require('./exec-file-out.js'); +import { pathToFileURL } from 'url'; +import execFileOut from './exec-file-out.js'; /** Is this process running on Windows? * @@ -22,7 +20,6 @@ const configScopes = Object.freeze(Object.assign(Object.create(null), { system: 'system', worktree: 'worktree', })); -exports.configScopes = configScopes; function trim(str) { return String.prototype.trim.call(str); @@ -36,13 +33,13 @@ function trim(str) { * branch, not in a git repository, or another error occurs. * @private */ -exports.getBranch = function getBranch(options) { +export function getBranch(options) { return execFileOut('git', ['symbolic-ref', '-q', '--short', 'HEAD'], options) .then(trim) .catch((err) => { throw new Error(`Unable to determine current branch: ${err.message}`); }); -}; +} /** Parse output of `git config --null`. * @@ -92,7 +89,7 @@ function parseConfigOutput(configData) { * @throws Error If an error occurs when parsing the git config output. * @private */ -exports.getConfig = async function getConfig(scope, options) { +export async function getConfig(scope, options) { if (scope !== undefined && scope !== null && !configScopes[scope]) { throw new RangeError(`Invalid scope "${scope}"`); } @@ -111,7 +108,7 @@ exports.getConfig = async function getConfig(scope, options) { }, ); return parseConfigOutput(configData); -}; +} /** Is git URL a local path? * From url_is_local_not_ssh in connect.c @@ -121,10 +118,10 @@ exports.getConfig = async function getConfig(scope, options) { * local path. * @private */ -exports.gitUrlIsLocalNotSsh = function gitUrlIsLocalNotSsh(gitUrl) { +export function gitUrlIsLocalNotSsh(gitUrl) { return !/^[^/]*:/.test(gitUrl) || (isWindows && /^[A-Za-z]:/.test(gitUrl)); -}; +} /** Parses a git URL string into a URL object like {@link url.parse} with * support for git helpers, git's SCP-like URL syntax, and local file paths. @@ -135,8 +132,8 @@ exports.gitUrlIsLocalNotSsh = function gitUrlIsLocalNotSsh(gitUrl) { * @throws {TypeError} If gitUrl can not be parsed as a URL. * @private */ -exports.parseGitUrl = function parseGitUrl(gitUrl) { - if (exports.gitUrlIsLocalNotSsh(gitUrl)) { +export function parseGitUrl(gitUrl) { + if (gitUrlIsLocalNotSsh(gitUrl)) { const fileUrlObj = pathToFileURL(gitUrl); fileUrlObj.helper = undefined; return fileUrlObj; @@ -160,7 +157,7 @@ exports.parseGitUrl = function parseGitUrl(gitUrl) { const gitUrlObj = new URL(gitUrl); gitUrlObj.helper = helper; return gitUrlObj; -}; +} /** Resolve a named commit to its hash. * @@ -171,7 +168,7 @@ exports.parseGitUrl = function parseGitUrl(gitUrl) { * if commitName can not be resolved. * @private */ -exports.resolveCommit = async function resolveCommit(commitName, options) { +export async function resolveCommit(commitName, options) { try { const sha = await execFileOut( 'git', @@ -184,4 +181,4 @@ exports.resolveCommit = async function resolveCommit(commitName, options) { `Unable to resolve '${commitName}' to a commit hash: ${err.message}`; throw err; } -}; +} diff --git a/lib/github-utils.js b/lib/github-utils.js index c88dd21..dfc8925 100644 --- a/lib/github-utils.js +++ b/lib/github-utils.js @@ -3,11 +3,9 @@ * @license MIT */ -'use strict'; +import { debuglog } from 'util'; -const { debuglog } = require('util'); - -const { getBranch, getConfig, parseGitUrl } = require('./git-utils.js'); +import { getBranch, getConfig, parseGitUrl } from './git-utils.js'; const debug = debuglog('hub-ci-status'); @@ -119,8 +117,8 @@ async function tryGetBranch(options) { * @returns {!Promise>} Promise for the owner and repo name, * as Array elements, or a UnknownProjectError if they can not be determined. */ -exports.getProjectName = -async function getProjectName(options) { +// eslint-disable-next-line import/prefer-default-export +export async function getProjectName(options) { // Run getBranch() and getConfig() concurrently. const [branch, config] = await Promise.all([ tryGetBranch(options), @@ -157,4 +155,4 @@ async function getProjectName(options) { } throw new UnknownProjectError(); -}; +} diff --git a/lib/retry-async.js b/lib/retry-async.js index 82ad53a..1c6d0f5 100644 --- a/lib/retry-async.js +++ b/lib/retry-async.js @@ -3,13 +3,11 @@ * @license MIT */ -'use strict'; +import timers from 'timers'; +import { promisify } from 'util'; -const timers = require('timers'); -const { promisify } = require('util'); - -const constant = require('./retry-async/constant.js'); -const exponential = require('./retry-async/exponential.js'); +import constant from './retry-async/constant.js'; +import exponential from './retry-async/exponential.js'; // TODO [engine:node@>=15]: import { setTimeout } from 'timers/promises'; const setTimeoutP = promisify(timers.setTimeout); @@ -48,7 +46,8 @@ function defaultShouldRetry(result) { * @private * @type {RetryAsyncOptions} */ -const DEFAULT_OPTIONS = Object.freeze({ +// eslint-disable-next-line import/no-unused-modules +export const DEFAULT_OPTIONS = Object.freeze({ maxTotalMs: Infinity, minWaitMs: 4000, now: Date.now, @@ -69,8 +68,7 @@ const DEFAULT_OPTIONS = Object.freeze({ * @returns {!Promise} Promise for return value of last call to * operation. */ -module.exports = -async function retryAsync( +export default async function retryAsync( operation, { maxTotalMs = DEFAULT_OPTIONS.maxTotalMs, @@ -126,6 +124,4 @@ async function retryAsync( waitIterator.return(); } } -}; - -module.exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS; +} diff --git a/lib/retry-async/constant.js b/lib/retry-async/constant.js index 47da0e6..82fb3b3 100644 --- a/lib/retry-async/constant.js +++ b/lib/retry-async/constant.js @@ -3,8 +3,6 @@ * @license MIT */ -'use strict'; - function* generateConstant(value, count) { for (; count > 0; count -= 1) { yield value; @@ -21,8 +19,7 @@ function* generateConstant(value, count) { * @throws {TypeError} If count is not a number. * @throws {RangeError} If count is not a positive integer. */ -module.exports = -function constant(value, count = Infinity) { +export default function constant(value, count = Infinity) { if (typeof count !== 'number') { throw new TypeError('count must be a number'); } @@ -31,4 +28,4 @@ function constant(value, count = Infinity) { } return generateConstant(value, count); -}; +} diff --git a/lib/retry-async/exponential.js b/lib/retry-async/exponential.js index 0e4463c..55bb09a 100644 --- a/lib/retry-async/exponential.js +++ b/lib/retry-async/exponential.js @@ -3,8 +3,6 @@ * @license MIT */ -'use strict'; - function* generateExponential(factor, initial, maxValue, count) { let value = Math.min(initial, maxValue); for (let i = 0; i < count; i += 1) { @@ -27,8 +25,7 @@ function* generateExponential(factor, initial, maxValue, count) { * @throws {RangeError} If maxValue or count is NaN, count is negative, or * count is not an integer (or Infinity). */ -module.exports = -function exponential( +export default function exponential( factor, initial = 1, maxValue = Infinity, @@ -54,4 +51,4 @@ function exponential( } return generateExponential(factor, initial, maxValue, count); -}; +} diff --git a/lib/symbols.js b/lib/symbols.js index dfbeb00..b1211cc 100644 --- a/lib/symbols.js +++ b/lib/symbols.js @@ -10,34 +10,34 @@ * * @private */ -exports.HttpAgentMockSymbol = Symbol('HttpAgent'); +export const HttpAgentMockSymbol = Symbol('HttpAgent'); /** Symbol of mock function used in place of https.Agent for testing. * * @private */ -exports.HttpsAgentMockSymbol = Symbol('HttpsAgent'); +export const HttpsAgentMockSymbol = Symbol('HttpsAgent'); /** Symbol of mock function used in place of Octokit for testing. * * @private */ -exports.OctokitMockSymbol = Symbol('Octokit'); +export const OctokitMockSymbol = Symbol('Octokit'); /** Symbol of mock function used in place of fetchCiStatus for testing. * * @private */ -exports.fetchCiStatusMockSymbol = Symbol('fetchCiStatus'); +export const fetchCiStatusMockSymbol = Symbol('fetchCiStatus'); /** Symbol of mock function used in place of getProjectName for testing. * * @private */ -exports.getProjectNameMockSymbol = Symbol('getProjectName'); +export const getProjectNameMockSymbol = Symbol('getProjectName'); /** Symbol of mock function used in place of resolveCommit for testing. * * @private */ -exports.resolveCommitMockSymbol = Symbol('resolveCommit'); +export const resolveCommitMockSymbol = Symbol('resolveCommit'); diff --git a/package.json b/package.json index 0c92e0d..9d51221 100644 --- a/package.json +++ b/package.json @@ -17,14 +17,13 @@ "type": "git", "url": "https://github.com/kevinoid/hub-ci-status.git" }, - "type": "commonjs", + "type": "module", "files": [ "*.js", "bin/", "lib/", "!**/.*" ], - "main": "index.js", "exports": { ".": "./index.js", "./package.json": "./package.json" diff --git a/test-lib/api-responses.js b/test-lib/api-responses.js index 6d8625e..7fd03a1 100644 --- a/test-lib/api-responses.js +++ b/test-lib/api-responses.js @@ -5,8 +5,6 @@ * @license MIT */ -"use strict"; - const octokitResult = { "status": 200, "url": "https://api.github.com/repos/github/hello-world/commits/master", @@ -47,8 +45,7 @@ const octokitResult = { * check_runs.conclusion "neutral". * @returns {!object} Mock API response with given conclusion values. */ -exports.makeCheckRuns = -function makeCheckRuns(...runConclusions) { +export function makeCheckRuns(...runConclusions) { // https://docs.github.com/en/rest/reference/checks#list-check-runs-for-a-git-reference const checkRun = { "id": 4, @@ -156,7 +153,7 @@ function makeCheckRuns(...runConclusions) { }) } }; -}; +} /** Creates an Octokit result object for "Get the combined status for a * specific reference". @@ -165,8 +162,7 @@ function makeCheckRuns(...runConclusions) { * ("success", "pending", "failure") * @returns {!object} Mock API response with given state values. */ -exports.makeCombinedStatus = -function makeCombinedStatus(...statusStates) { +export function makeCombinedStatus(...statusStates) { // https://docs.github.com/rest/reference/repos#get-the-combined-status-for-a-specific-reference const statuses = [ { @@ -287,4 +283,4 @@ function makeCombinedStatus(...statusStates) { "url": "https://api.github.com/repos/octocat/Hello-World/6dcb09b5b57875f334f61aebed695e2e4193db5e/status" } }; -}; +} diff --git a/test-lib/git-init.js b/test-lib/git-init.js index 63a67be..8f7e68e 100644 --- a/test-lib/git-init.js +++ b/test-lib/git-init.js @@ -3,11 +3,9 @@ * @license MIT */ -'use strict'; +import execFileOut from '../lib/exec-file-out.js'; -const execFileOut = require('../lib/exec-file-out.js'); - -module.exports = async function gitInit(repoPath, defaultBranch) { +export default async function gitInit(repoPath, defaultBranch) { try { await execFileOut( 'git', @@ -39,4 +37,4 @@ module.exports = async function gitInit(repoPath, defaultBranch) { 'git', ['-C', repoPath, 'config', 'user.email', 'test@example.com'], ); -}; +} diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 5c0b46e..f0e0010 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -11,6 +11,9 @@ // Braces around body of it() function is more consistent/readable "arrow-body-style": "off", + // Tests are not expected to have exports + "import/no-unused-modules": "off", + // Allow null use in tests "unicorn/no-null": "off" } diff --git a/test/cli.js b/test/cli.js index 630917c..b767900 100644 --- a/test/cli.js +++ b/test/cli.js @@ -3,14 +3,12 @@ * @license MIT */ -'use strict'; +import assert from 'assert'; +import sinon from 'sinon'; +import stream from 'stream'; -const assert = require('assert'); -const sinon = require('sinon'); -const stream = require('stream'); - -const getPackageJson = require('../lib/get-package-json.js'); -const hubCiStatusCmd = require('../cli.js'); +import getPackageJson from '../lib/get-package-json.js'; +import hubCiStatusCmd from '../cli.js'; const { match } = sinon; diff --git a/test/index.js b/test/index.js index fa688f8..ae7519f 100644 --- a/test/index.js +++ b/test/index.js @@ -3,21 +3,21 @@ * @license MIT */ -'use strict'; - -const ansiStyles = require('ansi-styles'); -const assert = require('assert'); -const sinon = require('sinon'); -const { PassThrough } = require('stream'); - -const hubCiStatus = require('..'); -const { makeCheckRuns, makeCombinedStatus } = - require('../test-lib/api-responses.js'); -const { +import ansiStyles from 'ansi-styles'; +import assert from 'assert'; +import sinon from 'sinon'; +import { PassThrough } from 'stream'; + +import hubCiStatus from '../index.js'; +import { + makeCheckRuns, + makeCombinedStatus, +} from '../test-lib/api-responses.js'; +import { fetchCiStatusMockSymbol, getProjectNameMockSymbol, resolveCommitMockSymbol, -} = require('../lib/symbols.js'); +} from '../lib/symbols.js'; const { match } = sinon; diff --git a/test/lib/exec-file-out.js b/test/lib/exec-file-out.js index a772dc5..22f0ab3 100644 --- a/test/lib/exec-file-out.js +++ b/test/lib/exec-file-out.js @@ -3,11 +3,9 @@ * @license MIT */ -'use strict'; +import assert from 'assert'; -const assert = require('assert'); - -const execFileOut = require('../../lib/exec-file-out.js'); +import execFileOut from '../../lib/exec-file-out.js'; function neverCalled() { throw new Error('Should not be called'); diff --git a/test/lib/fetch-ci-status.js b/test/lib/fetch-ci-status.js index 7f36829..ace4361 100644 --- a/test/lib/fetch-ci-status.js +++ b/test/lib/fetch-ci-status.js @@ -3,23 +3,23 @@ * @license MIT */ -'use strict'; - -const FakeTimers = require('@sinonjs/fake-timers'); -const assert = require('assert'); -const sinon = require('sinon'); -const timers = require('timers'); -const { promisify } = require('util'); - -const fetchCiStatus = require('../../lib/fetch-ci-status.js'); -const getPackageJson = require('../../lib/get-package-json.js'); -const { makeCheckRuns, makeCombinedStatus } = - require('../../test-lib/api-responses.js'); -const { +import FakeTimers from '@sinonjs/fake-timers'; +import assert from 'assert'; +import sinon from 'sinon'; +import timers from 'timers'; +import { promisify } from 'util'; + +import fetchCiStatus from '../../lib/fetch-ci-status.js'; +import getPackageJson from '../../lib/get-package-json.js'; +import { + makeCheckRuns, + makeCombinedStatus, +} from '../../test-lib/api-responses.js'; +import { HttpAgentMockSymbol, HttpsAgentMockSymbol, OctokitMockSymbol, -} = require('../../lib/symbols.js'); +} from '../../lib/symbols.js'; // TODO [engine:node@>=15]: import { setImmediate } from 'timers/promises'; const setImmediateP = promisify(timers.setImmediate); diff --git a/test/lib/git-utils.js b/test/lib/git-utils.js index 21a2080..99b7f7d 100644 --- a/test/lib/git-utils.js +++ b/test/lib/git-utils.js @@ -3,17 +3,15 @@ * @license MIT */ -'use strict'; - -const assert = require('assert'); -const path = require('path'); -const { dir: makeTempDir } = require('tmp-promise'); -const { pathToFileURL } = require('url'); - -const getPackageJson = require('../../lib/get-package-json.js'); -const gitInit = require('../../test-lib/git-init.js'); -const gitUtils = require('../../lib/git-utils.js'); -const execFileOut = require('../../lib/exec-file-out.js'); +import assert from 'assert'; +import path from 'path'; +import { dir as makeTempDir } from 'tmp-promise'; +import { pathToFileURL } from 'url'; + +import getPackageJson from '../../lib/get-package-json.js'; +import gitInit from '../../test-lib/git-init.js'; +import * as gitUtils from '../../lib/git-utils.js'; +import execFileOut from '../../lib/exec-file-out.js'; const defaultBranch = 'main'; const isWindows = /^win/i.test(process.platform); diff --git a/test/lib/github-utils.js b/test/lib/github-utils.js index e2a0141..d0ebc68 100644 --- a/test/lib/github-utils.js +++ b/test/lib/github-utils.js @@ -9,16 +9,14 @@ * @license MIT */ -'use strict'; - -const assert = require('assert'); -const { dir: makeTempDir } = require('tmp-promise'); - -const execFileOut = require('../../lib/exec-file-out.js'); -const getPackageJson = require('../../lib/get-package-json.js'); -const gitInit = require('../../test-lib/git-init.js'); -const { getProjectName } = require('../../lib/github-utils.js'); -const { resolveCommit } = require('../../lib/git-utils.js'); +import assert from 'assert'; +import { dir as makeTempDir } from 'tmp-promise'; + +import execFileOut from '../../lib/exec-file-out.js'; +import getPackageJson from '../../lib/get-package-json.js'; +import gitInit from '../../test-lib/git-init.js'; +import { getProjectName } from '../../lib/github-utils.js'; +import { resolveCommit } from '../../lib/git-utils.js'; const defaultBranch = 'main'; const isWindows = /^win/i.test(process.platform); diff --git a/test/lib/retry-async.js b/test/lib/retry-async.js index 308a57d..b378d4d 100644 --- a/test/lib/retry-async.js +++ b/test/lib/retry-async.js @@ -3,15 +3,13 @@ * @license MIT */ -'use strict'; +import FakeTimers from '@sinonjs/fake-timers'; +import assert from 'assert'; +import sinon from 'sinon'; +import timers from 'timers'; +import { promisify } from 'util'; -const FakeTimers = require('@sinonjs/fake-timers'); -const assert = require('assert'); -const sinon = require('sinon'); -const timers = require('timers'); -const { promisify } = require('util'); - -const retryAsync = require('../../lib/retry-async.js'); +import retryAsync from '../../lib/retry-async.js'; // TODO [engine:node@>=15]: import { setImmediate } from 'timers/promises'; const setImmediateP = promisify(timers.setImmediate); diff --git a/test/lib/retry-async/constant.js b/test/lib/retry-async/constant.js index cf2eeb5..0e85892 100644 --- a/test/lib/retry-async/constant.js +++ b/test/lib/retry-async/constant.js @@ -3,11 +3,9 @@ * @license MIT */ -'use strict'; +import assert from 'assert'; -const assert = require('assert'); - -const constant = require('../../../lib/retry-async/constant.js'); +import constant from '../../../lib/retry-async/constant.js'; describe('retryAsync.constant', () => { it('returns an iterable of number first argument', () => { diff --git a/test/lib/retry-async/exponential.js b/test/lib/retry-async/exponential.js index 40161f9..d2d4087 100644 --- a/test/lib/retry-async/exponential.js +++ b/test/lib/retry-async/exponential.js @@ -3,11 +3,9 @@ * @license MIT */ -'use strict'; +import assert from 'assert'; -const assert = require('assert'); - -const exponential = require('../../../lib/retry-async/exponential.js'); +import exponential from '../../../lib/retry-async/exponential.js'; describe('retryAsync.exponential', () => { it('returns an iterable of count exponentially increasing values', () => {