diff --git a/Gemfile b/Gemfile index e6a3f1f7973c..8e5218d6b7ad 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source "https://rubygems.org" group :test do + gem "fastimage", "~> 2.1.0" gem "minitest", "~> 5.10.3" gem "rake" gem "rubocop", "~> 0.50.0" diff --git a/Gemfile.lock b/Gemfile.lock index 0b30e41424f8..986b8ed94a6a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ GEM remote: https://rubygems.org/ specs: ast (2.3.0) + fastimage (2.1.0) minitest (5.10.3) parallel (1.12.0) parser (2.4.0.0) @@ -25,10 +26,11 @@ PLATFORMS ruby DEPENDENCIES + fastimage (~> 2.1.0) minitest (~> 5.10.3) rake rubocop (~> 0.50.0) safe_yaml (~> 1.0.4) BUNDLED WITH - 1.15.3 + 1.15.4 diff --git a/README.md b/README.md index dcff891f52ff..3ad9f5bc098d 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,16 @@ +There are some lint tests in place to ensure each topic is formatted in the way we expect. Travis +CI will run the tests automatically. If you want to run the tests yourself locally, you will need +Ruby and Bundler installed. + +You can run the tests using: + +```bash +script/cibuild +``` + Topic pages, curated by the community. [Topics](https://help.github.com/articles/about-topics/) help you explore repositories in a particular subject area, learn more about a subject area, and find projects to contribute to. diff --git a/test/test_helper.rb b/test/test_helper.rb index ec42878c82a5..a3d3f796d253 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,11 +1,13 @@ require "minitest/autorun" +require "fastimage" require "yaml" IMAGE_EXTENSIONS = %w[.jpg .jpeg .png].freeze - +IMAGE_WIDTH = 288 +IMAGE_HEIGHT = 288 +MAX_IMAGE_FILESIZE_IN_BYTES = 65_000 VALID_METADATA_KEYS = %w[aliases created_by display_name github_url logo related released short_description topic url wikipedia_url].freeze - REQUIRED_METADATA_KEYS = %w[topic short_description].freeze MAX_TOPIC_LENGTH = 35 diff --git a/test/topics_test.rb b/test/topics_test.rb index 09219f7c1068..53bbb98364dc 100644 --- a/test/topics_test.rb +++ b/test/topics_test.rb @@ -59,7 +59,7 @@ assert File.file?(path), "expected #{path} to be a file" end - it "has only one image with the right name" do + it "has at most one image with the right name, type, and dimensions" do paths = image_paths_for(topic) assert paths.size <= 1, "expected at most one image, found #{paths.size}" @@ -67,6 +67,18 @@ if path = paths.first assert_equal topic, File.basename(path, File.extname(path)), "expected image to be named [topic].[extension]" + + width, height = FastImage.size(path) + assert_equal IMAGE_WIDTH, width, "topic images should be #{IMAGE_WIDTH}px wide" + assert_equal IMAGE_HEIGHT, height, "topic images should be #{IMAGE_HEIGHT}px tall" + + assert_includes IMAGE_EXTENSIONS, ".#{FastImage.type(path)}", + "topic images should be one of #{IMAGE_EXTENSIONS.join(', ')}" + + file_size = FastImage.new(path).content_length + assert file_size <= MAX_IMAGE_FILESIZE_IN_BYTES, + "topic images should not exceed #{MAX_IMAGE_FILESIZE_IN_BYTES} bytes, got " \ + "#{file_size} bytes" end end diff --git a/topics/bitcoin/bitcoin.png b/topics/bitcoin/bitcoin.png index bf3ebe1b3f44..75c01c7ab232 100644 Binary files a/topics/bitcoin/bitcoin.png and b/topics/bitcoin/bitcoin.png differ diff --git a/topics/elixir/elixir.png b/topics/elixir/elixir.png index 003479fd8606..bd909f89858e 100644 Binary files a/topics/elixir/elixir.png and b/topics/elixir/elixir.png differ diff --git a/topics/sketch/sketch.png b/topics/sketch/sketch.png index be8873c2ecf8..e130d2f5a1f0 100644 Binary files a/topics/sketch/sketch.png and b/topics/sketch/sketch.png differ