Skip to content
Snippets Groups Projects
Commit afc4bd60 authored by Tomasz Ducin's avatar Tomasz Ducin
Browse files

IoC container, #12

parent 73203915
Branches
Tags
No related merge requests found
...@@ -2,6 +2,7 @@ language: node_js ...@@ -2,6 +2,7 @@ language: node_js
branches: branches:
only: only:
- master - master
- extending-dependencies
node_js: node_js:
- 0.10 - 0.10
before_script: before_script:
......
...@@ -3,7 +3,9 @@ Fake your schemas! ...@@ -3,7 +3,9 @@ Fake your schemas!
[![Build Status](https://travis-ci.org/pateketrueke/json-schema-faker.png?branch=master)](https://travis-ci.org/pateketrueke/json-schema-faker) [![NPM version](https://badge.fury.io/js/json-schema-faker.png)](http://badge.fury.io/js/json-schema-faker) [![Coverage Status](https://coveralls.io/repos/pateketrueke/json-schema-faker/badge.png?branch=master)](https://coveralls.io/r/pateketrueke/json-schema-faker?branch=master) [![Build Status](https://travis-ci.org/pateketrueke/json-schema-faker.png?branch=master)](https://travis-ci.org/pateketrueke/json-schema-faker) [![NPM version](https://badge.fury.io/js/json-schema-faker.png)](http://badge.fury.io/js/json-schema-faker) [![Coverage Status](https://coveralls.io/repos/pateketrueke/json-schema-faker/badge.png?branch=master)](https://coveralls.io/r/pateketrueke/json-schema-faker?branch=master)
`json-schema-faker` supports (currently) the JSON-Schema specification **draft-04** only (?) [![npm version](https://badge.fury.io/js/json-schema-faker.svg)](http://badge.fury.io/js/json-schema-faker)
`json-schema-faker` supports (currently) the JSON-Schema specification **draft-04** only.
```javascript ```javascript
var jsf = require('json-schema-faker'); var jsf = require('json-schema-faker');
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
{ {
"name": "json-schema-faker", "name": "json-schema-faker",
"version": "0.1.6", "version": "0.1.8",
"description": "JSON-Schema + Faker", "description": "JSON-Schema + Faker",
"main": "lib/index.js", "main": "lib/index.js",
"author": { "author": {
"name": "Alvaro Cabrera", "name": "Alvaro Cabrera",
"email": "pateketrueke@gmail.com" "email": "pateketrueke@gmail.com"
}, },
"contributors": [{
"name": "Tomasz Ducin",
"email": "tomasz.ducin@gmail.com",
"url": "http://ducin.it"
}],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/pateketrueke/json-schema-faker" "url": "https://github.com/pateketrueke/json-schema-faker"
...@@ -23,7 +28,7 @@ ...@@ -23,7 +28,7 @@
"z-schema": "^3.3.1" "z-schema": "^3.3.1"
}, },
"dependencies": { "dependencies": {
"chance": "^0.7.4", "chance": "^0.7.5",
"deref": "^0.2.8", "deref": "^0.2.8",
"faker": "^2.1.2", "faker": "^2.1.2",
"randexp": "^0.4.0" "randexp": "^0.4.0"
......
module.exports = {
extend: function (faker) {
faker.locale = "de";
faker.mixin = function (namespace, fnObject) {
faker[namespace] = fnObject;
};
faker.mixin('custom', {
statement: function (length) {
return faker.name.firstName() + " has " + faker.finance.amount() + " on " + faker.finance.account(length) + ".";
}
});
return faker;
},
register: function(jsfaker) {
return jsfaker.customize('faker', this.extend);
}
};
[
{
"description": "generated extended faker",
"tests": [
{
"description": "should handle faker.custom.statement",
"schema": {
"type": "string",
"faker": {
"custom.statement": [19]
}
},
"valid": true,
"require": "core/customize/faker-extend"
}
]
}
]
module.exports = {
register: function (jsf) {
return jsf.formats({
semver: function (gen, schema) {
return gen.randexp('\\d\\.\\d\\.[1-9]\\d?');
}
});
}
};
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"type": "string", "type": "string",
"format": "semver" "format": "semver"
}, },
"valid": true "valid": true,
"require": "core/formats/semver"
}, },
{ {
"description": "should support faker/chance on numeric types", "description": "should support faker/chance on numeric types",
......
...@@ -3,7 +3,7 @@ clone = require('clone') ...@@ -3,7 +3,7 @@ clone = require('clone')
ZSchema = require('z-schema') ZSchema = require('z-schema')
JaySchema = require('jayschema') JaySchema = require('jayschema')
formatValidators = require('./formats').validate formatValidators = require('./validator').validate
[tv4, ZSchema].map formatValidators [tv4, ZSchema].map formatValidators
......
...@@ -3,8 +3,6 @@ glob = require('glob') ...@@ -3,8 +3,6 @@ glob = require('glob')
deref = require('deref') deref = require('deref')
jsfaker = require('../lib') jsfaker = require('../lib')
require('./formats').register(jsfaker)
pick = (obj, key) -> pick = (obj, key) ->
parts = key.split('.') parts = key.split('.')
obj = obj[parts.shift()] while parts.length obj = obj[parts.shift()] while parts.length
...@@ -39,6 +37,9 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) -> ...@@ -39,6 +37,9 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) ->
error = '' error = ''
sample = try sample = try
if test.require
wrapper = require('./' + test.require)
wrapper.register(jsfaker)
jsfaker(schema, refs) jsfaker(schema, refs)
catch e catch e
error = e.message error = e.message
...@@ -60,6 +61,7 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) -> ...@@ -60,6 +61,7 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) ->
refs = [schema] if schema.id refs = [schema] if schema.id
expect(sample).toHaveSchema schema, refs expect(sample).toHaveSchema schema, refs
catch e catch e
console.log JSON.stringify(schema, null, 2) console.log suite.description
console.log JSON.stringify(sample, null, 2) console.log 'schema', JSON.stringify(schema, null, 2)
console.log 'sample', JSON.stringify(sample, null, 2)
throw e throw e
semver = require('semver') semver = require('semver')
module.exports = module.exports =
register: (jsf) ->
jsf.formats
semver: (gen, schema) ->
gen.randexp '\\d\\.\\d\\.[1-9]\\d?'
validate: (v) -> validate: (v) ->
registry = v.addFormat or v.registerFormat registry = v.addFormat or v.registerFormat
msgOnFail = not v.registerFormat msgOnFail = not v.registerFormat
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment