This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mocha to & run integration tests by default in ci
- Loading branch information
1 parent
02062bf
commit b37bc6e
Showing
8 changed files
with
155 additions
and
169 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict' | ||
/* global describe, it, context */ | ||
|
||
/** | ||
* Integration testing module (dt2js). | ||
* Runs dt2js script for each file from EXAMPLES_FOLDER and | ||
* performs validation of output JSON. | ||
* | ||
* Errors are output to console in a form: | ||
* FAIL (type of fail): | ||
* - Error message [optional line.column range] | ||
* | ||
* If test passes it will just log 'OK'. | ||
* | ||
* Tests are launched by running this file with nodejs. | ||
*/ | ||
|
||
const helpers = require('./helpers') | ||
const path = require('path') | ||
const rewire = require('rewire') | ||
const Ajv = require('ajv') | ||
const fs = require('fs') | ||
|
||
const dt2js = rewire('../../src/dt2js') | ||
const getRAMLContext = dt2js.__get__('getRAMLContext') | ||
|
||
const EXAMPLES_FOLDER = path.join(__dirname, 'raml') | ||
|
||
const ajv = new Ajv({ allErrors: true, schemaId: 'id' }) | ||
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')) | ||
|
||
/** | ||
* Log JSON validation errors. | ||
*/ | ||
function logValidationError () { | ||
const sep = '||' | ||
const errorsText = ajv.errorsText(ajv.errors, {'separator': sep}) | ||
const errors = errorsText.split(sep) | ||
console.log('FAIL (JSON validation):') | ||
errors.forEach(function (el) { | ||
console.log('-', el) | ||
}) | ||
} | ||
|
||
// FIXME: commented out line in complex_homeanimal.raml | ||
|
||
describe('dt2js integration test', () => { | ||
helpers.forEachFileIn(EXAMPLES_FOLDER, (filepath) => { | ||
/** | ||
* Test file by running js2dt script on it and then validating | ||
* with raml-1-parser. | ||
*/ | ||
context(`for file ${filepath}`, () => { | ||
const ramlData = fs.readFileSync(filepath).toString() | ||
dt2js.setBasePath(__dirname) | ||
const ctx = getRAMLContext(ramlData, __dirname) | ||
for (const typeName in ctx) { | ||
it(`should convert ${typeName}`, () => { | ||
const schema = dt2js.dt2js(ramlData, typeName) | ||
const valid = ajv.validateSchema(schema) | ||
if (!valid) { | ||
logValidationError() | ||
throw new Error('Invalid json') | ||
} | ||
// dt2js.dt2js(ramlData, typeName, function (err, schema) { | ||
// if (err) return done(err) | ||
// | ||
// try { | ||
// const valid = ajv.validateSchema(schema) | ||
// if (!valid) { | ||
// logValidationError() | ||
// return done(new Error('Invalid json')) | ||
// } | ||
// } catch (error) { | ||
// return done(error) | ||
// } | ||
// done() | ||
// }) | ||
}) | ||
} | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
'use strict' | ||
/* global describe, it */ | ||
|
||
/** | ||
* Integration testing module (js2dt). | ||
* Runs js2dt script for each file from EXAMPLES_FOLDER and | ||
* performs validation of output RAML. | ||
* | ||
* Errors are output to console in a form: | ||
* FAIL (type of fail): | ||
* - Error message [optional line.column range] | ||
* | ||
* If test passes it will just log 'OK'. | ||
* | ||
* Tests are launched by running this file with nodejs. | ||
*/ | ||
|
||
const { js2dt } = require('../../src/js2dt') | ||
const helpers = require('./helpers') | ||
const path = require('path') | ||
const parser = require('raml-1-parser') | ||
const fs = require('fs') | ||
|
||
const EXAMPLES_FOLDER = path.join(__dirname, 'json') | ||
|
||
/** | ||
* Log RAML validation error. | ||
*/ | ||
function logValidationError (error) { | ||
console.log('FAIL (RAML validation):') | ||
error.parserErrors.forEach(function (el) { | ||
const errMessage = '- ' + el.message + ' [' + | ||
el.range.start.line + '.' + el.range.start.column + ':' + | ||
el.range.end.line + '.' + el.range.end.column + ']' | ||
console.log(errMessage) | ||
}) | ||
} | ||
|
||
describe('js2dt integration test', () => { | ||
helpers.forEachFileIn(EXAMPLES_FOLDER, (filepath) => { | ||
/** | ||
* Test file by running js2dt script on it and then validating | ||
* with raml-1-parser. | ||
*/ | ||
it(`should convert ${filepath}`, () => { | ||
const jsonData = fs.readFileSync(filepath).toString() | ||
const typeName = 'TestType' | ||
|
||
let raml = js2dt(jsonData, typeName) | ||
|
||
console.log(raml) | ||
|
||
try { | ||
raml = '#%RAML 1.0 Library\n' + raml | ||
parser.parseRAMLSync(raml, {'rejectOnErrors': true}) | ||
} catch (error) { | ||
logValidationError(error) | ||
throw error | ||
} | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
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