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

Add success page if there are no errors #3

Open
dmstern opened this issue Apr 4, 2018 · 2 comments
Open

Add success page if there are no errors #3

dmstern opened this issue Apr 4, 2018 · 2 comments
Labels

Comments

@dmstern
Copy link

dmstern commented Apr 4, 2018

For console outputs, it's fine if an error reporter just outputs nothing if there are no errors and you have done a good job.
But if you put this graphical report html file to a server where you want to determine the validity of your project from time to time, I get only the last error report (with old errors) after fixing all of them.

It would be nice if there was a green colored output like "0 Errors in x files" or something like that.

Is this possible right now?

@prantlf
Copy link
Owner

prantlf commented Apr 6, 2018

Well, a reporter alone will not help here, because if there is not even a notice to report, the reporter is not called at all by the htmllint task. Similarly, if you check ten files and only one ends up with warnings, the report will contain only this one file. The other nine files will not be shown as valid in the report. You could open an issue for grunt-html about it.

For the time being, I solved this problem by using the built-in JSON reporter and running an additional task after htmllint - htmllint-html-report-converter - to convert the JSON report to HTML. It has an option includeUnreported to produce the report although the JSON report is missing.

Let's see how to modify a typical configuration like this:

htmllint: {
  options: {
    errorlevels: ['error', 'warning', 'info'],
    reporter: './node_modules/grunt-html-html-reporter',
    reporterOutput: 'results/report.html',
  },
  all: {
    src: ['input/*.html']
  }
}

to achieve the same using the report converter and dealing with a missing JSON report in the "total success" case:

htmllint: {
  options: {
    errorlevels: ['error', 'warning', 'info'],
    reporter: 'json',
    reporterOutput: 'results/report.json',
  },
  all: {
    src: ['input/*.html']
  }
},

'htmllint-html-report-converter': {
  options: {
    // Generate HTML file although the JSON source is missing after
    // a successfully ended `htmllint` task, assuming, that the task
    // ended successfully without any warnings or notices
    includeUnreported: true
  },
  all: {
    // How to find source HTML files to mention in the success report
    input: 'snapshots/*.html',
    src: 'results/report.json',
    dest: 'results/report.html'
  }
}

If there were any old JSON reports in the report directory, they have to be removed before another htmllint task will run. For example, using the clean task:

clean: {
  reports: ['results/*']
}

Finally, there is the last problem - if the htmllint task fails, it will aborts the whole Grunt task queue. The report converter will not be executed. If you ignore the problem by adding {force: true} option to the htmllint task, to let the next report conversion task running, you will miss the failure reported by the non-zero process exit code. I employed the continue task to overcome this. It puts both validator and report converter to a single group and lets the failure propagate after the whole group is finished:

grunt.registerTask('validate', ['clean:reports', 'continue:on',
  'htmllint', 'htmllint-html-report-converter', 'continue:off',
  'continue:fail-on-warning']);

All these tasks can be loaded like this:

grunt.loadNpmTasks('grunt-continue-ext');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-html-dev');
grunt.loadNpmTasks('grunt-html-html-report-converter');

And added to package.json and installed like this:

npm install grunt-continue-ext grunt-contrib-clean grunt-html-dev \
            grunt-html-html-report-converter --save-dev

@prantlf
Copy link
Owner

prantlf commented Apr 6, 2018

I opened issue 117 for htmllint about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants