gjtorikian / html-proofer

Test your rendered HTML files to make sure they're accurate.
MIT License
1.57k stars 199 forks source link

Running without the cache clobbers the cache #647

Closed fulldecent closed 2 years ago

fulldecent commented 3 years ago

Description

Running HTMLProofer without the cache option causes any existing cache to be discarded. This is not desirible.

Test case

Here is a test script where first an on-site thing is checked and then later off-site things are checked.

On-site:

    puts "⚡️  Checking mailto links".blue
    checks_to_ignore = HTMLProofer::Check.subchecks.map(&:name)
    checks_to_ignore.delete 'MailToAwesome'
    options = {
        :check_mailto_awesome => true,
        :checks_to_ignore => checks_to_ignore
    }
    begin
      HTMLProofer.check_directory("#{@build_dir}", options).run
    rescue => msg
      abort "#{msg}".red
    end

Off-site:

  desc "Checks everything with htmlproofer that is reasonable to check"
  task :check do
    puts "⚡️  Checking HTML".blue
    options = {
      :disable_external => true,
      :check_external_hash => true,
      :check_sri => true,
      :check_html => true,
      :check_opengraph => true,
      :check_img_http => true,
      :enforce_https => true,
      :report_eof_tags => true,
      :report_invalid_tags => true,
      :report_mismatched_tags => true,
      :report_missing_doctype => true,
        :cache => {
          :timeframe => '6w'
        }
    }
    begin
      HTMLProofer.check_directory("#{@build_dir}", options).run
    rescue => msg
      abort "#{msg}".red
    end

Expected outcome

The first check will complete without any consideration for the items in the cache.

Actual outcome

The first check clobbers the cache.

⚡️  Checking mailto links
Running [] on ["BUILD"] on *.html... 

Found 159 links in the cache...
Adding 0 links to the cache...
Removing 159 links from the cache... <--------------------------------😳
Checking 0 external links...
Ran on 37 files!

And then the second check is starting up cold

⚡️  Checking HTML
Running ["HtmlCheck", "ImageCheck", "OpenGraphCheck", "LinkCheck", "ScriptCheck", "Html::Proofer::MailtoAwesome::MailToAwesome"] on ["BUILD"] on *.html... 

Found 0 links in the cache... <--------------------------------😳
Adding 159 links to the cache...
Removing 0 links from the cache...
Checking 159 external links...
...
gjtorikian commented 2 years ago

Hi—the next version of HTMLProofer has completely rewritten the cache and this is no longer a problem. I am going to close this issue out, as I'm just one person and can't maintain both the 3.x and 4.x features. ✌️