From 8c5826175d497605a82bdf90ce9f049d64366c0d Mon Sep 17 00:00:00 2001 From: SIPS1980 Date: Sun, 9 Jun 2019 10:01:46 -0400 Subject: [PATCH] Update Tests --- Makefile | 6 ++++++ index.js | 26 +++++++++++--------------- test/default.js | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 2f633a2..ca8168a 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,15 @@ GITHUB_PROJ := https://github.com//camelaissani//markdown-it-include lint: ./node_modules/.bin/eslint . +lintWin10PS: + .\node_modules\.bin\eslint . + test: lint ./node_modules/.bin/mocha -R spec +testWin10PS: lintWin10PS + .\node_modules\.bin\mocha -R spec + coverage: rm -rf coverage ./node_modules/.bin/istanbul cover node_modules/.bin/_mocha diff --git a/index.js b/index.js index 1771c21..27590f4 100644 --- a/index.js +++ b/index.js @@ -18,9 +18,9 @@ module.exports = function include_plugin(md, options) { } else { root = options.root || root; includeRe = options.includeRe || includeRe; - throwError = options.throwError === undefined ? throwError : options.throwError; - notFoundMessage = options.notFoundMessage === undefined ? notFoundMessage : options.notFoundMessage; - circularMessage = options.circularMessage === undefined ? circularMessage : options.circularMessage; + throwError = options.throwError || throwError; + notFoundMessage = options.notFoundMessage || notFoundMessage; + circularMessage = options.circularMessage || circularMessage; } } @@ -34,25 +34,21 @@ module.exports = function include_plugin(md, options) { } while ((cap = includeRe.exec(src))) { filePath = path.resolve(rootdir, cap[1].trim()); - mdSrc = undefined; + mdSrc = ''; - // check if child file exists + // check if child file exists or if there is a circular reference if (fs.existsSync(filePath) === false) { // child file does not exist mdSrc = notFoundMessage.replace('{{FILE}}', filePath); - } else { - // check if circular reference - if (filesProcessed.indexOf(filePath) !== -1) { - mdSrc = circularMessage.replace('{{FILE}}', filePath).replace('{{PARENT}}', parentFilePath) - } + } else if (filesProcessed.indexOf(filePath) !== -1) { + // reference would be circular + mdSrc = circularMessage.replace('{{FILE}}', filePath).replace('{{PARENT}}', parentFilePath); } // check if there were any errors and / or ensure error message is not empty - if (mdSrc !== undefined) { - if (throwError === true && mdSrc !== '') { - throw new Error(mdSrc) - } - } else { + if (mdSrc !== '' && throwError === true) { + throw new Error(mdSrc); + } else if (mdSrc === '') { // get content of child file mdSrc = fs.readFileSync(filePath, 'utf8'); // check if child file also has includes diff --git a/test/default.js b/test/default.js index 4c3ceaf..75b4d47 100644 --- a/test/default.js +++ b/test/default.js @@ -61,7 +61,7 @@ describe('plugin', function () { assert.throws(function () { md.render('!!! include( xxx.md ) !!!'); - }, Error, /ENOENT/); + }, Error, /not found/i); }); it ('direct circular reference', function () {