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

Commit

Permalink
fix: typescript 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 3, 2018
1 parent aa56f5d commit 07988ac
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 159 deletions.
32 changes: 20 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions .circleci/greenkeeper
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions .circleci/release

This file was deleted.

12 changes: 0 additions & 12 deletions .circleci/setup_git

This file was deleted.

29 changes: 0 additions & 29 deletions .circleci/test

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "dxcli"
"extends": "anycli"
}
9 changes: 3 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
- 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
Expand Down
53 changes: 0 additions & 53 deletions package-scripts.js

This file was deleted.

20 changes: 8 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand All @@ -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"
}
2 changes: 1 addition & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}))
2 changes: 1 addition & 1 deletion src/catch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -21,6 +21,5 @@ export type Fancy = typeof fancy
export {
expect,
FancyTypes,
NockScope,
}
export default fancy
10 changes: 8 additions & 2 deletions src/nock.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,3 +20,7 @@ export default (host: string, cb: (nock: Nock.Scope) => any) => {
},
}
}

export namespace nock {
export interface Scope extends Nock.Scope {}
}
25 changes: 14 additions & 11 deletions src/stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}
2 changes: 1 addition & 1 deletion test/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./lib",
"pretty": true,
"rootDirs": [
"./src"
],
"strict": true,
"strictFunctionTypes": false,
"target": "es2017"
},
"include": [
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "@dxcli/tslint"
"extends": "@anycli/tslint"
}
Loading

0 comments on commit 07988ac

Please sign in to comment.