Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
feat!: node 18 minimum
Browse files Browse the repository at this point in the history
BREAKING CHANGE: node 18 minimum
  • Loading branch information
mdonnalley committed Sep 20, 2023
1 parent 1764d75 commit 506657d
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 218 deletions.
9 changes: 0 additions & 9 deletions .eslintrc

This file was deleted.

17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": [
"oclif",
"oclif-typescript"
],
"rules": {
"unicorn/no-array-reduce": "off",
"unicorn/prefer-object-from-entries": "off",
"unicorn/no-array-for-each": "off",
"unicorn/prefer-module": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"valid-jsdoc": "off",
"unicorn/import-style": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/interface-name-prefix": "off"
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"chai": "^4.3.8",
"chalk": "^4.1.0",
"eslint": "^7.3.1",
"eslint-config-oclif": "^3.1.0",
"eslint-config-oclif-typescript": "^0.2.0",
"eslint-config-oclif": "^4",
"eslint-config-oclif-typescript": "^1",
"http-call": "^5.2.3",
"markdown-toc": "^1.2.0",
"mocha": "^5.2.0",
Expand All @@ -30,7 +30,7 @@
"typescript": "4.4.3"
},
"engines": {
"node": ">=12.0.0"
"node": ">=18.0.0"
},
"files": [
"/lib"
Expand All @@ -44,7 +44,7 @@
"repository": "oclif/fancy-test",
"scripts": {
"build": "rm -rf lib && tsc",
"lint": "eslint . --ext .ts --config .eslintrc",
"lint": "eslint . --ext .ts",
"posttest": "yarn lint",
"prepublishOnly": "yarn run build",
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
Expand Down
10 changes: 9 additions & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ function assignWithProps(target: any, ...sources: any[]) {
return target
}

// eslint-disable-next-line @typescript-eslint/ban-types
const base = <I extends Types.Context>(context: I): Types.Base<I, {}> => {
const end = (arg1: any, cb: Types.MochaCallback<I>) => {
const originalContext = context
if (_.isFunction(arg1)) {
cb = arg1
arg1 = undefined
}

if (!arg1) arg1 = context.expectation || 'test'
async function run(this: Types.ITestCallbackContext, done?: Types.MochaDone) {
context = assignWithProps({}, originalContext)
Expand All @@ -45,6 +47,7 @@ const base = <I extends Types.Context>(context: I): Types.Base<I, {}> => {
},
}]
}

for (let i = 0; i < context.chain.length; i++) {
const handleError = async (err: Error): Promise<boolean> => {
context.error = err
Expand All @@ -59,6 +62,7 @@ const base = <I extends Types.Context>(context: I): Types.Base<I, {}> => {
return handleError(error)
}
}

const next = context.chain[i]
try {
// eslint-disable-next-line no-await-in-loop
Expand All @@ -68,12 +72,15 @@ const base = <I extends Types.Context>(context: I): Types.Base<I, {}> => {
if (!await handleError(error)) break
}
}

for (const p of context.chain.reverse()) {
// eslint-disable-next-line no-await-in-loop
if (p.finally) await p.finally(context)
}

if (context.error) throw context.error
}

return context.test(arg1, (cb && cb.length === 2) ? function (done) {
if (context.timeout) this.timeout(context.timeout)
run.call(this, done).catch(done)
Expand All @@ -82,6 +89,7 @@ const base = <I extends Types.Context>(context: I): Types.Base<I, {}> => {
return run.call(this)
})
}

return {
...Object.entries(context.plugins)
.reduce((plugins, [k, v]) => {
Expand All @@ -95,6 +103,7 @@ const base = <I extends Types.Context>(context: I): Types.Base<I, {}> => {
chain: [...c.chain, plugin],
})
}

return plugins
}, {} as any),
register(k: any, v: any) {
Expand Down Expand Up @@ -123,7 +132,6 @@ const base = <I extends Types.Context>(context: I): Types.Base<I, {}> => {
...context as any,
chain: [...context.chain, {
run: async (ctx: any) => {
// eslint-disable-next-line require-atomic-updates
ctx[key] = await (_.isFunction(v) ? v(ctx) : v)
},
}],
Expand Down
3 changes: 1 addition & 2 deletions src/chai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
const tryRequire = (module: string) => {
try {
return require(module)
} catch (_) {
}
} catch {}
}

const chai: Chai.ChaiStatic = tryRequire('chai')
Expand Down
2 changes: 2 additions & 0 deletions src/nock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function nock(host: string, options: NockCallback | NockOptions, cb?: Noc
cb = options
options = {}
}

if (cb === undefined) throw new Error('callback is undefined')

let nock: typeof Nock
Expand All @@ -19,6 +20,7 @@ export function nock(host: string, options: NockCallback | NockOptions, cb?: Noc
},
}
}

const intercepter = nock(host, options)
return {
async run(ctx: {nock: number}) {
Expand Down
3 changes: 2 additions & 1 deletion src/stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as sinon from 'sinon'
/**
* mocks an object's property
*/
export default function <T extends object, K extends keyof T> (
export default function <T extends Record<string, unknown>, K extends keyof T> (
object: T,
path: K,
fn: (stub: sinon.SinonStub) => sinon.SinonStub,
Expand All @@ -17,6 +17,7 @@ export default function <T extends object, K extends keyof T> (
if (!ctx.sandbox) {
ctx.sandbox = sinon.createSandbox()
}

stub = fn(ctx.sandbox.stub(object, path))
},
finally() {
Expand Down
3 changes: 1 addition & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/interface-name-prefix */
export type PluginBuilder<I, Args extends any[]> = (...args: Args) => Plugin<I>
import Nock = require('nock')

Expand All @@ -20,7 +19,7 @@ export interface Plugin<I> {
}

export interface PluginDef {
output: object | unknown;
output: Record<string, unknown> | unknown;
args: any[];
}

Expand Down
2 changes: 1 addition & 1 deletion test/timeout.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, fancy} from '../src'

// tslint:disable-next-line no-string-based-set-timeout
// eslint-disable-next-line no-promise-executor-return
const wait = (ms = 10) => new Promise(resolve => setTimeout(resolve, ms))

describe('timeout', () => {
Expand Down
Loading

0 comments on commit 506657d

Please sign in to comment.