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

Improved test-loop for better debug

parent f8f33f78
Branches
Tags
No related merge requests found
...@@ -22,6 +22,10 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) -> ...@@ -22,6 +22,10 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) ->
describe "#{suite.description} (#{file.replace(__dirname + '/', '')})", -> describe "#{suite.description} (#{file.replace(__dirname + '/', '')})", ->
suite.tests.forEach (test) -> suite.tests.forEach (test) ->
it test.description, -> it test.description, ->
if test.require
wrapper = require('./' + test.require)
wrapper.register(jsfaker)
schema = if typeof test.schema is 'string' schema = if typeof test.schema is 'string'
pick(suite, test.schema) pick(suite, test.schema)
else else
...@@ -33,15 +37,12 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) -> ...@@ -33,15 +37,12 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) ->
else else
ref ref
error = '' error = null
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 = String(e)
throw e unless test.throws throw e unless test.throws
if test.hasNot if test.hasNot
...@@ -51,13 +52,25 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) -> ...@@ -51,13 +52,25 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) ->
expect(sample).toHaveType test.type expect(sample).toHaveType test.type
if typeof test.throws is 'string' if typeof test.throws is 'string'
expect(error).toMatch new RegExp('^' + test.throws + '$', 'i') if typeof error isnt 'string'
throw """
THIS SHOULD NOT HAPPEN --- #{error}
#{JSON.stringify(schema, null, 2)}
#{JSON.stringify(sample, null, 2)}
"""
expect(error).toMatch new RegExp(test.throws, 'i')
if test.valid if test.valid
try try
expect(sample).toHaveSchema schema, refs expect(sample).toHaveSchema schema, refs
catch e catch e
console.log suite.description throw """
console.log 'schema', JSON.stringify(schema, null, 2) #{suite.description} (#{e})
console.log 'sample', JSON.stringify(sample, null, 2)
throw e #{JSON.stringify(schema, null, 2)}
#{JSON.stringify(sample, null, 2)}
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment