Skip to content

Commit

Permalink
test: localIdentName option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Nov 27, 2018
1 parent 0a68bb4 commit a421ab4
Show file tree
Hide file tree
Showing 5 changed files with 520 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
}
}
const request = path.relative(options.context, loaderContext.resourcePath);

/* eslint-disable no-console */
console.log(options.context);
console.log(request);
console.log(loaderContext.resourcePath);
console.log(localIdentName);
/* eslint-enable no-console */

// eslint-disable-next-line no-param-reassign
options.content = `${options.hashPrefix + request}+${localName}`;
// eslint-disable-next-line no-param-reassign
Expand Down
365 changes: 365 additions & 0 deletions test/__snapshots__/localIdentName-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,365 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`localIdentName option basic: errors 1`] = `Array []`;

exports[`localIdentName option basic: locals 1`] = `
Object {
"-a0-34a___f": "_2nJ5XVdGAwkzTI324zw6Pg",
"_test": "_23te_4QsMe8I6hzxjH0MUx",
"className": "_1E8Hx67EIx_tltp58vyNJ0",
"someId": "_3w7JetWWlr8Zm4sxZ-ANzU",
"subClass": "_3lo0JvMLLK_gjw1mbsomb3",
"test": "NW9YAb4ijHq-3lCxF5vFu",
}
`;

exports[`localIdentName option basic: module (evaluated) 1`] = `
Array [
Array [
1,
".NW9YAb4ijHq-3lCxF5vFu {
background: red;
}
._23te_4QsMe8I6hzxjH0MUx {
background: blue;
}
._1E8Hx67EIx_tltp58vyNJ0 {
background: red;
}
#_3w7JetWWlr8Zm4sxZ-ANzU {
background: green;
}
._1E8Hx67EIx_tltp58vyNJ0 ._3lo0JvMLLK_gjw1mbsomb3 {
color: green;
}
#_3w7JetWWlr8Zm4sxZ-ANzU ._3lo0JvMLLK_gjw1mbsomb3 {
color: blue;
}
._2nJ5XVdGAwkzTI324zw6Pg {
color: red;
}
",
"",
],
]
`;

exports[`localIdentName option basic: warnings 1`] = `Array []`;

exports[`localIdentName option should have hash: errors 1`] = `Array []`;

exports[`localIdentName option should have hash: locals 1`] = `
Object {
"-a0-34a___f": "localIdentName---a0-34a___f--3RHUZ",
"_test": "localIdentName--_test--3Q--B",
"className": "localIdentName--className--3wBIH",
"someId": "localIdentName--someId--mxosG",
"subClass": "localIdentName--subClass--3jIM-",
"test": "localIdentName--test--1Os7J",
}
`;

exports[`localIdentName option should have hash: module (evaluated) 1`] = `
Array [
Array [
1,
".localIdentName--test--1Os7J {
background: red;
}
.localIdentName--_test--3Q--B {
background: blue;
}
.localIdentName--className--3wBIH {
background: red;
}
#localIdentName--someId--mxosG {
background: green;
}
.localIdentName--className--3wBIH .localIdentName--subClass--3jIM- {
color: green;
}
#localIdentName--someId--mxosG .localIdentName--subClass--3jIM- {
color: blue;
}
.localIdentName---a0-34a___f--3RHUZ {
color: red;
}
",
"",
],
]
`;

exports[`localIdentName option should have hash: warnings 1`] = `Array []`;

exports[`localIdentName option should have path naming with context: errors 1`] = `Array []`;

exports[`localIdentName option should have path naming with context: locals 1`] = `
Object {
"-a0-34a___f": "fixtures-modules--localIdentName---a0-34a___f",
"_test": "fixtures-modules--localIdentName--_test",
"className": "fixtures-modules--localIdentName--className",
"someId": "fixtures-modules--localIdentName--someId",
"subClass": "fixtures-modules--localIdentName--subClass",
"test": "fixtures-modules--localIdentName--test",
}
`;

exports[`localIdentName option should have path naming with context: module (evaluated) 1`] = `
Array [
Array [
1,
".fixtures-modules--localIdentName--test {
background: red;
}
.fixtures-modules--localIdentName--_test {
background: blue;
}
.fixtures-modules--localIdentName--className {
background: red;
}
#fixtures-modules--localIdentName--someId {
background: green;
}
.fixtures-modules--localIdentName--className .fixtures-modules--localIdentName--subClass {
color: green;
}
#fixtures-modules--localIdentName--someId .fixtures-modules--localIdentName--subClass {
color: blue;
}
.fixtures-modules--localIdentName---a0-34a___f {
color: red;
}
",
"",
],
]
`;

