-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a linter, update codebase to confirm. Update readme. Updated depe…
…ndencies
- Loading branch information
Showing
14 changed files
with
1,613 additions
and
809 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Javascript Node CircleCI 2.0 configuration file | ||
# | ||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details | ||
# | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
# specify the version you desire here | ||
- image: circleci/node:7.10 | ||
|
||
# Specify service dependencies here if necessary | ||
# CircleCI maintains a library of pre-built images | ||
# documented at https://circleci.com/docs/2.0/circleci-images/ | ||
# - image: circleci/mongo:3.4.4 | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: yarn install | ||
|
||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
|
||
# run tests! | ||
- run: yarn test | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
.idea | ||
coverage | ||
dist/ | ||
node_modules | ||
publish | ||
yarn-error.log | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
.idea | ||
coverage | ||
node_modules | ||
src | ||
yarn-error.log | ||
yarn.lock | ||
|
||
src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
{ | ||
"author": "Dean Merchant", | ||
"dependencies": { | ||
"chalk": "^2.0.1", | ||
"lodash": "^4.17.4" | ||
}, | ||
"description": "A jest matcher to verify the structure of an object, particularly useful for api integration tests", | ||
"devDependencies": { | ||
"@types/chalk": "0.4.31", | ||
"@types/jest": "20.0.5", | ||
"@types/lodash": "4.14.71", | ||
"jest": "20.0.4", | ||
"ts-jest": "20.0.7", | ||
"typescript": "2.4.2" | ||
"@types/chalk": "2.2.0", | ||
"@types/jest": "22.0.1", | ||
"@types/lodash": "4.14.92", | ||
"jest": "22.0.6", | ||
"ts-jest": "22.0.1", | ||
"tslint": "5.9.1", | ||
"tslint-react": "3.4.0", | ||
"typescript": "2.6.2" | ||
}, | ||
"files": [ | ||
"publish" | ||
"dist" | ||
], | ||
"jest": { | ||
"collectCoverageFrom": [ | ||
|
@@ -42,18 +43,19 @@ | |
} | ||
}, | ||
"license": "MIT", | ||
"main": "publish/index.js", | ||
"types": "publish/index.d.ts", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"name": "jest-to-match-shape-of", | ||
"peerDependencies": { | ||
"jest": "20.x" | ||
"jest": "22.x" | ||
}, | ||
"repository": "[email protected]:Dean177/jest-to-match-shape-of.git", | ||
"scripts": { | ||
"dev": "tsc --watch", | ||
"build": "rm -rf publish && tsc", | ||
"build": "rm -rf dist && tsc", | ||
"dev": "tsc --noEmit --pretty --watch", | ||
"lint": "tslint ./src/**/*.ts", | ||
"prepublish": "npm test && npm run build", | ||
"test": "jest --coverage" | ||
"test": "jest --watch" | ||
}, | ||
"version": "0.1.3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export type MatcherFactory = jasmine.CustomMatcherFactory; | ||
export type Result = jasmine.CustomMatcherResult; | ||
export type MatcherFactory = jasmine.CustomMatcherFactory | ||
export type Result = jasmine.CustomMatcherResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { toMatchOneOf, toMatchShapeOf } from './toMatchShapeOf'; | ||
import { toMatchOneOf, toMatchShapeOf } from './toMatchShapeOf' | ||
|
||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toMatchOneOf(expected: Array<any>): R, | ||
toMatchShapeOf(expected: any): R, | ||
toMatchOneOf(expected: Array<any>): R, // tslint:disable-line:no-any | ||
toMatchShapeOf(expected: any): R, // tslint:disable-line:no-any | ||
} | ||
} | ||
} | ||
|
||
jasmine.addMatchers({ | ||
toMatchOneOf, | ||
toMatchShapeOf, | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { toBeTypeOfCompare } from './toBeTypeOf'; | ||
import { toBeTypeOfCompare } from './toBeTypeOf' | ||
|
||
describe('toBeTypeOf', () => { | ||
it('Returns no error when the types match', () => { | ||
expect(toBeTypeOfCompare(false, true).pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare(false, true).pass).toBe(true) | ||
|
||
expect(toBeTypeOfCompare(1, 0).pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare(1, 0).pass).toBe(true) | ||
|
||
expect(toBeTypeOfCompare('a', 'b').pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare('a', '').pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare('a', 'b').pass).toBe(true) | ||
expect(toBeTypeOfCompare('a', '').pass).toBe(true) | ||
|
||
expect(toBeTypeOfCompare([1, 2, 3], [1, 2, 3]).pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare([1, 2, 3], []).pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare([1, 2, 3], ['a', 'b', 'c']).pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare([1, 2, 3], [1, 2, 3]).pass).toBe(true) | ||
expect(toBeTypeOfCompare([1, 2, 3], []).pass).toBe(true) | ||
expect(toBeTypeOfCompare([1, 2, 3], ['a', 'b', 'c']).pass).toBe(true) | ||
|
||
expect(toBeTypeOfCompare(() => {}, () => {}).pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare(() => {}, function() {}).pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare(() => true, () => false).pass).toBe(true) | ||
expect(toBeTypeOfCompare(() => 6, function() { return 7 }).pass).toBe(true) | ||
|
||
expect(toBeTypeOfCompare(null, null).pass).toBeTruthy(); | ||
expect(toBeTypeOfCompare(null, null).pass).toBe(true) | ||
|
||
expect(toBeTypeOfCompare(undefined, undefined).pass).toBeTruthy(); | ||
}); | ||
expect(toBeTypeOfCompare(undefined, undefined).pass).toBe(true) | ||
}) | ||
|
||
it(`fails when the types don't match`, () => { | ||
expect(toBeTypeOfCompare('a', false).pass).toBeFalsy(); | ||
expect(toBeTypeOfCompare(1, 'b').pass).toBeFalsy(); | ||
expect(toBeTypeOfCompare('a', []).pass).toBeFalsy(); | ||
expect(toBeTypeOfCompare(null, 1).pass).toBeFalsy(); | ||
expect(toBeTypeOfCompare(null, () => {}).pass).toBeFalsy(); | ||
|
||
expect(toBeTypeOfCompare({}, []).pass).toBeFalsy(); | ||
}); | ||
}); | ||
expect(toBeTypeOfCompare('a', false).pass).toBe(false) | ||
expect(toBeTypeOfCompare(1, 'b').pass).toBe(false) | ||
expect(toBeTypeOfCompare('a', []).pass).toBe(false) | ||
expect(toBeTypeOfCompare(null, 1).pass).toBe(false) | ||
expect(toBeTypeOfCompare(null, () => null).pass).toBe(false) | ||
|
||
expect(toBeTypeOfCompare({}, []).pass).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
import { green, red } from 'chalk'; | ||
import { Result } from './common-types'; | ||
import chalk from 'chalk' | ||
import { Result } from './common-types' | ||
|
||
const { green, red } = chalk | ||
|
||
// tslint:disable-next-line:no-any | ||
export const toBeTypeOfCompare = (actual: any, expected: any): Result => { | ||
if (actual == null && expected != null) { | ||
return { | ||
message: `expected '${green(typeof expected)}' but got '${red(actual)}'`, | ||
pass: false, | ||
}; | ||
} | ||
} | ||
|
||
if (Array.isArray(expected)) { | ||
const pass = Array.isArray(actual); | ||
const message = (!pass) ? | ||
`expected '${green('array')}', but was '${red(typeof actual)}'` : | ||
''; | ||
return { message, pass }; | ||
const hasPassed = Array.isArray(actual) | ||
return { | ||
message: (!hasPassed) | ||
? `expected '${green('array')}', but was '${red(typeof actual)}'` | ||
: '', | ||
pass: hasPassed, | ||
} | ||
} | ||
|
||
const pass = typeof actual === typeof expected; | ||
const pass = typeof actual === typeof expected | ||
const message = (!pass) ? | ||
`expected '${green(typeof expected)}', but was '${red(typeof actual)}' for ${JSON.stringify(actual)}` : | ||
''; | ||
return { message, pass }; | ||
}; | ||
'' | ||
|
||
return { message, pass } | ||
} |
Oops, something went wrong.