Skip to content

Commit 5072a3a

Browse files
Test: Suppress Node warnings
Generators that invoke `yarn` can result in warning being printed during testing, such as: ``` warning " > [email protected]" has unmet peer dependency "postcss@^8.0.0". ``` or ``` DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead. ``` Although these warnings may be legitimate, they disrupt the test output.
1 parent 0a7fc6f commit 5072a3a

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

test/generators/suspenders/lint_generator_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class LintGeneratorTest < Rails::Generators::TestCase
144144
test "created package.json if one does not exist" do
145145
remove_file_if_exists "package.json"
146146

147-
run_generator
147+
capture(:stderr) { run_generator }
148148

149149
assert_file app_root("package.json")
150150
end

test/generators/suspenders/styles_generator_test.rb

+32-24
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,54 @@ class StylesGeneratorTest < Rails::Generators::TestCase
2121

2222
test "does not raise if API configuration is commented out" do
2323
within_api_only_app(commented_out: true) do
24-
run_generator
24+
capture(:stderr) { run_generator }
2525
end
2626
end
2727

2828
test "adds gems to Gemfile" do
29-
run_generator
29+
capture(:stderr) { run_generator }
3030

3131
assert_file app_root("Gemfile") do |file|
3232
assert_match "cssbundling-rails", file
3333
end
3434
end
3535

3636
test "installs gems with Bundler" do
37-
output = run_generator
37+
capture(:stderr) do
38+
output = run_generator
3839

39-
assert_match(/bundle install/, output)
40+
assert_match(/bundle install/, output)
41+
end
4042
end
4143

4244
test "runs install script" do
43-
output = run_generator
45+
capture(:stderr) do
46+
output = run_generator
4447

45-
assert_match(/bin\/rails css:install:postcss/, output)
48+
assert_match(/bin\/rails css:install:postcss/, output)
49+
end
4650
end
4751

4852
test "installs modern-normalize and imports stylesheets" do
49-
output = run_generator
50-
application_stylesheet = <<~TEXT
51-
@import "modern-normalize";
52-
@import "base.css";
53-
@import "components.css";
54-
@import "utilities.css";
55-
TEXT
56-
57-
assert_match(/add.*modern-normalize/, output)
58-
59-
assert_file app_root("app/assets/stylesheets/application.postcss.css") do |file|
60-
assert_equal application_stylesheet, file
53+
capture(:stderr) do
54+
output = run_generator
55+
application_stylesheet = <<~TEXT
56+
@import "modern-normalize";
57+
@import "base.css";
58+
@import "components.css";
59+
@import "utilities.css";
60+
TEXT
61+
62+
assert_match(/add.*modern-normalize/, output)
63+
64+
assert_file app_root("app/assets/stylesheets/application.postcss.css") do |file|
65+
assert_equal application_stylesheet, file
66+
end
6167
end
6268
end
6369

6470
test "creates stylesheets" do
65-
run_generator
71+
capture(:stderr) { run_generator }
6672

6773
assert_file app_root("app/assets/stylesheets/base.css") do |file|
6874
assert_equal "/* Base Styles */", file
@@ -76,15 +82,17 @@ class StylesGeneratorTest < Rails::Generators::TestCase
7682
end
7783

7884
test "installs postcss-url" do
79-
output = run_generator
85+
capture(:stderr) do
86+
output = run_generator
8087

81-
assert_match(/add\s*postcss-url/, output)
88+
assert_match(/add\s*postcss-url/, output)
89+
end
8290
end
8391

8492
test "configures postcss.config.js" do
8593
expected = file_fixture("postcss.config.js").read
8694

87-
run_generator
95+
capture(:stderr) { run_generator }
8896

8997
assert_file app_root("postcss.config.js") do |file|
9098
assert_equal expected, file
@@ -95,15 +103,15 @@ class StylesGeneratorTest < Rails::Generators::TestCase
95103
touch "postcss.config.js", content: "unexpected"
96104
expected = file_fixture("postcss.config.js").read
97105

98-
run_generator
106+
capture(:stderr) { run_generator }
99107

100108
assert_file app_root("postcss.config.js") do |file|
101109
assert_equal expected, file
102110
end
103111
end
104112

105113
test "creates directory to store static assets generated from postcss-url" do
106-
run_generator
114+
capture(:stderr) { run_generator }
107115

108116
assert_file app_root("app/assets/static/.gitkeep")
109117
end

0 commit comments

Comments
 (0)