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

JUnit #103

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

JUnit #103

Show file tree
Hide file tree
Changes from 5 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
36 changes: 34 additions & 2 deletions markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,37 @@ function printResult(lintResult) {
process.exitCode = 1;
}

if (program.output) {
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
if (program.junit) {
const builder = require('junit-report-builder');
const suite = builder
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
.testSuite()
.name('Markdownlint')
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
.timestamp(new Date().toISOString());
if (results.length > 0) {
results.forEach(result => {
const {file, lineNumber, column, names, description} = result;
const columnText = column ? `:${column}` : '';
suite
.testCase()
.className(file)
.name(`${file}:${lineNumber}${columnText} ${names}`)
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
.failure(`${file}:${lineNumber}${columnText} ${names} ${description}`, names)
.time(0);
});
} else {
suite.testCase().className(program.args).name('Markdownlint');
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
DavidAnson marked this conversation as resolved.
Show resolved Hide resolved
}

suite.time(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand the difference between timestamp above and time(0) here and above?

Copy link
Author

@FISHMANPET FISHMANPET Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. The JUnit format has a timestamp indicating when the Test Suite was started, and then Time indicates the time (in seconds) that the test suite took. Test cases also have a time in second, but no timestamp to indicate when they started. The fact that testSuite.time(0) is here is I think a relic of when I was trying to actually calculate the time it took to generate the report, so I couldn't set the time until the report was done. However after looking at what eslint did (just setting the time to 0) I removed the calculation but left setting it there. There's no reason why it can't be moved into the construction of the testSuite since I know the time will be 0.

But regardless of where it's defined, they're two separate values. Eslint just doesn't set the timestamp at all, but it is one of the JUnit fields, separate from time.

try {
builder.writeTo(program.junit);
} catch (error) {
console.warn('Cannot write to output file ' + program.junit + ': ' + error.message);
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
process.exitCode = 2;
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
}

console.log(lintResultString);
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
} else if (program.output) {
try {
fs.writeFileSync(program.output, lintResultString);
} catch (error) {
Expand All @@ -182,9 +212,11 @@ program
.version(pkg.version)
.description(pkg.description)
.usage('[options] <files|directories|globs>')
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
.arguments('[options] <files|directories|globs>')
.option('-f, --fix', 'fix basic errors (does not work with STDIN)')
.option('-s, --stdin', 'read from STDIN (does not work with files)')
.option('-o, --output [outputFile]', 'write issues to file (no console)')
.option('-o, --output <outputFile>', 'write issues to file (no console)')
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
.option('-j, --junit [junitFile]', 'write issues to file in junit format as well as to the console')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is “junit” the preferred capitalization?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like JUnit is the correct name, but I'm thinking it makes sense to leave the option name and file name in the current case, and just change the descriptive text?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
.option('-c, --config [configFile]', 'configuration file (JSON, JSONC, JS, or YAML)')
.option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, [])
.option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)')
Expand Down
39 changes: 37 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"ignore": "~5.1.4",
"js-yaml": "~3.13.1",
"jsonc-parser": "~2.2.0",
"junit-report-builder": "^2.0.0",
FISHMANPET marked this conversation as resolved.
Show resolved Hide resolved
"lodash.differencewith": "~4.5.0",
"lodash.flatten": "~4.4.0",
"markdownlint": "~0.20.3",
Expand Down