forked from zuriby/Faker.js
-
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.
[test] Add
faker.fake
functional tests #386
- Now running all methods through faker.fake - Adds coverage for scope issues #376 - Refactors functional test methods to helper
- Loading branch information
Showing
3 changed files
with
111 additions
and
34 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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
if (typeof module !== 'undefined') { | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var faker = require('../../index'); | ||
} | ||
|
||
var functionHelpers = {}; | ||
|
||
module.exports = functionHelpers; | ||
|
||
|
||
var IGNORED_MODULES = ['locales', 'locale', 'localeFallback', 'definitions', 'fake', 'helpers']; | ||
var IGNORED_METHODS = { | ||
system: ['directoryPath', 'filePath'] // these are TODOs | ||
}; | ||
|
||
function isTestableModule(mod) { | ||
return IGNORED_MODULES.indexOf(mod) === -1; | ||
} | ||
|
||
function isMethodOf(mod) { | ||
return function(meth) { | ||
return typeof faker[mod][meth] === 'function'; | ||
}; | ||
} | ||
|
||
function isTestableMethod(mod) { | ||
return function(meth) { | ||
return !(mod in IGNORED_METHODS && IGNORED_METHODS[mod].indexOf(meth) >= 0); | ||
}; | ||
} | ||
|
||
function both(pred1, pred2) { | ||
return function(value) { | ||
return pred1(value) && pred2(value); | ||
}; | ||
} | ||
|
||
// Basic smoke tests to make sure each method is at least implemented and returns a value. | ||
|
||
functionHelpers.modulesList = function modulesList () { | ||
var modules = Object.keys(faker) | ||
.filter(isTestableModule) | ||
.reduce(function(result, mod) { | ||
result[mod] = Object.keys(faker[mod]).filter(both(isMethodOf(mod), isTestableMethod(mod))); | ||
return result; | ||
}, {}); | ||
|
||
return modules; | ||
} |