From 0084b93a9e061105f906a9e91294e0924b81c801 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Mon, 25 Dec 2023 20:27:41 +0300 Subject: [PATCH] fix: warning output (#1173) --- src/utils.js | 14 +- test/__snapshots__/loader.test.js.snap | 264 ++++++++++++++---- .../warnRuleAsWarning.test.js.snap | 68 +++++ test/helpers/getWarnings.js | 3 +- test/helpers/normalizeErrors.js | 10 +- test/loader.test.js | 4 +- test/sass/broken.sass | 6 + test/warnRuleAsWarning.test.js | 36 +++ 8 files changed, 339 insertions(+), 66 deletions(-) create mode 100644 test/sass/broken.sass diff --git a/src/utils.js b/src/utils.js index a356baea..b47cd36f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -127,7 +127,9 @@ async function getSassOptions( const needEmitWarning = loaderOptions.warnRuleAsWarning !== false; const logger = loaderContext.getLogger("sass-loader"); const formatSpan = (span) => - `${span.url || "-"}:${span.start.line}:${span.start.column}: `; + `Warning on line ${span.start.line}, column ${span.start.column} of ${ + span.url || "-" + }:${span.start.line}:${span.start.column}:\n`; const formatDebugSpan = (span) => `[debug:${span.start.line}:${span.start.column}] `; @@ -150,13 +152,17 @@ async function getSassOptions( builtMessage += "Deprecation "; } - if (loggerOptions.span && !loggerOptions.stack) { - builtMessage = formatSpan(loggerOptions.span); + if (loggerOptions.span) { + builtMessage += formatSpan(loggerOptions.span); } builtMessage += message; - if (loggerOptions.stack) { + if (loggerOptions.span && loggerOptions.span.context) { + builtMessage += `\n\n${loggerOptions.span.start.line} | ${loggerOptions.span.context}`; + } + + if (loggerOptions.stack && loggerOptions.stack !== "null") { builtMessage += `\n\n${loggerOptions.stack}`; } diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index c97d4b98..999d477b 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -5499,28 +5499,72 @@ exports[`loader should work and output deprecation message (dart-sass): errors 4 exports[`loader should work and output deprecation message (dart-sass): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $saturation: Passing a number without unit % (0) is deprecated.", +Deprecation Warning on line 0, column 25 of file:///test/scss/deprecation.scss:0:25: +$saturation: Passing a number without unit % (0) is deprecated. + +To preserve current behavior: $saturation * 1% + +More info: https://sass-lang.com/d/function-units + +0 | $side-nav-link-bg-hover: hsla(0, 0, 0%, 0.025) !default; + + +test/scss/deprecation.scss 1:26 root stylesheet +", ] `; exports[`loader should work and output deprecation message (dart-sass): warnings 2`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $saturation: Passing a number without unit % (0) is deprecated.", +Deprecation Warning on line 0, column 25 of file:///test/sass/deprecation.sass:0:25: +$saturation: Passing a number without unit % (0) is deprecated. + +To preserve current behavior: $saturation * 1% + +More info: https://sass-lang.com/d/function-units + +0 | $side-nav-link-bg-hover: hsla(0, 0, 0%, 0.025) !default + + +test/sass/deprecation.sass 1:26 root stylesheet +", ] `; exports[`loader should work and output deprecation message (dart-sass): warnings 3`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $saturation: Passing a number without unit % (0) is deprecated.", +Deprecation Warning on line 0, column 25 of file:///test/scss/deprecation.scss:0:25: +$saturation: Passing a number without unit % (0) is deprecated. + +To preserve current behavior: $saturation * 1% + +More info: https://sass-lang.com/d/function-units + +0 | $side-nav-link-bg-hover: hsla(0, 0, 0%, 0.025) !default; + + +test/scss/deprecation.scss 1:26 root stylesheet +", ] `; exports[`loader should work and output deprecation message (dart-sass): warnings 4`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $saturation: Passing a number without unit % (0) is deprecated.", +Deprecation Warning on line 0, column 25 of file:///test/sass/deprecation.sass:0:25: +$saturation: Passing a number without unit % (0) is deprecated. + +To preserve current behavior: $saturation * 1% + +More info: https://sass-lang.com/d/function-units + +0 | $side-nav-link-bg-hover: hsla(0, 0, 0%, 0.025) !default + + +test/sass/deprecation.sass 1:26 root stylesheet +", ] `; @@ -5559,28 +5603,72 @@ exports[`loader should work and output deprecation message (sass-embedded): erro exports[`loader should work and output deprecation message (sass-embedded): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $saturation: Passing a number without unit % (0) is deprecated.", +Deprecation Warning on line 0, column 25 of file:///test/scss/deprecation.scss:0:25: +$saturation: Passing a number without unit % (0) is deprecated. + +To preserve current behavior: $saturation * 1% + +More info: https://sass-lang.com/d/function-units + +0 | $side-nav-link-bg-hover: hsla(0, 0, 0%, 0.025) !default; + + +test/scss/deprecation.scss 1:26 root stylesheet +", ] `; exports[`loader should work and output deprecation message (sass-embedded): warnings 2`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $saturation: Passing a number without unit % (0) is deprecated.", +Deprecation Warning on line 0, column 25 of file:///test/sass/deprecation.sass:0:25: +$saturation: Passing a number without unit % (0) is deprecated. + +To preserve current behavior: $saturation * 1% + +More info: https://sass-lang.com/d/function-units + +0 | $side-nav-link-bg-hover: hsla(0, 0, 0%, 0.025) !default + + +test/sass/deprecation.sass 1:26 root stylesheet +", ] `; exports[`loader should work and output deprecation message (sass-embedded): warnings 3`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $saturation: Passing a number without unit % (0) is deprecated.", +Deprecation Warning on line 0, column 25 of file:///test/scss/deprecation.scss:0:25: +$saturation: Passing a number without unit % (0) is deprecated. + +To preserve current behavior: $saturation * 1% + +More info: https://sass-lang.com/d/function-units + +0 | $side-nav-link-bg-hover: hsla(0, 0, 0%, 0.025) !default; + + +test/scss/deprecation.scss 1:26 root stylesheet +", ] `; exports[`loader should work and output deprecation message (sass-embedded): warnings 4`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $saturation: Passing a number without unit % (0) is deprecated.", +Deprecation Warning on line 0, column 25 of file:///test/sass/deprecation.sass:0:25: +$saturation: Passing a number without unit % (0) is deprecated. + +To preserve current behavior: $saturation * 1% + +More info: https://sass-lang.com/d/function-units + +0 | $side-nav-link-bg-hover: hsla(0, 0, 0%, 0.025) !default + + +test/sass/deprecation.sass 1:26 root stylesheet +", ] `; @@ -99391,7 +99479,23 @@ exports[`loader should work when "@use" with "bootstrap" package v5 without tild exports[`loader should work when "@use" with "bootstrap" package v5 without tilde, import as a package ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10: +$weight: Passing a number without unit % (100) is deprecated. + +To preserve current behavior: $weight * 1% + +More info: https://sass-lang.com/d/function-units + +200 | @return mix(rgba($foreground, 1), $background, opacity($foreground) * 100); + + +node_modules/bootstrap-v5/scss/_functions.scss 201:11 opaque() +node_modules/bootstrap-v5/scss/mixins/_table-variants.scss 4:28 table-variant() +node_modules/bootstrap-v5/scss/_tables.scss 138:3 @import +node_modules/bootstrap-v5/scss/bootstrap.scss 22:9 @import +test/sass/bootstrap-v5.sass 1:9 @use +test/sass/use-bootstrap-package-v5.sass 1:1 root stylesheet +", ] `; @@ -109508,7 +109612,23 @@ exports[`loader should work when "@use" with "bootstrap" package v5 without tild exports[`loader should work when "@use" with "bootstrap" package v5 without tilde, import as a package ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10: +$weight: Passing a number without unit % (100) is deprecated. + +To preserve current behavior: $weight * 1% + +More info: https://sass-lang.com/d/function-units + +200 | @return mix(rgba($foreground, 1), $background, opacity($foreground) * 100); + + +node_modules/bootstrap-v5/scss/_functions.scss 201:11 opaque() +node_modules/bootstrap-v5/scss/mixins/_table-variants.scss 4:28 table-variant() +node_modules/bootstrap-v5/scss/_tables.scss 138:3 @import +node_modules/bootstrap-v5/scss/bootstrap.scss 22:9 @import +test/scss/bootstrap-v5.scss 1:9 @use +test/scss/use-bootstrap-package-v5.scss 1:1 root stylesheet +", ] `; @@ -119625,7 +119745,23 @@ exports[`loader should work when "@use" with "bootstrap" package v5 without tild exports[`loader should work when "@use" with "bootstrap" package v5 without tilde, import as a package ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10: +$weight: Passing a number without unit % (100) is deprecated. + +To preserve current behavior: $weight * 1% + +More info: https://sass-lang.com/d/function-units + +200 | @return mix(rgba($foreground, 1), $background, opacity($foreground) * 100); + + +node_modules/bootstrap-v5/scss/_functions.scss 201:11 opaque() +node_modules/bootstrap-v5/scss/mixins/_table-variants.scss 4:28 table-variant() +node_modules/bootstrap-v5/scss/_tables.scss 138:3 @import +bootstrap.scss 22:9 @import +test/sass/bootstrap-v5.sass 1:9 @use +test/sass/use-bootstrap-package-v5.sass 1:1 root stylesheet +", ] `; @@ -129742,7 +129878,23 @@ exports[`loader should work when "@use" with "bootstrap" package v5 without tild exports[`loader should work when "@use" with "bootstrap" package v5 without tilde, import as a package ('sass-embedded', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10: +$weight: Passing a number without unit % (100) is deprecated. + +To preserve current behavior: $weight * 1% + +More info: https://sass-lang.com/d/function-units + +200 | @return mix(rgba($foreground, 1), $background, opacity($foreground) * 100); + + +node_modules/bootstrap-v5/scss/_functions.scss 201:11 opaque() +node_modules/bootstrap-v5/scss/mixins/_table-variants.scss 4:28 table-variant() +node_modules/bootstrap-v5/scss/_tables.scss 138:3 @import +bootstrap.scss 22:9 @import +test/scss/bootstrap-v5.scss 1:9 @use +test/scss/use-bootstrap-package-v5.scss 1:1 root stylesheet +", ] `; @@ -139859,7 +140011,7 @@ exports[`loader should work when "@use" with "bootstrap" package v5, import as a exports[`loader should work when "@use" with "bootstrap" package v5, import as a package ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -149976,7 +150128,7 @@ exports[`loader should work when "@use" with "bootstrap" package v5, import as a exports[`loader should work when "@use" with "bootstrap" package v5, import as a package ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -160093,7 +160245,7 @@ exports[`loader should work when "@use" with "bootstrap" package v5, import as a exports[`loader should work when "@use" with "bootstrap" package v5, import as a package ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -170210,7 +170362,7 @@ exports[`loader should work when "@use" with "bootstrap" package v5, import as a exports[`loader should work when "@use" with "bootstrap" package v5, import as a package ('sass-embedded', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -278789,7 +278941,7 @@ exports[`loader should work with "bootstrap" package v5 without tilde, import as exports[`loader should work with "bootstrap" package v5 without tilde, import as a package ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -278798,7 +278950,7 @@ exports[`loader should work with "bootstrap" package v5 without tilde, import as exports[`loader should work with "bootstrap" package v5 without tilde, import as a package ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -278815,7 +278967,7 @@ exports[`loader should work with "bootstrap" package v5 without tilde, import as exports[`loader should work with "bootstrap" package v5 without tilde, import as a package ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -278824,7 +278976,7 @@ exports[`loader should work with "bootstrap" package v5 without tilde, import as exports[`loader should work with "bootstrap" package v5 without tilde, import as a package ('sass-embedded', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -288941,7 +289093,7 @@ exports[`loader should work with "bootstrap" package v5, import as a package ('d exports[`loader should work with "bootstrap" package v5, import as a package ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -299058,7 +299210,7 @@ exports[`loader should work with "bootstrap" package v5, import as a package ('d exports[`loader should work with "bootstrap" package v5, import as a package ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -324811,7 +324963,7 @@ exports[`loader should work with "bootstrap" package v5, import as a package ('s exports[`loader should work with "bootstrap" package v5, import as a package ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -334928,7 +335080,7 @@ exports[`loader should work with "bootstrap" package v5, import as a package ('s exports[`loader should work with "bootstrap" package v5, import as a package ('sass-embedded', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation $weight: Passing a number without unit % (100) is deprecated.", +Deprecation Warning on line 200, column 10 of file:///node_modules/bootstrap-v5/scss/_functions.scss:200:10:", ] `; @@ -452960,26 +453112,26 @@ exports[`loader should work with the "material-components-web" package ('dart-sa exports[`loader should work with the "material-components-web" package ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/theme/_theme-color.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/typography/_typography.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 51, column 10 of file:///node_modules/@material/typography/_typography.scss:51:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touch-target/_touch-target.scss:89:26:", ] `; exports[`loader should work with the "material-components-web" package ('dart-sass', 'legacy' API, 'sass' syntax): warnings 2`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/theme/_theme-color.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/typography/_typography.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 51, column 10 of file:///node_modules/@material/typography/_typography.scss:51:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touch-target/_touch-target.scss:89:26:", ] `; @@ -453810,26 +453962,26 @@ exports[`loader should work with the "material-components-web" package ('dart-sa exports[`loader should work with the "material-components-web" package ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/theme/_theme-color.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/typography/_typography.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 51, column 10 of file:///node_modules/@material/typography/_typography.scss:51:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touch-target/_touch-target.scss:89:26:", ] `; exports[`loader should work with the "material-components-web" package ('dart-sass', 'legacy' API, 'scss' syntax): warnings 2`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/theme/_theme-color.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/typography/_typography.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 51, column 10 of file:///node_modules/@material/typography/_typography.scss:51:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touch-target/_touch-target.scss:89:26:", ] `; @@ -454660,26 +454812,26 @@ exports[`loader should work with the "material-components-web" package without t exports[`loader should work with the "material-components-web" package without the "includePaths" option ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/theme/_theme-color.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/typography/_typography.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 51, column 10 of file:///node_modules/@material/typography/_typography.scss:51:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touch-target/_touch-target.scss:89:26:", ] `; exports[`loader should work with the "material-components-web" package without the "includePaths" option ('dart-sass', 'legacy' API, 'sass' syntax): warnings 2`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/theme/_theme-color.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/typography/_typography.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 51, column 10 of file:///node_modules/@material/typography/_typography.scss:51:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touch-target/_touch-target.scss:89:26:", ] `; @@ -455510,26 +455662,26 @@ exports[`loader should work with the "material-components-web" package without t exports[`loader should work with the "material-components-web" package without the "includePaths" option ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/theme/_theme-color.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/typography/_typography.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 51, column 10 of file:///node_modules/@material/typography/_typography.scss:51:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touch-target/_touch-target.scss:89:26:", ] `; exports[`loader should work with the "material-components-web" package without the "includePaths" option ('dart-sass', 'legacy' API, 'scss' syntax): warnings 2`] = ` [ "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/theme/_theme-color.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 47, column 10 of file:///node_modules/@material/typography/_typography.scss:47:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 51, column 10 of file:///node_modules/@material/typography/_typography.scss:51:10:", "ModuleWarning: Module Warning (from ../src/cjs.js): -Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.", +Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touch-target/_touch-target.scss:89:26:", ] `; diff --git a/test/__snapshots__/warnRuleAsWarning.test.js.snap b/test/__snapshots__/warnRuleAsWarning.test.js.snap index 070141c5..b9292156 100644 --- a/test/__snapshots__/warnRuleAsWarning.test.js.snap +++ b/test/__snapshots__/warnRuleAsWarning.test.js.snap @@ -1,5 +1,73 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`loader should emit good formatted warning ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `""`; + +exports[`loader should emit good formatted warning ('dart-sass', 'legacy' API, 'sass' syntax): errors 1`] = `[]`; + +exports[`loader should emit good formatted warning ('dart-sass', 'legacy' API, 'sass' syntax): logs 1`] = `[]`; + +exports[`loader should emit good formatted warning ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = ` +[ + "ModuleWarning: Module Warning (from ../src/cjs.js): +Warning on line 5, column 3 of file:///test/sass/broken.sass:5:3: +This selector doesn't have any properties and won't be rendered. + +5 | asdf +", +] +`; + +exports[`loader should emit good formatted warning ('dart-sass', 'modern' API, 'sass' syntax): css 1`] = `""`; + +exports[`loader should emit good formatted warning ('dart-sass', 'modern' API, 'sass' syntax): errors 1`] = `[]`; + +exports[`loader should emit good formatted warning ('dart-sass', 'modern' API, 'sass' syntax): logs 1`] = `[]`; + +exports[`loader should emit good formatted warning ('dart-sass', 'modern' API, 'sass' syntax): warnings 1`] = ` +[ + "ModuleWarning: Module Warning (from ../src/cjs.js): +Warning on line 5, column 3 of file:///test/sass/broken.sass:5:3: +This selector doesn't have any properties and won't be rendered. + +5 | asdf +", +] +`; + +exports[`loader should emit good formatted warning ('sass-embedded', 'legacy' API, 'sass' syntax): css 1`] = `""`; + +exports[`loader should emit good formatted warning ('sass-embedded', 'legacy' API, 'sass' syntax): errors 1`] = `[]`; + +exports[`loader should emit good formatted warning ('sass-embedded', 'legacy' API, 'sass' syntax): logs 1`] = `[]`; + +exports[`loader should emit good formatted warning ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 1`] = ` +[ + "ModuleWarning: Module Warning (from ../src/cjs.js): +Warning on line 5, column 3 of file:///test/sass/broken.sass:5:3: +This selector doesn't have any properties and won't be rendered. + +5 | asdf +", +] +`; + +exports[`loader should emit good formatted warning ('sass-embedded', 'modern' API, 'sass' syntax): css 1`] = `""`; + +exports[`loader should emit good formatted warning ('sass-embedded', 'modern' API, 'sass' syntax): errors 1`] = `[]`; + +exports[`loader should emit good formatted warning ('sass-embedded', 'modern' API, 'sass' syntax): logs 1`] = `[]`; + +exports[`loader should emit good formatted warning ('sass-embedded', 'modern' API, 'sass' syntax): warnings 1`] = ` +[ + "ModuleWarning: Module Warning (from ../src/cjs.js): +Warning on line 5, column 3 of file:///test/sass/broken.sass:5:3: +This selector doesn't have any properties and won't be rendered. + +5 | asdf +", +] +`; + exports[`loader should emit warning by default ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = ` "a { color: red; diff --git a/test/helpers/getWarnings.js b/test/helpers/getWarnings.js index 456c588d..9727d58a 100644 --- a/test/helpers/getWarnings.js +++ b/test/helpers/getWarnings.js @@ -1,3 +1,4 @@ import normalizeErrors from "./normalizeErrors"; -export default (stats) => normalizeErrors(stats.compilation.warnings.sort()); +export default (stats, needVerbose) => + normalizeErrors(stats.compilation.warnings.sort(), needVerbose); diff --git a/test/helpers/normalizeErrors.js b/test/helpers/normalizeErrors.js index 72baa177..51b4d599 100644 --- a/test/helpers/normalizeErrors.js +++ b/test/helpers/normalizeErrors.js @@ -9,10 +9,14 @@ function removeCWD(str) { cwd = cwd.replace(/\\/g, "/"); } - return str.replace(new RegExp(cwd, "g"), ""); + return str.replace(new RegExp(cwd, "g"), "").replace("file:////", "file:///"); } -export default (errors) => +export default (errors, needVerbose) => errors.map((error) => - removeCWD(error.toString().split("\n").slice(0, 2).join("\n")) + removeCWD( + needVerbose + ? error.toString() + : error.toString().split("\n").slice(0, 2).join("\n") + ) ); diff --git a/test/loader.test.js b/test/loader.test.js index a44d7922..52227237 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -1853,7 +1853,7 @@ describe("loader", () => { expect(codeFromBundle.css).toBe(codeFromSass.css); expect(codeFromBundle.css).toMatchSnapshot("css"); - expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getWarnings(stats, true)).toMatchSnapshot("warnings"); expect(getErrors(stats)).toMatchSnapshot("errors"); }); } @@ -2040,7 +2040,7 @@ describe("loader", () => { expect(codeFromBundle.css).toBe(codeFromSass.css); expect(codeFromBundle.css).toMatchSnapshot("css"); - expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getWarnings(stats, true)).toMatchSnapshot("warnings"); expect(getErrors(stats)).toMatchSnapshot("errors"); }); diff --git a/test/sass/broken.sass b/test/sass/broken.sass new file mode 100644 index 00000000..95b72c91 --- /dev/null +++ b/test/sass/broken.sass @@ -0,0 +1,6 @@ + + + + + + asdf diff --git a/test/warnRuleAsWarning.test.js b/test/warnRuleAsWarning.test.js index 4806d543..0623463a 100644 --- a/test/warnRuleAsWarning.test.js +++ b/test/warnRuleAsWarning.test.js @@ -130,6 +130,42 @@ describe("loader", () => { expect(getErrors(stats)).toMatchSnapshot("errors"); expect(logs).toMatchSnapshot("logs"); }); + + if (syntax === "sass" && implementationName !== "node-sass") { + it(`should emit good formatted warning ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => { + const testId = getTestId("broken", syntax); + const options = { + implementation, + api, + }; + const compiler = getCompiler(testId, { loader: { options } }); + const stats = await compile(compiler); + const codeFromBundle = getCodeFromBundle(stats, compiler); + const logs = []; + + for (const [name, value] of stats.compilation.logging) { + if (/sass-loader/.test(name)) { + logs.push( + value.map((i) => { + return { + type: i.type, + args: i.args.map((arg) => + arg + .replace(url.pathToFileURL(__dirname), "file:///") + .replace(/\\/g, "/") + ), + }; + }) + ); + } + } + + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats, true)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + expect(logs).toMatchSnapshot("logs"); + }); + } }); }); });