Browse Source

Use separate package for spec tests generation

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
8f288565af
  1. 1
      package.json
  2. 4
      test/commonmark.js
  3. 6
      test/markdown-it.js
  4. 46
      test/utils.js

1
package.json

@ -35,6 +35,7 @@
"eslint-plugin-nodeca": "^1.0.0",
"istanbul": "*",
"jade": "^1.6.0",
"markdown-it-testgen": "~ 0.1.0",
"marked": "0.3.2",
"stylus": "^0.49.1",
"mocha": "*",

4
test/commonmark.js

@ -4,11 +4,11 @@
var path = require('path');
var utils = require('./utils');
var generate = require('markdown-it-testgen');
describe('CommonMark', function () {
var md = require('../')('commonmark');
utils.addTests(path.join(__dirname, 'fixtures/commonmark/good.txt'), md);
generate(path.join(__dirname, 'fixtures/commonmark/good.txt'), md);
});

6
test/markdown-it.js

@ -4,10 +4,10 @@
var path = require('path');
var utils = require('./utils');
var generate = require('markdown-it-testgen');
describe('markdownit', function () {
describe('markdown-it', function () {
var md = require('../')('full', {
html: true,
langPrefix: '',
@ -15,5 +15,5 @@ describe('markdownit', function () {
linkify: true
});
utils.addTests(path.join(__dirname, 'fixtures/markdown-it'), md);
generate(path.join(__dirname, 'fixtures/markdown-it'), md);
});

46
test/utils.js

@ -1,46 +0,0 @@
'use strict';
var fs = require('fs');
var path = require('path');
var assert = require('assert');
function addTests(fPath, markdown, skip) {
var input,
stat = fs.statSync(fPath);
if (stat.isFile()) {
input = fs.readFileSync(fPath, 'utf8');
input = input.replace(/→/g, '\t');
describe(fPath, function () {
input.replace(/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$/gm, function(__, md, html, offset, orig) {
var line = orig.slice(0, offset).split(/\r?\n/g).length;
// Also skip tests if file name starts with "_"
if (!skip && path.basename(fPath)[0] !== '_') {
it('line ' + line, function () {
assert.strictEqual(html, markdown.render(md));
});
} else {
it.skip('line ' + line, function () {
assert.strictEqual(html, markdown.render(md));
});
}
});
});
return;
}
if (stat.isDirectory()) {
fs.readdirSync(fPath).forEach(function (name) {
addTests(path.join(fPath, name), markdown, skip);
});
}
}
module.exports.addTests = addTests;
Loading…
Cancel
Save