Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
test: ajv transpile option
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Nov 5, 2017
1 parent 54337ec commit 91f7607
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .travis.yml
@@ -0,0 +1,6 @@
language: node_js
node_js:
- "4"
- "6"
after_script:
- coveralls < coverage/lcov.info
19 changes: 18 additions & 1 deletion package.json
Expand Up @@ -4,7 +4,9 @@
"description": "Configure async validation mode in Ajv - JSON-Schema validator",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test-spec": "mocha spec/*.spec.js -R spec",
"test-cov": "nyc npm run test-spec",
"test": "npm run test-cov"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,5 +42,20 @@
},
"dependencies": {
"nodent": "^3.1.3"
},
"devDependencies": {
"mocha": "^4.0.1",
"nyc": "^11.3.0",
"pre-commit": "^1.2.2"
},
"nyc": {
"exclude": [
"**/spec/**",
"node_modules"
],
"reporter": [
"lcov",
"text-summary"
]
}
}
45 changes: 45 additions & 0 deletions spec/transpile.spec.js
@@ -0,0 +1,45 @@
'use strict';

var Ajv = require('ajv');
var setupAsync = require('../index.js');
var assert = require('assert');


describe('transpile option', function() {
var majorNodeVersion;
if (typeof process != 'undefined')
majorNodeVersion = +process.versions.node.split('.')[0];

it('should set processCode if async not supported', function() {
var ajv = setupAsync(new Ajv);
if (majorNodeVersion >= 7)
assert.strictEqual(ajv._opts.processCode, undefined);
else
assert.equal(typeof ajv._opts.processCode, 'function');
});

it('should always set processCode if transpile: true', function() {
var ajv = setupAsync(new Ajv({ transpile: true }));
assert.equal(typeof ajv._opts.processCode, 'function');
});

it('should throw error if async not supported and transpile: false', function() {
if (majorNodeVersion >= 7) assert.doesNotThrow(test);
else assert.throws(test, /async functions not supported/);

function test() {
setupAsync(new Ajv({ transpile: false }));
}
});

it('should throw error with unknown transpile option', function() {
test('nodent');
test({});

function test(transpile) {
assert.throws(function() {
setupAsync(new Ajv({ transpile: transpile }));
}, /transpile option must be boolean or undefined/);
}
});
});

0 comments on commit 91f7607

Please sign in to comment.