-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SteffenHummel/develop
first version of jest-json-schema-matcher
- Loading branch information
Showing
9 changed files
with
4,022 additions
and
0 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,4 @@ | ||
node_modules | ||
/dist | ||
yarn-error.log | ||
coveragenpm |
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,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
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,52 @@ | ||
{ | ||
"name": "jest-json-schema-matcher", | ||
"version": "1.0.0", | ||
"description": "jest json schema matcher extension", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"preversion": "npm run lint", | ||
"version": "npm run format && git add -A src", | ||
"postversion": "git push && git push --tags", | ||
"test": "jest", | ||
"build": "tsc", | ||
"lint": "tslint -p . --fix 'src/**/*.{ts,tsx}'", | ||
"formatter": "tsfmt -r --useTsfmt ./tsfmt.json --useTslint ./tslint.json --useTsconfig ./tsconfig.json" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/SteffenHummel/jest-json-schema-matcher.git" | ||
}, | ||
"keywords": [ | ||
"jest", | ||
"json", | ||
"schema", | ||
"matcher", | ||
"extension" | ||
], | ||
"author": "Steffen Hummel", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/SteffenHummel/jest-json-schema-matcher/issues" | ||
}, | ||
"homepage": "https://github.com/SteffenHummel/jest-json-schema-matcher#readme", | ||
"devDependencies": { | ||
"@types/jest": "^23.3.12", | ||
"jest": "^23.6.0", | ||
"ts-jest": "^23.10.5", | ||
"tslint": "^5.12.0", | ||
"tslint-config-airbnb": "^5.11.1", | ||
"tslint-config-prettier": "^1.17.0", | ||
"tslint-sonarts": "^1.8.0", | ||
"typescript": "^3.2.2", | ||
"typescript-formatter": "^7.2.2" | ||
}, | ||
"dependencies": { | ||
"jsonschema": "^1.2.4" | ||
} | ||
} |
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,13 @@ | ||
import { jsonSchemaMatcher } from '../index' | ||
expect.extend(jsonSchemaMatcher) | ||
test('jsonSchemaMatcher matches schema', () => { | ||
const schema = { | ||
properties: { | ||
testProp: { | ||
type: 'integer', | ||
}, | ||
}, | ||
required: ['testProp'], | ||
} | ||
expect({ testProp: 1 }).toMatchSchema(schema) | ||
}) |
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,24 @@ | ||
import * as Validator from 'jsonschema' | ||
|
||
declare global { | ||
namespace jest { | ||
interface Expect { | ||
toMatchSchema<T>(jsonSchema: any): Matchers<T> | ||
} | ||
interface Matchers<R> { | ||
toMatchSchema(jsonSchema: any): R | ||
} | ||
} | ||
} | ||
|
||
export const jsonSchemaMatcher: jest.ExpectExtendMap = { | ||
toMatchSchema(received: any, jsonSchema: any): jest.CustomMatcherResult | Promise<jest.CustomMatcherResult> { | ||
|
||
const validationResult: Validator.ValidatorResult = Validator.validate(received, jsonSchema) | ||
const message: string = validationResult.valid ? '' : validationResult.toString() | ||
return { | ||
pass: validationResult.valid, | ||
message: () => message, | ||
} | ||
}, | ||
} |
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,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"outDir": "./dist", | ||
"strict": true | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules", "**/__tests__/*"] | ||
} |
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,24 @@ | ||
{ | ||
"baseIndentSize": 0, | ||
"indentSize": 2, | ||
"tabSize": 2, | ||
"indentStyle": 2, | ||
"newLineCharacter": "\n", | ||
"convertTabsToSpaces": true, | ||
"insertSpaceAfterCommaDelimiter": true, | ||
"insertSpaceAfterSemicolonInForStatements": true, | ||
"insertSpaceBeforeAndAfterBinaryOperators": true, | ||
"insertSpaceAfterConstructor": false, | ||
"insertSpaceAfterKeywordsInControlFlowStatements": true, | ||
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false, | ||
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, | ||
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, | ||
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, | ||
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, | ||
"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, | ||
"insertSpaceAfterTypeAssertion": false, | ||
"insertSpaceBeforeFunctionParenthesis": false, | ||
"insertSpaceBeforeTypeAnnotation": false, | ||
"placeOpenBraceOnNewLineForFunctions": false, | ||
"placeOpenBraceOnNewLineForControlBlocks": 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": ["tslint-config-airbnb", "tslint-sonarts"], | ||
"rules": { | ||
"import-name": false, | ||
"semicolon": [true, "never"], | ||
"max-line-length": [true, 300], | ||
"no-eval": true, | ||
"no-default-export": true | ||
} | ||
} |
Oops, something went wrong.