🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

raml2code-fixtures

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raml2code-fixtures - npm Package Compare versions

Comparing version
0.0.6
to
0.0.7
+5
-1
package.json
{
"name": "raml2code-fixtures",
"version": "0.0.6",
"version": "0.0.7",
"description": "fixtures for raml2code",

@@ -23,3 +23,7 @@ "main": "test-utils.js",

"skeemas": "^1.1.4"
},
"devDependencies": {
"gulp-util": "^3.0.4",
"raml2code": "^0.8.41"
}
}
+110
-75

@@ -1,21 +0,23 @@

var path = require('path');
var codeReferences = path.join(__dirname, 'code-reference/');
var raml = require('raml-parser');
var chai = require('chai');
var _ = require('lodash');
var should = chai.should();
var expect = require('chai').expect;
var fs = require('fs');
var Glob = require("glob");
var data2Code = require('data2code');
var path = require('path'),
codeReferences = path.join(__dirname, 'code-reference/'),
raml = require('raml-parser'),
chai = require('chai'),
_ = require('lodash'),
should = chai.should(),
expect = require('chai').expect,
fs = require('fs'),
Glob = require("glob"),
data2Code = require('data2code'),
raml2code = require('raml2code'),
gutil = require('gulp-util');
var helpersUtil = {};
helpersUtil.ramlPath = path.join(__dirname, 'raml/');
var ramlPath = path.join(__dirname, 'raml/');
exports.ramlPath = ramlPath;
helpersUtil.readRaml = function (filename) {
return raml.loadFile(helpersUtil.ramlPath + filename)
var readRaml = function (filename) {
return raml.loadFile(ramlPath + filename)
};
helpersUtil.wrapAssertion = function (fn, done) {
var wrapAssertion = function (fn, done) {
try {

@@ -25,31 +27,13 @@ fn();

done(e);
return e;
}
};
helpersUtil.runSimpleTest = function (raml, generator, extra, sampleFile, validateWith, logContent ) {
exports.wrapAssertion = wrapAssertion;
return function(done){
helpersUtil.loadFixtureRaml(raml, function(data, done){
var loadFixtureRaml = function (raml, fn, done) {
helpersUtil.wrapAssertion(function(){
logContent = logContent || false;
generator.handleRender = helpersUtil.handleRender.bind(undefined, done, sampleFile, validateWith, logContent);
data.extra = extra;
data2Code.process(data, generator);
done()
},done);
}, done);
}
};
helpersUtil.loadFixtureRaml = function (raml, fn, done) {
var p1 = helpersUtil.readRaml(raml);
var p1 = readRaml(raml);
p1.then(function (ramlData) {
helpersUtil.wrapAssertion(function () {
wrapAssertion(function () {
fn(ramlData, done);

@@ -63,21 +47,3 @@ }, done);

helpersUtil.loadSchemasAndRun = function (fn, done, file) {
var testSchemas;
if(file === undefined){
testSchemas = path.join(__dirname, 'schemas/') + "**/*schema.json";
}else{
testSchemas = path.join(__dirname, 'schemas/') + file
}
var wrap = function (err, schemas) {
helpersUtil.wrapAssertion(function () {
fn(err, schemas, done);
}, done)
};
new Glob(testSchemas, {}, helpersUtil.readSchemas(wrap, done));
};
helpersUtil.readSchemas = function (fn, done) {
var readSchemas = function (fn, done) {
return function (err, files) {

@@ -95,16 +61,5 @@ try {

helpersUtil.handleRender = function (done, sampleFile, validateWith, logContent, results) {
var compareContents = function (content, fixtureName, logContent) {
var validateWithContent = _.find(results, function (arr) {
return arr[validateWith] !== undefined
});
helpersUtil.compareContents({body: validateWithContent[validateWith], name: validateWith}, sampleFile, logContent);
};
helpersUtil.compareContents = function (content, fixtureName, logContent) {
if (logContent) {

@@ -116,3 +71,3 @@ console.log("=================" + content.name + "================")

if(fixtureName !== undefined){
if (fixtureName !== undefined) {

@@ -131,9 +86,8 @@ var sampleFileFs = codeReferences + fixtureName;

var validateDataWithFixture = function (done, sampleFile, validateWith, logContent, file) {
helpersUtil.validateDataWithFixture = function (done, sampleFile, validateWith, logContent, file) {
helpersUtil.wrapAssertion(function () {
return wrapAssertion(function () {
if (file.path == validateWith) {
var content = file.contents.toString('utf8');
helpersUtil.compareContents({body: content, name: file.path}, sampleFile, logContent);
compareContents({body: content, name: file.path}, sampleFile, logContent);
}

@@ -144,2 +98,83 @@ }, done);

module.exports = helpersUtil;
exports.runSimpleTest = function (raml, generator, extra, sampleFile, validateWith, logContent) {
return function (done) {
loadFixtureRaml(raml, function (data, done) {
wrapAssertion(function () {
logContent = logContent || false;
generator.handleRender = handleRender.bind(undefined, done, sampleFile, validateWith, logContent);
data.extra = extra;
data2Code.process(data, generator);
done();
}, done);
}, done);
}
};
exports.loadSchemasAndRun = function (fn, done, file) {
var testSchemas;
if (file === undefined) {
testSchemas = path.join(__dirname, 'schemas/') + "**/*schema.json";
} else {
testSchemas = path.join(__dirname, 'schemas/') + file
}
var wrap = function (err, schemas) {
wrapAssertion(function () {
fn(err, schemas, done);
}, done)
};
new Glob(testSchemas, {}, readSchemas(wrap, done));
};
var handleRender = function (done, sampleFile, validateWith, logContent, results) {
var validateWithContent = _.find(results, function (arr) {
return arr[validateWith] !== undefined
});
compareContents({body: validateWithContent[validateWith], name: validateWith}, sampleFile, logContent);
};
exports.handleRender = handleRender;
exports.raml2codeIntegration = function (done, ramlFile, generator, extra, sampleFile, validateWith, logContent) {
logContent = logContent || false;
var raml2codeInstance = raml2code({generator: generator, extra: extra});
var innerRamlPath = ramlPath + ramlFile;
var ramlContents = fs.readFileSync(innerRamlPath);
raml2codeInstance.write(new gutil.File({
path: innerRamlPath,
contents: ramlContents
}));
raml2codeInstance.on('data', function (file) {
if (file.path === validateWith) {
var e = validateDataWithFixture(done, sampleFile, validateWith, logContent, file);
if(e === undefined || e === null){
done();
}
}
});
raml2codeInstance.on('error', function (error) {
console.log("raml2code integration error", error);
done(error);
});
};