From 07988acff811e4cedd5afc753e8a139002a74160 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Sat, 3 Feb 2018 08:26:00 -0800 Subject: [PATCH] fix: typescript 2.7 --- .circleci/config.yml | 32 ++++++++++++++++---------- .circleci/greenkeeper | 25 ++++++++++++++++++++ .circleci/release | 11 --------- .circleci/setup_git | 12 ---------- .circleci/test | 29 ----------------------- .eslintrc | 2 +- appveyor.yml | 9 +++----- package-scripts.js | 53 ------------------------------------------- package.json | 20 +++++++--------- src/base.ts | 2 +- src/catch.ts | 2 +- src/env.ts | 2 +- src/index.ts | 3 +-- src/nock.ts | 10 ++++++-- src/stub.ts | 25 +++++++++++--------- test/base.test.ts | 2 +- tsconfig.json | 2 +- tslint.json | 2 +- yarn.lock | 38 +++++++++++++++++++++++++++++-- 19 files changed, 122 insertions(+), 159 deletions(-) create mode 100755 .circleci/greenkeeper delete mode 100755 .circleci/release delete mode 100755 .circleci/setup_git delete mode 100755 .circleci/test delete mode 100644 package-scripts.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 12bfc69..7c91e05 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,34 +5,42 @@ jobs: docker: - image: node:latest working_directory: ~/cli + environment: + NYC: "yarn exec nyc -- --nycrc-path node_modules/@anycli/nyc-config/.nycrc" + MOCHA_FILE: "reports/mocha.xml" steps: - checkout - restore_cache: &restore_cache keys: - - v0-yarn-{{checksum ".circleci/config.yml"}}-{{ .Branch }}-{{checksum "yarn.lock"}} - - v0-yarn-{{checksum ".circleci/config.yml"}}-{{ .Branch }}- - - v0-yarn-{{checksum ".circleci/config.yml"}}-master- - - run: .circleci/test + - v0-yarn-{{checksum ".circleci/config.yml"}}-{{ checksum "yarn.lock"}} + - v0-yarn-{{checksum ".circleci/config.yml"}} + - run: .circleci/greenkeeper + - run: yarn add -D nyc@11 @anycli/nyc-config@0 mocha-junit-reporter@1 @commitlint/cli@6 @commitlint/config-conventional@6 + - run: | + mkdir -p reports + $NYC yarn test --reporter mocha-junit-reporter + $NYC report --reporter text-lcov > coverage.lcov + curl -s https://codecov.io/bash | bash + - run: yarn exec commitlint -- -x @commitlint/config-conventional --from origin/master - store_test_results: &store_test_results path: ~/cli/reports node-8: <<: *test docker: - image: node:8 - steps: - - checkout - - restore_cache: *restore_cache - - run: .circleci/test - - store_test_results: *store_test_results release: <<: *test steps: - add_ssh_keys - checkout - restore_cache: *restore_cache - - run: .circleci/release - - save_cache: &save_cache - key: v0-yarn-{{checksum ".circleci/config.yml"}}-{{ .Branch }}-{{checksum "yarn.lock"}} + - run: yarn global add @anycli/semantic-release@1 semantic-release@12 + - run: yarn --frozen-lockfile + - run: | + export PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH + semantic-release -e @anycli/semantic-release + - save_cache: + key: v0-yarn-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}} paths: - ~/cli/node_modules - /usr/local/share/.cache/yarn diff --git a/.circleci/greenkeeper b/.circleci/greenkeeper new file mode 100755 index 0000000..bf73a3e --- /dev/null +++ b/.circleci/greenkeeper @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -ex + +PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH + +if [[ "$CIRCLE_BRANCH" != greenkeeper/* ]]; then + yarn + # yarn check + exit 0 +fi + +if [[ ! -z "$GIT_EMAIL" ]] & [[ ! -z "$GIT_USERNAME" ]]; then + git config --global push.default simple + git config --global user.email "$GIT_EMAIL" + git config --global user.name "$GIT_USERNAME" +fi + +if [[ ! -x "$(command -v greenkeeper-lockfile-update)" ]]; then + yarn global add greenkeeper-lockfile@1 +fi + +greenkeeper-lockfile-update +yarn +greenkeeper-lockfile-upload diff --git a/.circleci/release b/.circleci/release deleted file mode 100755 index b79d957..0000000 --- a/.circleci/release +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -.circleci/setup_git - -PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH - -yarn global add @dxcli/semantic-release@1 semantic-release@12 -yarn install --frozen-lockfile -semantic-release -e @dxcli/semantic-release diff --git a/.circleci/setup_git b/.circleci/setup_git deleted file mode 100755 index ac22623..0000000 --- a/.circleci/setup_git +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -if [[ ! -z "$GIT_EMAIL" ]] & [[ ! -z "$GIT_USERNAME" ]]; then - git config --global push.default simple - git config --global user.email "$GIT_EMAIL" - git config --global user.name "$GIT_USERNAME" -fi - -git submodule sync -git submodule update --init --recursive diff --git a/.circleci/test b/.circleci/test deleted file mode 100755 index deb213c..0000000 --- a/.circleci/test +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -.circleci/setup_git - -PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH - -CLI_ENGINE_UTIL_YARN_ARGS="--frozen-lockfile" - -if [[ "$CIRCLE_BRANCH" == greenkeeper/* ]]; then - CLI_ENGINE_GREENKEEPER_BRANCH=1 - CLI_ENGINE_UTIL_YARN_ARGS="" - if [[ ! -x "$(command -v greenkeeper-lockfile-update)" ]]; then - yarn global add greenkeeper-lockfile@1 - fi - greenkeeper-lockfile-update -fi - -yarn install $CLI_ENGINE_UTIL_YARN_ARGS - -if [[ "$CLI_ENGINE_GREENKEEPER_BRANCH" == 1 ]]; then - greenkeeper-lockfile-upload -fi - -yarn add -D nyc @dxcli/nyc-config -yarn test - -curl -s https://codecov.io/bash | bash diff --git a/.eslintrc b/.eslintrc index 9ccc568..adc3295 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,3 @@ { - "extends": "dxcli" + "extends": "anycli" } diff --git a/appveyor.yml b/appveyor.yml index d6e9ff4..87593df 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,14 +6,11 @@ cache: install: - ps: Install-Product node $env:nodejs_version x64 - - git submodule sync - - git submodule update --init --recursive - - git config --global user.email "dxcli@example.com" - - git config --global user.name "dxcli" - - yarn add -D nyc @dxcli/nyc-config + - yarn add -D nyc@11 @anycli/nyc-config@0 test_script: - - yarn test + - .\node_modules\.bin\nyc --nycrc-path node_modules/@anycli/nyc-config/.nycrc yarn test after_test: + - .\node_modules\.bin\nyc --nycrc-path node_modules/@anycli/nyc-config/.nycrc report --reporter text-lcov > coverage.lcov - ps: | $env:PATH = 'C:\msys64\usr\bin;' + $env:PATH Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh diff --git a/package-scripts.js b/package-scripts.js deleted file mode 100644 index 6751e89..0000000 --- a/package-scripts.js +++ /dev/null @@ -1,53 +0,0 @@ -/* eslint-disable unicorn/filename-case */ - -const { - setColors, - concurrent, - crossEnv, - mkdirp, - series, -} = require('nps-utils') - -setColors(['dim']) - -const script = (script, description) => description ? {script, description} : {script} - -const linters = { - eslint: script('eslint .', 'lint js files'), - commitlint: script('commitlint --from origin/master', 'ensure that commits are in valid conventional-changelog format'), - tsc: script('tsc -p test --noEmit', 'syntax check with tsc'), - tslint: script('tslint -p test', 'lint ts files'), -} - -let mocha = 'mocha --forbid-only "test/**/*.test.ts"' -if (process.env.CI) { - if (process.env.CIRCLECI) { - // add mocha junit reporter - mocha = crossEnv(`MOCHA_FILE=reports/mocha.xml ${mocha} --reporter mocha-junit-reporter`) - // add eslint reporter - linters.eslint.script = `${linters.eslint.script} --format junit --output-file reports/eslint.xml` - // add tslint reporter - linters.tslint.script = `${linters.tslint.script} --format junit > reports/tslint.xml` - } - // add code coverage reporting with nyc - const nyc = 'nyc --nycrc-path node_modules/@dxcli/nyc-config/.nycrc' - const nycReport = `${nyc} report --reporter text-lcov > coverage.lcov` - mocha = series(`${nyc} ${mocha}`, nycReport) -} - -let test = concurrent({ - ...linters, - test: series('nps build', mocha), -}) - -if (process.env.CI) test = series(mkdirp('reports'), test) - -module.exports = { - scripts: { - ...linters, - build: series('rm -rf lib', 'tsc'), - lint: concurrent(linters), - test, - mocha, - }, -} diff --git a/package.json b/package.json index 1071a91..8a9cfd4 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,7 @@ "stdout-stderr": "^0.1.6" }, "devDependencies": { - "@commitlint/cli": "^6.1.0", - "@commitlint/config-conventional": "^6.1.0", - "@dxcli/tslint": "^0.1.3", + "@anycli/tslint": "^0.2.5", "@types/chai": "^4.1.2", "@types/lodash": "^4.14.100", "@types/mocha": "^2.2.48", @@ -22,15 +20,12 @@ "@types/sinon": "^4.1.3", "chai": "^4.1.2", "chalk": "^2.3.0", + "concurrently": "^3.5.1", "eslint": "^4.17.0", - "eslint-config-dxcli": "^1.2.1", + "eslint-config-anycli": "^1.3.2", "http-call": "^5.0.2", - "husky": "^0.14.3", "mocha": "^5.0.0", - "mocha-junit-reporter": "^1.17.0", "nock": "^9.1.6", - "nps": "^5.7.1", - "nps-utils": "^1.5.0", "sinon": "^4.2.2", "ts-node": "^4.1.0", "typescript": "^2.7.1" @@ -49,10 +44,11 @@ "main": "lib/index.js", "repository": "jdxcode/fancy-test", "scripts": { - "commitmsg": "commitlint -x @commitlint/config-conventional -e $GIT_PARAMS", - "precommit": "nps lint -l warn", - "prepublishOnly": "nps build", - "test": "nps test -l warn" + "build": "rm -rf lib && tsc", + "lint": "concurrently -p command \"eslint .\" \"tsc -p test --noEmit\" \"tslint -p test\"", + "posttest": "yarn run lint", + "prepublishOnly": "yarn run build", + "test": "mocha --forbid-only \"test/**/*.test.ts\"" }, "types": "lib/index.d.ts" } diff --git a/src/base.ts b/src/base.ts index c67045c..22780bc 100644 --- a/src/base.ts +++ b/src/base.ts @@ -139,6 +139,6 @@ export default base(context) .register('only', () => ({ init: ctx => {ctx.test = it.only} })) -.register('retries', (count: number) => ({ +.register('retries', (count?: number) => ({ init: ctx => ctx.retries = count })) diff --git a/src/catch.ts b/src/catch.ts index 3659c0e..30a6c84 100644 --- a/src/catch.ts +++ b/src/catch.ts @@ -2,7 +2,7 @@ import * as _ from 'lodash' import {expect} from './chai' -export default (arg: RegExp | string | ((err: Error) => any), opts: {raiseIfNotThrown?: boolean} = {}) => ({ +export default (arg?: RegExp | string | ((err: Error) => any), opts: {raiseIfNotThrown?: boolean} = {}) => ({ run() { if (opts.raiseIfNotThrown !== false) { throw new Error('expected error to be thrown') diff --git a/src/env.ts b/src/env.ts index e77e37f..26020a3 100644 --- a/src/env.ts +++ b/src/env.ts @@ -2,7 +2,7 @@ import * as _ from 'lodash' import {EnvOptions} from './types' -export default (env: {[k: string]: string | null | undefined}, opts: EnvOptions = {}) => { +export default (env?: {[k: string]: string | null | undefined}, opts: EnvOptions = {}) => { const envs: (typeof process.env)[] = [] return { run() { diff --git a/src/index.ts b/src/index.ts index 8dc1806..58596ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import base from './base' import _catch from './catch' import {expect} from './chai' import env from './env' -import nock, {NockScope} from './nock' +import {nock} from './nock' import {stderr, stdout} from './stdmock' import stub from './stub' @@ -21,6 +21,5 @@ export type Fancy = typeof fancy export { expect, FancyTypes, - NockScope, } export default fancy diff --git a/src/nock.ts b/src/nock.ts index 04cd8bd..6d57ea7 100644 --- a/src/nock.ts +++ b/src/nock.ts @@ -1,8 +1,10 @@ +import * as _ from 'lodash' import * as Nock from 'nock' -export {Scope as NockScope} from 'nock' +export function nock(host?: string, cb?: (nock: nock.Scope) => any) { + if (_.isUndefined(host)) throw new Error('host is undefined') + if (_.isUndefined(cb)) throw new Error('callback is undefined') -export default (host: string, cb: (nock: Nock.Scope) => any) => { const nock: typeof Nock = require('nock') const intercepter = nock(host) return { @@ -18,3 +20,7 @@ export default (host: string, cb: (nock: Nock.Scope) => any) => { }, } } + +export namespace nock { + export interface Scope extends Nock.Scope {} +} diff --git a/src/stub.ts b/src/stub.ts index 8e82da0..98a6e56 100644 --- a/src/stub.ts +++ b/src/stub.ts @@ -3,14 +3,17 @@ import * as _ from 'lodash' /** * mocks an object's property */ -export default (object: any, path: string, value: any) => ({ - run(ctx: {stubs: any[]}) { - ctx.stubs = ctx.stubs || [] - ctx.stubs.push(_.get(object, path)) - _.set(object, path, value) - }, - finally(ctx: {stubs: any[]}) { - const stub = ctx.stubs.pop() - _.set(object, path, stub) - }, -}) +export default function (object?: any, path?: string, value?: any) { + if (_.isUndefined(object) || _.isUndefined(path))throw new Error('should not be undefined') + return { + run(ctx: {stubs: any[]}) { + ctx.stubs = ctx.stubs || [] + ctx.stubs.push(_.get(object, path)) + _.set(object, path, value) + }, + finally(ctx: {stubs: any[]}) { + const stub = ctx.stubs.pop() + _.set(object, path, stub) + }, + } +} diff --git a/test/base.test.ts b/test/base.test.ts index 667559f..a9d0482 100644 --- a/test/base.test.ts +++ b/test/base.test.ts @@ -4,7 +4,7 @@ let count = 0 // note that .register() MUST be called on a non-instantiated fancy object. const myFancy = fancy -.register('count', (prefix: string) => { +.register('count', (prefix?: string) => { return { run(ctx: {count: number, testLabel: string}) { ctx.count = ++count diff --git a/tsconfig.json b/tsconfig.json index e69ec83..12491d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,11 +7,11 @@ "noUnusedLocals": true, "noUnusedParameters": true, "outDir": "./lib", + "pretty": true, "rootDirs": [ "./src" ], "strict": true, - "strictFunctionTypes": false, "target": "es2017" }, "include": [ diff --git a/tslint.json b/tslint.json index 3a427ce..d4ef989 100644 --- a/tslint.json +++ b/tslint.json @@ -1,3 +1,3 @@ { - "extends": "@dxcli/tslint" + "extends": "@anycli/tslint" } diff --git a/yarn.lock b/yarn.lock index a38d0ea..e3bfdc3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,13 @@ # yarn lockfile v1 +"@anycli/tslint@^0.2.5": + version "0.2.5" + resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.5.tgz#63feeb981b11f36326e0cb745c62f51d55c2ed67" + dependencies: + tslint "^5.9.1" + tslint-xo "^0.6.0" + "@commitlint/cli@^6.1.0": version "6.1.0" resolved "https://registry.yarnpkg.com/@commitlint/cli/-/cli-6.1.0.tgz#0a545088b4e0268cca1dca7e8ccd95bd55847b88" @@ -480,7 +487,7 @@ concat-stream@^1.6.0: readable-stream "^2.2.2" typedarray "^0.0.6" -concurrently@^3.4.0: +concurrently@^3.4.0, concurrently@^3.5.1: version "3.5.1" resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-3.5.1.tgz#ee8b60018bbe86b02df13e5249453c6ececd2521" dependencies: @@ -694,6 +701,15 @@ eslint-ast-utils@^1.0.0: lodash.get "^4.4.2" lodash.zip "^4.2.0" +eslint-config-anycli@^1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/eslint-config-anycli/-/eslint-config-anycli-1.3.2.tgz#0f28e63a8ae93d490623cdcd89eeafcb7635b082" + dependencies: + eslint-config-xo-space "^0.17.0" + eslint-plugin-mocha "^4.11.0" + eslint-plugin-node "^5.2.1" + eslint-plugin-unicorn "^3.0.1" + eslint-config-dxcli@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/eslint-config-dxcli/-/eslint-config-dxcli-1.2.1.tgz#8e65ee698fa77e9485462c788fa466edffccc13d" @@ -712,6 +728,12 @@ eslint-config-xo@^0.18.0: version "0.18.2" resolved "https://registry.yarnpkg.com/eslint-config-xo/-/eslint-config-xo-0.18.2.tgz#0a157120875619929e735ffd6b185c41e8a187af" +eslint-plugin-mocha@^4.11.0: + version "4.11.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-4.11.0.tgz#91193a2f55e20a5e35974054a0089d30198ee578" + dependencies: + ramda "^0.24.1" + eslint-plugin-node@^5.2.1: version "5.2.1" resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-5.2.1.tgz#80df3253c4d7901045ec87fa660a284e32bdca29" @@ -1801,6 +1823,10 @@ qs@^6.5.1: version "6.5.1" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8" +ramda@^0.24.1: + version "0.24.1" + resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.24.1.tgz#c3b7755197f35b8dc3502228262c4c91ddb6b857" + read-pkg-up@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02" @@ -2265,7 +2291,7 @@ tslint-eslint-rules@^4.1.1: tslib "^1.0.0" tsutils "^1.4.0" -tslint-microsoft-contrib@^5.0.1: +tslint-microsoft-contrib@^5.0.1, tslint-microsoft-contrib@^5.0.2: version "5.0.2" resolved "https://registry.yarnpkg.com/tslint-microsoft-contrib/-/tslint-microsoft-contrib-5.0.2.tgz#ecc2a797f777a12f0066944cec0c81a9e7c59ee9" dependencies: @@ -2279,6 +2305,14 @@ tslint-xo@^0.5.0: tslint-eslint-rules "^4.1.1" tslint-microsoft-contrib "^5.0.1" +tslint-xo@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/tslint-xo/-/tslint-xo-0.6.0.tgz#95a05b8dcac7aaa1f4d6ca1397a3c4c45a8b848e" + dependencies: + tslint-consistent-codestyle "^1.11.0" + tslint-eslint-rules "^4.1.1" + tslint-microsoft-contrib "^5.0.2" + tslint@^5.9.1: version "5.9.1" resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.9.1.tgz#1255f87a3ff57eb0b0e1f0e610a8b4748046c9ae"