[ADDED] font LICENSE

[REFACTOR] use mocha sugar free and integrate benchmark into the test
This commit is contained in:
Weilin 2016-08-10 09:31:20 +08:00
parent 93f32dca01
commit 0532d6b528
5 changed files with 29 additions and 12 deletions

2
fonts/LICENSE.md Normal file
View File

@ -0,0 +1,2 @@
license: free
website: http://www.moorstation.org/typoasis/designers/gemnew/home.htm

View File

@ -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": {

View File

@ -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');

View File

@ -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));

View File

@ -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);