forked from magento/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rake
65 lines (55 loc) · 2.07 KB
/
test.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.
# frozen_string_literal: true
namespace :test do
# Run html-proofer to check for broken links
desc 'Build site, check for broken links, write report to a file'
task links: %w[build links_no_build]
desc 'Check the existing _site for broken EXTERNAL links'
task :external_links do
puts 'Testing external links'
system 'bin/htmlproofer _site/ --external_only'
end
desc 'Check the existing _site for broken INTERNAL links'
task :html do
puts 'Checking HTML ...'.magenta
LinkChecker.check_site
end
desc 'Check the existing _site for broken links and report to a separate file'
task :links_no_build do
# Write console output (stderr only) to a file.
# Use this if you need to also capture stdout: https://stackoverflow.com/a/2480439
report = LinkChecker.md_report_path
$stderr.reopen(report, 'w+')
Rake::Task['test:html'].invoke
# We're expecting link validation errors, but unless we rescue from
# StandardError, rake will abort and won't run the convert task (https://stackoverflow.com/a/10048406).
# Wrapping task in a begin-rescue block prevent rake from aborting.
# Seems to prevent printing an error count though.
rescue StandardError => e
# Show how many lines contains the Markdown report
puts e.to_s.red
puts "To see the report, open the #{report} file.".red
end
desc 'Report about broken links in HTML'
task report: %w[links] do
puts 'Converting the link check report to HTML...'.magenta
Converter.to_html
end
desc 'Test Markdown style with mdl'
task :md do
puts 'Testing Markdown style with mdl ...'.magenta
print 'List the rules: $ '.magenta
sh 'bin/mdl -l --style=_checks/styles/style-rules-prod'
puts 'Linting ...'.magenta
output =
`bin/mdl \
--style=_checks/styles/style-rules-prod \
--ignore-front-matter \
--git-recurse \
-- .`
puts output.yellow
abort 'Fix the reported issues'.red unless output.empty?
puts 'No issues found'.green
end
end