From ca714340e80d5e7a9e0ba517868be8db1d24e8e1 Mon Sep 17 00:00:00 2001 From: Yuya Takeyama Date: Thu, 11 Jan 2018 18:25:13 +0900 Subject: [PATCH] Check generated Jest snap file (#3874) * Check generated Jest snap file * Check file name rule first ref: https://github.com/github/linguist/pull/3874/files#r146168309 * Check extension first It must be cheaper ref: https://github.com/github/linguist/pull/3874/files#r146168426 --- lib/linguist/generated.rb | 8 +++++ .../Data/__snapshots__/Button.ios.js.snap | 31 +++++++++++++++++++ test/test_generated.rb | 3 ++ 3 files changed, 42 insertions(+) create mode 100644 test/fixtures/Data/__snapshots__/Button.ios.js.snap diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index cb1d1106..00107f1d 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -62,6 +62,7 @@ module Linguist npm_shrinkwrap_or_package_lock? || godeps? || generated_by_zephir? || + generated_jest_snap? || minified_files? || has_source_map? || source_map? || @@ -525,5 +526,12 @@ module Linguist return false unless lines.count > 1 return lines[0].start_with?("// Generated by the gRPC") end + + # Internal: Is this a snap file of Jest? + # + # Return true or false + def generated_jest_snap? + name.end_with?(".snap") && name.include?("__snapshots__") + end end end diff --git a/test/fixtures/Data/__snapshots__/Button.ios.js.snap b/test/fixtures/Data/__snapshots__/Button.ios.js.snap new file mode 100644 index 00000000..4b5f8e5c --- /dev/null +++ b/test/fixtures/Data/__snapshots__/Button.ios.js.snap @@ -0,0 +1,31 @@ +exports[`test renders regular button 1`] = ` + + + Test + +`; diff --git a/test/test_generated.rb b/test/test_generated.rb index f82dfdf8..bddb4b12 100644 --- a/test/test_generated.rb +++ b/test/test_generated.rb @@ -115,5 +115,8 @@ class TestGenerated < Minitest::Test # PostScript generated_sample_loading_data("PostScript/lambda.pfa") + + # Jest snap + generated_fixture_without_loading_data("Data/__snapshots__/Button.ios.js.snap") end end