Skip to content

Commit 6ca068f

Browse files
avalymichael-ciniawsky
authored andcommitted
test: usage with css-loader and composes (#208)
1 parent 084b2f8 commit 6ca068f

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

test/basicTest.js

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ describe("basic tests", function() {
1212
var requiredCss = ".required { color: blue }",
1313
requiredCssTwo = ".requiredTwo { color: cyan }",
1414
localScopedCss = ":local(.className) { background: red; }",
15+
localComposingCss = `
16+
:local(.composingClass) {
17+
composes: className from './localScoped.css';
18+
color: blue;
19+
}
20+
`,
1521
requiredStyle = `<style type="text/css">${requiredCss}</style>`,
1622
existingStyle = "<style>.existing { color: yellow }</style>",
1723
checkValue = '<div class="check">check</div>',
@@ -71,6 +77,7 @@ describe("basic tests", function() {
7177
fs.writeFileSync(rootDir + "style.css", requiredCss);
7278
fs.writeFileSync(rootDir + "styleTwo.css", requiredCssTwo);
7379
fs.writeFileSync(rootDir + "localScoped.css", localScopedCss);
80+
fs.writeFileSync(rootDir + "localComposing.css", localComposingCss);
7481
}); // before each
7582

7683
it("insert at bottom", function(done) {
@@ -239,7 +246,7 @@ describe("basic tests", function() {
239246
},
240247
{
241248
loader: "css-loader",
242-
options: {
249+
options: {
243250
localIdentName: '[name].[local]_[hash:base64:7]'
244251
}
245252
}
@@ -256,14 +263,72 @@ describe("basic tests", function() {
256263
runCompilerTest(expected, done, function() { return this.css.className; });
257264
}); // it local scope
258265

266+
it("local scope, composing", function(done) {
267+
cssRule.use = [
268+
{
269+
loader: "style-loader"
270+
},
271+
{
272+
loader: "css-loader",
273+
options: {
274+
localIdentName: '[name].[local]_[hash:base64:7]'
275+
}
276+
}
277+
];
278+
279+
fs.writeFileSync(
280+
rootDir + "main.js",
281+
[
282+
"css = require('./localComposing.css');"
283+
].join("\n")
284+
);
285+
286+
let expected =
287+
'localComposing-composingClass_3kXcqag localScoped-className_3dIU6Uf';
288+
runCompilerTest(expected, done, function() {
289+
return this.css.composingClass;
290+
});
291+
}); // it local scope, composing
292+
293+
it("local scope, composing, custom getLocalIdent", function(done) {
294+
cssRule.use = [
295+
{
296+
loader: "style-loader"
297+
},
298+
{
299+
loader: "css-loader",
300+
options: {
301+
ident: 'css',
302+
localIdentName: '[name].[local]_[hash:base64:7]',
303+
getLocalIdent: (context, localIdentName, localName) => {
304+
return 'X' + localName;
305+
}
306+
}
307+
}
308+
];
309+
310+
fs.writeFileSync(
311+
rootDir + "main.js",
312+
[
313+
"css = require('./localComposing.css');"
314+
].join("\n")
315+
);
316+
317+
let expected =
318+
'XcomposingClass XclassName';
319+
runCompilerTest(expected, done, function() {
320+
return this.css.composingClass;
321+
});
322+
}); // it local scope, composing, custom getLocalIdent
323+
259324
it("local scope, useable", function(done) {
260325
cssRule.use = [
261326
{
262327
loader: "style-loader/useable"
263328
},
264329
{
265330
loader: "css-loader",
266-
options: {
331+
options: {
267332
localIdentName: '[name].[local]_[hash:base64:7]'
268333
}
269334
}

0 commit comments

Comments
 (0)