@gkotulski/doc_preprocessing
Version:
Preprocess 4D doc to be built by docusaurus
87 lines (76 loc) • 2.76 kB
JavaScript
const preproc = require("../lib/preprocessor")
var assert = require('chai').assert;
const glob = require("glob")
const fs = require('fs');
var rmDir = function(dir, rmSelf) {
var files;
rmSelf = (rmSelf === undefined) ? true : rmSelf;
dir = dir + "/";
try { files = fs.readdirSync(dir); } catch (e) { console.log("!Oops, directory not exist."); return; }
if (files.length > 0) {
files.forEach(function(x, i) {
if (fs.statSync(dir + x).isDirectory()) {
rmDir(dir + x);
} else {
fs.unlinkSync(dir + x);
}
});
}
if (rmSelf) {
// check if user want to delete the directory ir just the files in this directory
fs.rmdirSync(dir);
}
}
describe('Preprocessor', function() {
describe('References', function() {
const folderPath = "./test/Resources/Test_Ref/"
var p = new preproc.Preprocessing(folderPath, ".")
p.collect()
it('Number of references', function() {
const map = p._refManager._ref
assert.equal(map.size,3)
});
it('List of references', function() {
const map = p._refManager._ref
let ref = map.get("ref1")
assert.equal(ref.content.trim(), "Testref1")
assert.equal(ref.content, "Testref1")
assert.equal(ref.filePath, folderPath + "ref.md")
ref = map.get("ref2")
assert.equal(ref.content.trim(), "Testref2")
assert.isAbove(ref.content.length, "Testref2".length)
assert.equal(ref.content.search("Testref2"), 0)
ref = map.get("ref3")
assert.equal(ref.content.trim(), "Testref3")
assert.isAbove(ref.content.length, "Testref3".length)
assert.isAbove(ref.content.search("Testref3"), 0)
});
});
describe('After post process', function() {
const folderPath = "./test/Resources/"
const dest = "./test/OUTPUT/"
if(fs.existsSync(dest))
rmDir(dest);
var p = new preproc.Preprocessing(folderPath, dest)
p.run()
it('Files consistency', function() {
var bi = 0
fs.readdirSync(folderPath).forEach(file => {
bi++
});
var ai = 0
fs.readdirSync(dest).forEach(file => {
ai++
});
assert.notEqual(ai, 0)
assert.equal(bi, ai)
});
it('Check include', function() {
const content = fs.readFileSync(dest + "Test_Include/include.md")
const map = p._refManager._ref
for(var [key, value] in map) {
assert.notEqual(content.search(value.content), -1)
}
});
});
});