This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
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
1 parent
54337ec
commit 91f7607
Showing
3 changed files
with
69 additions
and
1 deletion.
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,6 @@ | ||
language: node_js | ||
node_js: | ||
- "4" | ||
- "6" | ||
after_script: | ||
- coveralls < coverage/lcov.info |
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,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/); | ||
} | ||
}); | ||
}); |