Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

67 fix option report not mentioned #69

Merged
merged 3 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions conf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"description": "Report on terms which exist in a glossary but have neither been mentioned directly nor with any of its aliases.",
"type": "boolean",
"alias": "",
"default": true
"default": false
},
"dev": {
"descriptions": "Options for testing and debugging",
Expand Down Expand Up @@ -173,21 +173,25 @@
"DevOpts": {
"type": "object",
"properties": {
"termsFile": {
"description": "File where to write term book to. Enables testing the term extraction results of terminator.",
"type": "string"
},
"reproducablePaths": {
"description": "Write system-independent paths into 'termsFile' to produce reproducable output accross environments.",
"type": "boolean"
},
"printInputAst": {
"description": "Print the AST of scanned markdown documents prior to linkification. May be a Regex to only print AST for particular document.",
"type": ["boolean", "string"]
},
"printOutputAst": {
"description": "Print the AST of scanned markdown documents after linkification. May be a Regex to only print AST for particular document.",
"type": ["boolean", "string"]
},
"reportsFile": {
"description": "File where to write console report output. Enables testing the report output generated by the 'writer' component.",
"type": "string"
},
"reproducablePaths": {
"description": "Write system-independent paths into 'termsFile' to produce reproducable output accross environments.",
"type": "boolean"
},
"termsFile": {
"description": "File where to write term book to. Enables testing the term extraction results of the 'terminator' component.",
"type": "string"
}
}
}
Expand Down
60 changes: 36 additions & 24 deletions lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,19 @@ api.writeMarkdownFile = function writeMarkdownFile(context, mdAst, filename) {
};

api.writeReport = function(context) {
const {terms: dict} = context;
let report = "";
dict.inOrder()
.filter((term) => term.countOccurrenceTotal === 0)
.forEach((term) => {
report += `☛ ${term.glossary.file}: "${term.term}" has not been mentioned or has been mentioned only by unknown aliases.
const {opts, terms: dict} = context;
const {reportNotMentioned} = opts;
if (reportNotMentioned) {
let report = "";
dict.inOrder()
.filter((term) => term.countOccurrenceTotal === 0)
.forEach((term) => {
report += `☛ ${term.glossary.file}: "${term.term}" has not been mentioned or has been mentioned only by unknown aliases.
`;
});
console.info(`\n${report}`);
});
context.report = report;
console.info(`\n${report}`);
}
return Promise.resolve(context);
};

Expand All @@ -153,34 +157,42 @@ api.writeReport = function(context) {
* @param {} context
*/
api.writeTestOutput = function (context) {
const {terms, opts} = context;
const {baseDir, dev} = opts;
const {termsFile} = dev;
if (! termsFile) {
return;
const {terms, report, opts} = context;
const {termsFile, reportsFile} = opts.dev;
const promises = [];
if (termsFile) {
// Important! Write terms in defined order to get reliable diff.
promises.push(writeTextFile(context, termsFile, JSON.stringify(terms.inOrder(), null, 2)));
}
if (reportsFile) {
promises.push(writeTextFile(context, reportsFile, report || ""));
}
const termsFile_ = toSystemSlash(path.resolve(baseDir, termsFile));
return Promise
.all(promises)
.then(() => context);
};

function writeTextFile(context, filename, data) {
const {baseDir} = context.opts;
const filename_ = toSystemSlash(path.resolve(baseDir, filename));
return new Promise((resolve, reject) => {
const output = JSON
.stringify(terms.inOrder(), null, 2) /* [1] */
.replace("\r", "") /* [2] */
+ "\n"; /* [3] */
const output = `${data}`
.replace("\r", "") /* [1] */
+ "\n"; /* [2] */

fs.outputFile(termsFile_, output, (err) => {
fs.outputFile(filename_, output, (err) => {
err ? reject(err) : resolve(context);
});
});

// [1]: Important! Write terms in defined order to get reliable diff.
// [2]: Important! Drop carriage-return in CRLF (\r\n) windows-style
// [1]: Important! Drop carriage-return in CRLF (\r\n) windows-style
// line-endings to get LF (\n) unix-style line endings for reliable
// cross-plattform git-diffs. Also make sure a .gitattributes file
// exists in the repo with:
//
// * text eol=auto
// /test/* text eol=lf'
//
// [3]: Add newline at EOF.
};
// [2]: Add newline at EOF.
}

module.exports = api;
9 changes: 9 additions & 0 deletions test/input/config-reportNotMentioned/false/document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Testing config option 'reportNotMentioned'

GIVEN a term 'Mentioned' being mentioned
AND option `reportNotMentioned: false`
THEN the report MUST NOT list this term.

GIVEN another term being neither mentioned here nor anywhere else
AND option `reportNotMentioned: false`
THEN the report MUST NOT list anything due to reporting being disabled.
19 changes: 19 additions & 0 deletions test/input/config-reportNotMentioned/false/glossarify-md.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "../../../../conf.schema.json",
"baseDir": ".",
"linking": "relative",
"includeFiles": ["."],
"excludeFiles": [],
"reportNotMentioned": false,
"glossaries": [
{ "file": "./glossary.md"}
],
"ignoreCase": false,
"outDir": "../../../output-actual/config-reportNotMentioned/false",
"dev": {
"reportsFile": "../../../output-actual/config-reportNotMentioned/false/report.txt",
"printInputAst": false,
"reproducablePaths": true,
"printOutputAst": false
}
}
5 changes: 5 additions & 0 deletions test/input/config-reportNotMentioned/false/glossary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Testing option `reportNotMentioned`

## Mentioned

## Not-Mentioned
9 changes: 9 additions & 0 deletions test/input/config-reportNotMentioned/true/document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Testing config option 'reportNotMentioned'

GIVEN a term 'Mentioned' being mentioned
AND option `reportNotMentioned: true`
THEN the report MUST NOT list this term.

GIVEN another term being neither mentioned here nor anywhere else
AND option `reportNotMentioned: true`
THEN the report MUST list at least one term not being mentioned.
19 changes: 19 additions & 0 deletions test/input/config-reportNotMentioned/true/glossarify-md.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "../../../../conf.schema.json",
"baseDir": ".",
"linking": "relative",
"includeFiles": ["."],
"excludeFiles": [],
"reportNotMentioned": true,
"glossaries": [
{ "file": "./glossary.md"}
],
"ignoreCase": false,
"outDir": "../../../output-actual/config-reportNotMentioned/true",
"dev": {
"reportsFile": "../../../output-actual/config-reportNotMentioned/true/report.txt",
"printInputAst": false,
"reproducablePaths": true,
"printOutputAst": false
}
}
5 changes: 5 additions & 0 deletions test/input/config-reportNotMentioned/true/glossary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Testing option `reportNotMentioned`

## Mentioned

## Not-Mentioned
11 changes: 11 additions & 0 deletions test/output-expected/config-reportNotMentioned/false/document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# [Testing config option 'reportNotMentioned'](#testing-config-option-reportnotmentioned)

GIVEN a term '[Mentioned][1]' being mentioned
AND option `reportNotMentioned: false`
THEN the report MUST NOT list this term.

GIVEN another term being neither mentioned here nor anywhere else
AND option `reportNotMentioned: false`
THEN the report MUST NOT list anything due to reporting being disabled.

[1]: ./glossary.md#mentioned
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "../../../../conf.schema.json",
"baseDir": ".",
"linking": "relative",
"includeFiles": ["."],
"excludeFiles": [],
"reportNotMentioned": false,
"glossaries": [
{ "file": "./glossary.md"}
],
"ignoreCase": false,
"outDir": "../../../output-actual/config-reportNotMentioned/false",
"dev": {
"reportsFile": "../../../output-actual/config-reportNotMentioned/false/report.txt",
"printInputAst": false,
"reproducablePaths": true,
"printOutputAst": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [Testing option `reportNotMentioned`](#testing-option-reportnotmentioned)

## [Mentioned](#mentioned)

## [Not-Mentioned](#not-mentioned)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 11 additions & 0 deletions test/output-expected/config-reportNotMentioned/true/document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# [Testing config option 'reportNotMentioned'](#testing-config-option-reportnotmentioned)

GIVEN a term '[Mentioned][1]' being mentioned
AND option `reportNotMentioned: true`
THEN the report MUST NOT list this term.

GIVEN another term being neither mentioned here nor anywhere else
AND option `reportNotMentioned: true`
THEN the report MUST list at least one term not being mentioned.

[1]: ./glossary.md#mentioned
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "../../../../conf.schema.json",
"baseDir": ".",
"linking": "relative",
"includeFiles": ["."],
"excludeFiles": [],
"reportNotMentioned": true,
"glossaries": [
{ "file": "./glossary.md"}
],
"ignoreCase": false,
"outDir": "../../../output-actual/config-reportNotMentioned/true",
"dev": {
"reportsFile": "../../../output-actual/config-reportNotMentioned/true/report.txt",
"printInputAst": false,
"reproducablePaths": true,
"printOutputAst": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [Testing option `reportNotMentioned`](#testing-option-reportnotmentioned)

## [Mentioned](#mentioned)

## [Not-Mentioned](#not-mentioned)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
☛ ./glossary.md: "Not-Mentioned" has not been mentioned or has been mentioned only by unknown aliases.

2 changes: 2 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"test_25": "npx . --config ./input/config-listOfFigures/groupByHeadingDepth-2/glossarify-md.conf.json",
"test_26": "npx . --config ./input/config-listOfFigures/groupByHeadingDepth-2/glossarify-md.conf.json",
"test_27": "npx . --config ./input/config-listOfFigures/option-title-missing/glossarify-md.conf.json",
"test_28": "npx . --config ./input/config-reportNotMentioned/true/glossarify-md.conf.json",
"test_29": "npx . --config ./input/config-reportNotMentioned/false/glossarify-md.conf.json",
"postsuite": "git diff --minimal --color --no-index --ignore-cr-at-eol ./output-expected ./output-actual | node ../bin/test.js",
"new-baseline": "rm -r ./output-expected && mv ./output-actual ./output-expected",
"new-baseline-win": "del /Q .\\output-expected && rename .\\output-actual .\\output-expected",
Expand Down