[ADDED] font LICENSE
[REFACTOR] use mocha sugar free and integrate benchmark into the test
This commit is contained in:
parent
93f32dca01
commit
0532d6b528
|
@ -0,0 +1,2 @@
|
|||
license: free
|
||||
website: http://www.moorstation.org/typoasis/designers/gemnew/home.htm
|
|
@ -4,7 +4,7 @@
|
|||
"description": "generate svg captcha in node.js or express.js",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"test": "mocha test/test.js",
|
||||
"lint": "xo",
|
||||
"test:visual": "node test-visual.js"
|
||||
},
|
||||
|
@ -33,6 +33,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^2.5.3",
|
||||
"mocha-sugar-free": "^1.3.1",
|
||||
"xo": "^0.16.0"
|
||||
},
|
||||
"xo": {
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
const svgCaptcha = require('../');
|
||||
|
||||
console.time('generate 100 images');
|
||||
for (var i = 0; i < 100; i++) {
|
||||
var text = svgCaptcha.randomText();
|
||||
svgCaptcha(text);
|
||||
}
|
||||
console.timeEnd('generate 100 images');
|
26
test/test.js
26
test/test.js
|
@ -1,12 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const mochaSugar = require('mocha-sugar-free');
|
||||
const svgCaptcha = require('../');
|
||||
|
||||
const describe = mochaSugar.describe;
|
||||
const it = mochaSugar.it;
|
||||
|
||||
const xmlReg = /^<svg[\s\S]+\/svg>$/;
|
||||
const textTagReg = /text/;
|
||||
|
||||
describe('svg captcha', function () {
|
||||
it('should generate random text', function () {
|
||||
for (var i = 0; i < 62; i++) {
|
||||
var text = svgCaptcha.randomText();
|
||||
for (let i = 0; i < 62; i++) {
|
||||
let text = svgCaptcha.randomText();
|
||||
assert(/^[0-9a-zA-Z]+$/.test(text));
|
||||
}
|
||||
});
|
||||
|
@ -15,6 +22,20 @@ describe('svg captcha', function () {
|
|||
assert(xmlReg.test(svgCaptcha()));
|
||||
assert(xmlReg.test(svgCaptcha({text: 'abcd'})));
|
||||
});
|
||||
|
||||
it('should generate path', function () {
|
||||
assert(!textTagReg.test(svgCaptcha({text: 'text'})));
|
||||
});
|
||||
|
||||
it('should be fast', function () {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
let text = svgCaptcha.randomText();
|
||||
svgCaptcha(text);
|
||||
}
|
||||
}, {
|
||||
slow: 50,
|
||||
timeout: 100
|
||||
});
|
||||
});
|
||||
|
||||
const random = require('../lib/random');
|
||||
|
@ -26,6 +47,7 @@ describe('random function', function () {
|
|||
assert(num >= 0 && num <= 10);
|
||||
}
|
||||
});
|
||||
|
||||
it('should generate grey color', function () {
|
||||
assert(random.greyColor());
|
||||
assert(random.greyColor(3, 4));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const fs = require('fs');
|
||||
const svg = require('../');
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
fs.writeFile(`test${i}.svg`, svg(svg.randomText()), 'utf8', function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
|
Loading…
Reference in New Issue