Skip to content
Snippets Groups Projects
Commit 9bd5fe3a authored by Alvaro Cabrera's avatar Alvaro Cabrera
Browse files

Merge remote-tracking branch 'tkoomzaask/extending-dependencies' into develop

Conflicts:
	README.md
	package.json
parents b0b5db83 afc4bd60
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ language: node_js
branches:
only:
- master
- extending-dependencies
node_js:
- 0.10
before_script:
......
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.
......@@ -7,6 +7,11 @@
"name": "Alvaro Cabrera",
"email": "pateketrueke@gmail.com"
},
"contributors": [{
"name": "Tomasz Ducin",
"email": "tomasz.ducin@gmail.com",
"url": "http://ducin.it"
}],
"repository": {
"type": "git",
"url": "https://github.com/pateketrueke/json-schema-faker"
......@@ -23,7 +28,7 @@
"z-schema": "^3.9.5"
},
"dependencies": {
"chance": "^0.7.4",
"chance": "^0.7.5",
"deref": "^0.3.0",
"faker": "^2.1.2",
"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 @@
"type": "string",
"format": "semver"
},
"valid": true
"valid": true,
"require": "core/formats/semver"
},
{
"description": "should support faker/chance on numeric types",
......
......@@ -3,7 +3,7 @@ clone = require('clone')
ZSchema = require('z-schema')
JaySchema = require('jayschema')
formatValidators = require('./formats').validate
formatValidators = require('./validator').validate
[tv4, ZSchema].map formatValidators
......
......@@ -2,8 +2,6 @@ fs = require('fs')
glob = require('glob')
jsfaker = require('../lib')
require('./formats').register(jsfaker)
pick = (obj, key) ->
parts = key.split('.')
obj = obj[parts.shift()] while parts.length
......@@ -38,6 +36,9 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) ->
error = ''
sample = try
if test.require
wrapper = require('./' + test.require)
wrapper.register(jsfaker)
jsfaker(schema, refs)
catch e
error = e.message
......@@ -56,6 +57,7 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) ->
try
expect(sample).toHaveSchema schema, refs
catch e
console.log JSON.stringify(schema, null, 2)
console.log JSON.stringify(sample, null, 2)
console.log suite.description
console.log 'schema', JSON.stringify(schema, null, 2)
console.log 'sample', JSON.stringify(sample, null, 2)
throw e
semver = require('semver')
module.exports =
register: (jsf) ->
jsf.formats
semver: (gen, schema) ->
gen.randexp '\\d\\.\\d\\.[1-9]\\d?'
validate: (v) ->
registry = v.addFormat or 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