exports[`localIdentName option should have path naming with context: warnings 1`] = `Array []`;

exports[`localIdentName option should prefixes leading hyphen + digit with underscore: errors 1`] = `Array []`;

exports[`localIdentName option should prefixes leading hyphen + digit with underscore: locals 1`] = `
Object {
"-a0-34a___f": "_-1-a0-34a___f",
"_test": "_-1_test",
"className": "_-1className",
"someId": "_-1someId",
"subClass": "_-1subClass",
"test": "_-1test",
}
`;

exports[`localIdentName option should prefixes leading hyphen + digit with underscore: module (evaluated) 1`] = `
Array [
Array [
1,
"._-1test {
background: red;
}
._-1_test {
background: blue;
}
._-1className {
background: red;
}
#_-1someId {
background: green;
}
._-1className ._-1subClass {
color: green;
}
#_-1someId ._-1subClass {
color: blue;
}
._-1-a0-34a___f {
color: red;
}
",
"",
],
]
`;

exports[`localIdentName option should prefixes leading hyphen + digit with underscore: warnings 1`] = `Array []`;

exports[`localIdentName option should prefixes two leading hyphens with underscore: errors 1`] = `Array []`;

exports[`localIdentName option should prefixes two leading hyphens with underscore: locals 1`] = `
Object {
"-a0-34a___f": "_---a0-34a___f",
"_test": "_--_test",
"className": "_--className",
"someId": "_--someId",
"subClass": "_--subClass",
"test": "_--test",
}
`;

exports[`localIdentName option should prefixes two leading hyphens with underscore: module (evaluated) 1`] = `
Array [
Array [
1,
"._--test {
background: red;
}
._--_test {
background: blue;
}
._--className {
background: red;
}
#_--someId {
background: green;
}
._--className ._--subClass {
color: green;
}
#_--someId ._--subClass {
color: blue;
}
._---a0-34a___f {
color: red;
}
",
"",
],
]
`;

exports[`localIdentName option should prefixes two leading hyphens with underscore: warnings 1`] = `Array []`;

exports[`localIdentName option should saves underscore prefix in exported class names: errors 1`] = `Array []`;

exports[`localIdentName option should saves underscore prefix in exported class names: locals 1`] = `
Object {
"-a0-34a___f": "-a0-34a___f",
"_test": "_test",
"className": "className",
"someId": "someId",
"subClass": "subClass",
"test": "test",
}
`;

exports[`localIdentName option should saves underscore prefix in exported class names: module (evaluated) 1`] = `
Array [
Array [
1,
".test {
background: red;
}
._test {
background: blue;
}
.className {
background: red;
}
#someId {
background: green;
}
.className .subClass {
color: green;
}
#someId .subClass {
color: blue;
}
.-a0-34a___f {
color: red;
}
",
"",
],
]
`;

exports[`localIdentName option should saves underscore prefix in exported class names: warnings 1`] = `Array []`;

exports[`localIdentName option should use hash prefix: errors 1`] = `Array []`;

exports[`localIdentName option should use hash prefix: locals 1`] = `
Object {
"-a0-34a___f": "-a0-34a___f--e99d667fe0ceff9363b011302ac3f508",
"_test": "_test--d745495d407559ef605c9072243801fd",
"className": "className--eab624d1bc6b9c6b6a4278d1030dd690",
"someId": "someId--a0ce220cc9bbb1ee0e85cc0d1f0c6aa9",
"subClass": "subClass--2c82998be8a2b2e94ad7be56c9e685cd",
"test": "test--307c32aa793aaec9aecded85a9fdd448",
}
`;

exports[`localIdentName option should use hash prefix: module (evaluated) 1`] = `
Array [
Array [
1,
".test--307c32aa793aaec9aecded85a9fdd448 {
background: red;
}
._test--d745495d407559ef605c9072243801fd {
background: blue;
}
.className--eab624d1bc6b9c6b6a4278d1030dd690 {
background: red;
}
#someId--a0ce220cc9bbb1ee0e85cc0d1f0c6aa9 {
background: green;
}
.className--eab624d1bc6b9c6b6a4278d1030dd690 .subClass--2c82998be8a2b2e94ad7be56c9e685cd {
color: green;
}
#someId--a0ce220cc9bbb1ee0e85cc0d1f0c6aa9 .subClass--2c82998be8a2b2e94ad7be56c9e685cd {
color: blue;
}
.-a0-34a___f--e99d667fe0ceff9363b011302ac3f508 {
color: red;
}
",
"",
],
]
`;

exports[`localIdentName option should use hash prefix: warnings 1`] = `Array []`;
Loading

0 comments on commit a421ab4

Please sign in to comment.