-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
113 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,35 @@ | ||
"use strict"; | ||
|
||
var fs = require('fs-promise'); | ||
var yaml = require('js-yaml'); | ||
|
||
var me = {}; | ||
|
||
me.setIfFileExists = function setIfFileExists(fileName, outObject, outProperty, options) { | ||
return fs.exists(fileName).then(function(exists) { | ||
if(exists) { return fs.readFile(fileName, (options || {encoding:'utf8'})); } | ||
return { notExists: true }; | ||
}).then(function(content) { | ||
if(! content.notExists) { | ||
outObject[outProperty] = content; | ||
} | ||
}); | ||
} | ||
|
||
me.loadYamlIfFileExists = function loadYamlIfFileExists(fileName) { | ||
var res = {}; | ||
return me.setIfFileExists(fileName, res, 'all').then(function() { | ||
return yaml.safeLoad(res.all || {}); | ||
}); | ||
} | ||
|
||
me.defaultExpectedResult; | ||
|
||
me.loadDefaultExpectedResult = function loadDefaultExpectedResult() { | ||
if(me.defaultExpectedResult) { return Promise.resolve(me.defaultExpectedResult); } | ||
return me.loadYamlIfFileExists('./test/fixtures/_default_.result.yaml').then(function(yml) { | ||
me.defaultExpectedResult = yml; | ||
}); | ||
} | ||
|
||
module.exports = me; |
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