Skip to content

Commit c170a4a

Browse files
test: sass-loader (#831)
1 parent da95db8 commit c170a4a

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed

package-lock.json

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
"postcss-loader": "^3.0.0",
4747
"postcss-preset-env": "^6.4.0",
4848
"prettier": "^1.15.2",
49+
"sass": "^1.15.1",
50+
"sass-loader": "^7.1.0",
4951
"standard-version": "^4.0.0",
5052
"strip-ansi": "^5.0.0",
5153
"webpack": "^4.26.1"

test/__snapshots__/loader.test.js.snap

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,32 @@ exports.push([module.id, \\":root {\\\\n --fontSize: 1rem;\\\\n --mainColor: r
527527
`;
528528

529529
exports[`loader using together with "postcss-loader": warnings 1`] = `Array []`;
530+
531+
exports[`loader using together with "sass-loader": errors 1`] = `Array []`;
532+
533+
exports[`loader using together with "sass-loader": module (evaluated) 1`] = `
534+
Array [
535+
Array [
536+
1,
537+
"body {
538+
font: 100% Helvetica, sans-serif;
539+
color: #333;
540+
}",
541+
"",
542+
],
543+
]
544+
`;
545+
546+
exports[`loader using together with "sass-loader": module 1`] = `
547+
"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false);
548+
// imports
549+
550+
551+
// module
552+
exports.push([module.id, \\"body {\\\\n font: 100% Helvetica, sans-serif;\\\\n color: #333;\\\\n}\\", \\"\\"]);
553+
554+
// exports
555+
"
556+
`;
557+
558+
exports[`loader using together with "sass-loader": warnings 1`] = `Array []`;

test/fixtures/scss/source.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$font-stack: Helvetica, sans-serif;
2+
$primary-color: #333;
3+
4+
body {
5+
font: 100% $font-stack;
6+
color: $primary-color;
7+
}

test/helpers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ const moduleConfig = (config) => {
114114
},
115115
]
116116
: []
117+
)
118+
.concat(
119+
config.sassLoader
120+
? [
121+
{
122+
loader: 'sass-loader',
123+
options: config.sassLoaderOptions || {},
124+
},
125+
]
126+
: []
117127
),
118128
},
119129
{

test/loader.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,26 @@ describe('loader', () => {
109109
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
110110
expect(stats.compilation.errors).toMatchSnapshot('errors');
111111
});
112+
113+
it('using together with "sass-loader"', async () => {
114+
const config = {
115+
loader: { test: /\.s[ca]ss$/i },
116+
sassLoader: true,
117+
sassLoaderOptions: {
118+
// eslint-disable-next-line global-require
119+
implementation: require('sass'),
120+
},
121+
};
122+
const testId = './scss/source.scss';
123+
const stats = await webpack(testId, config);
124+
const { modules } = stats.toJson();
125+
const module = modules.find((m) => m.id === testId);
126+
127+
expect(module.source).toMatchSnapshot('module');
128+
expect(evaluated(module.source, modules)).toMatchSnapshot(
129+
'module (evaluated)'
130+
);
131+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
132+
expect(stats.compilation.errors).toMatchSnapshot('errors');
133+
});
112134
});

0 commit comments

Comments
 (0)