Skip to content

Commit

Permalink
add test-helper module
Browse files Browse the repository at this point in the history
  • Loading branch information
openhoat committed Jun 3, 2018
1 parent 5121c89 commit 726d261
Show file tree
Hide file tree
Showing 20 changed files with 7,228 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/test-helper/.buildrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
libDir: lib
testDir: test
typesDir: types
builtDir: built
distDir: dist
mainScript: lib/helper.ts
39 changes: 39 additions & 0 deletions packages/test-helper/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=false
indent_style=space
indent_size=4

[{.eslintrc,.prettierrc,.redis-commander,.babelrc,jest.config,.stylelintrc,*.json,*.jsb3,*.jsb2,*.bowerrc}]
indent_style=space
indent_size=2

[{*.ats,*.ts}]
indent_style=space
indent_size=2

[{tsconfig.e2e.json,tsconfig.spec.json,tsconfig.app.json,tsconfig.json}]
indent_style=space
indent_size=2

[*.js]
indent_style=space
indent_size=2
insert_final_newline=true

[*.js.map]
indent_style=space
indent_size=2

[{.analysis_options,*.yml,*.yaml}]
indent_style=space
indent_size=2

[yarn.lock]
indent_style=space
indent_size=2

[tslint.json]
indent_style=space
indent_size=2
11 changes: 11 additions & 0 deletions packages/test-helper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea/
.DS_Store
.vscode
.history
.nyc_output
built/
dist/
node_modules/
tsconfig.json
lib/tsconfig.json
test/tsconfig.json
3 changes: 3 additions & 0 deletions packages/test-helper/.huskyrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hooks:
pre-commit: nps lint && nps 'test -- --forbid-only'
pre-push": nps check
1 change: 1 addition & 0 deletions packages/test-helper/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.0.0
11 changes: 11 additions & 0 deletions packages/test-helper/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dist/
.editorconfig
.gitignore
.idea/
.node-version
.nycrc
.travis.yml
lib/
test/
tsconfig.json
tslint.json
1 change: 1 addition & 0 deletions packages/test-helper/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.0.0
18 changes: 18 additions & 0 deletions packages/test-helper/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extension": [
".ts"
],
"exclude": [
"built",
"dist",
"src/test",
"**/*.d.ts"
],
"temp-directory": "./dist/.nyc_output",
"report-dir": "./dist/coverage",
"reporter": [
"html",
"text-summary"
],
"all": true
}
5 changes: 5 additions & 0 deletions packages/test-helper/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "10.0.0"
script:
- "npm start cover.travis"
49 changes: 49 additions & 0 deletions packages/test-helper/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { dirname, resolve } from 'path'
import { expect, use as chaiUse } from 'chai'
import { inspect } from 'util'
import { createSandbox, SinonSandbox, SinonStub, createStubInstance } from 'sinon'
import * as sinonChai from 'sinon-chai'
import { noCallThru } from 'proxyquire'

const caller = require('caller')

const proxyquireLoad = noCallThru().load

function proxyquire(request: string, stubs: any): any {
const baseDir = dirname(caller())
return proxyquireLoad(resolve(baseDir, request), stubs)
}

const chaiAsPromised = require('chai-as-promised')
chaiUse(sinonChai)
chaiUse(chaiAsPromised)

function hasBeenCalled(fn: Function) {
expect(fn).to.be.called
}

function asString(data: any) {
return data === undefined ?
'undefined' :
(
typeof data === 'object' ?
inspect(data, { colors: process.stdin.isTTY, breakLength: Infinity }) :
data
)
}

function givenDesc(data: any) {
return `given : ${asString(data)}`
}

export {
expect,
hasBeenCalled,
SinonSandbox,
SinonStub,
createSandbox,
createStubInstance,
proxyquire,
asString,
givenDesc,
}
6 changes: 6 additions & 0 deletions packages/test-helper/lib/tsconfig.tpl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends: ../tsconfig.json
compilerOptions:
rootDir: .
outDir: '../{{ builtDir }}'
include:
- './**/*.ts'
Loading

0 comments on commit 726d261

Please sign in to comment.