Skip to content

Commit

Permalink
Test query params in internal links
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Jun 24, 2021
1 parent d64768a commit 45c433c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 27 deletions.
85 changes: 58 additions & 27 deletions spec/html-proofer/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,58 +246,89 @@ def read_cache(cache_file)

Timecop.return
end
end

it 'does recheck failures, regardless of external-only cache' do
cache_file_name = '.external.log'
cache_location = File.join(storage_dir, cache_file_name)
it 'does recheck failures, regardless of external-only cache' do
cache_file_name = '.external.log'
cache_location = File.join(storage_dir, cache_file_name)

file = "#{FIXTURES_DIR}/cache/external_example.html"
file = "#{FIXTURES_DIR}/cache/external_example.html"

new_time = Time.local(2021, 0o1, 27, 12, 0, 0)
Timecop.freeze(new_time)
new_time = Time.local(2021, 0o1, 27, 12, 0, 0)
Timecop.freeze(new_time)

File.delete(cache_location) if File.exist?(cache_location)
File.delete(cache_location) if File.exist?(cache_location)

run_proofer(file, :file, external_only: true, links_only: true, cache: { timeframe: '1d', cache_file: cache_file_name }.merge(default_cache_options))
run_proofer(file, :file, external_only: true, links_only: true, cache: { timeframe: '1d', cache_file: cache_file_name }.merge(default_cache_options))

cache = JSON.parse(File.read(cache_location))
cache = JSON.parse(File.read(cache_location))

expect(cache.keys.count).to eq(1)
expect(cache.keys[0]).to eq('https://github.com/gjtorikian/html-proofer')
expect(cache.keys.count).to eq(1)
expect(cache.keys[0]).to eq('https://github.com/gjtorikian/html-proofer')

run_proofer(file, :file, links_only: true, cache: { timeframe: '1d', cache_file: cache_file_name }.merge(default_cache_options))
run_proofer(file, :file, links_only: true, cache: { timeframe: '1d', cache_file: cache_file_name }.merge(default_cache_options))

cache = JSON.parse(File.read(cache_location))
expect(cache.keys.count).to eq(1)
expect(cache.keys[0]).to eq('https://github.com/gjtorikian/html-proofer')
cache = JSON.parse(File.read(cache_location))
expect(cache.keys.count).to eq(1)
expect(cache.keys[0]).to eq('https://github.com/gjtorikian/html-proofer')

Timecop.return
Timecop.return
end

it 'does recheck failures, regardless of external and internal cache' do
cache_file_name = '.internal_and_external.log'
cache_location = File.join(storage_dir, cache_file_name)

file = "#{FIXTURES_DIR}/cache/internal_and_external_example.html"

new_time = Time.local(2021, 0o1, 27, 12, 0, 0)
Timecop.freeze(new_time)

File.delete(cache_location) if File.exist?(cache_location)

run_proofer(file, :file, external_only: true, links_only: true, cache: { timeframe: '1d', cache_file: cache_file_name }.merge(default_cache_options))

cache = JSON.parse(File.read(cache_location))

expect(cache.keys.count).to eq(1)
expect(cache.keys[0]).to eq('https://github.com/gjtorikian/html-proofer')

run_proofer(file, :file, links_only: true, cache: { timeframe: '1d', cache_file: cache_file_name }.merge(default_cache_options))

cache = JSON.parse(File.read(cache_location))
expect(cache.keys.count).to eq(2)
expect(cache.keys[0]).to eq('https://github.com/gjtorikian/html-proofer')

Timecop.return
end
end

it 'does recheck failures, regardless of external and internal cache' do
cache_file_name = '.internal_and_external.log'
it 'does not blow up if internal link has query params' do
cache_file_name = '.new_internal_url_w_query_params.log'
cache_location = File.join(storage_dir, cache_file_name)

file = "#{FIXTURES_DIR}/cache/internal_and_external_example.html"
file = "#{FIXTURES_DIR}/links/internal_query_link.html"

new_time = Time.local(2021, 0o1, 27, 12, 0, 0)
new_time = Time.local(2020, 0o1, 27, 12, 0, 0)
Timecop.freeze(new_time)

File.delete(cache_location) if File.exist?(cache_location)

run_proofer(file, :file, external_only: true, links_only: true, cache: { timeframe: '1d', cache_file: cache_file_name }.merge(default_cache_options))
run_proofer(file, :file, links_only: true, cache: { timeframe: '1d', cache_file: cache_file_name }.merge(default_cache_options))

cache = JSON.parse(File.read(cache_location))

expect(cache.keys.count).to eq(1)
expect(cache.keys[0]).to eq('https://github.com/gjtorikian/html-proofer')
expect(cache.keys[0]).to eq('./gpl.png?v=2020-12-10-1')

run_proofer(file, :file, links_only: true, cache: { timeframe: '1d', cache_file: cache_file_name }.merge(default_cache_options))
Timecop.return

cache = JSON.parse(File.read(cache_location))
expect(cache.keys.count).to eq(2)
expect(cache.keys[0]).to eq('https://github.com/gjtorikian/html-proofer')
new_time = Time.local(2021, 0o6, 20, 12, 0, 0)
Timecop.freeze(new_time)

# expect_any_instance_of(HTMLProofer::Cache).to receive(:add)

# we expect one new link to be added because it's outside the 30d time frame
run_proofer(file, :file, cache: { timeframe: '30d', cache_file: cache_file_name }.merge(default_cache_options))

Timecop.return
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"./gpl.png?v=2020-12-10-1":{"time":"2021-06-20 12:00:00 -0400","filenames":["spec/html-proofer/fixtures/links/internal_query_link.html"],"status":200,"message":""}}
3 changes: 3 additions & 0 deletions spec/html-proofer/fixtures/links/internal_query_link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<ul>
<li>Visit <a href="./gpl.png?v=2020-12-10-1">http://1.2.3.4/</a>.</li>
</ul>

0 comments on commit 45c433c

Please sign in to comment.