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 58dd0d3
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 2 deletions.
169 changes: 169 additions & 0 deletions test/__snapshots__/localIdentName-option.test.js.snap
@@ -0,0 +1,169 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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

exports[`localIdentName option should have hash: locals 1`] = `
Object {
"_test": "localIdentName--_test--3Q--B",
"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;
}
",
"",
],
]
`;

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 {
"_test": "fixtures-modules--localIdentName--_test",
"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;
}
",
"",
],
]
`;

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 {
"_test": "_-1_test",
"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;
}
",
"",
],
]
`;

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 {
"_test": "_--_test",
"test": "_--test",
}
`;

exports[`localIdentName option should prefixes two leading hyphens with underscore: module (evaluated) 1`] = `
Array [
Array [
1,
"._--test {
background: red;
}
._--_test {
background: blue;
}
",
"",
],
]
`;

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 {
"_test": "_test",
"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;
}
",
"",
],
]
`;

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 {
"_test": "_test--d745495d407559ef605c9072243801fd",
"test": "test--307c32aa793aaec9aecded85a9fdd448",
}
`;

exports[`localIdentName option should use hash prefix: module (evaluated) 1`] = `
Array [
Array [
1,
".test--307c32aa793aaec9aecded85a9fdd448 {
background: red;
}
._test--d745495d407559ef605c9072243801fd {
background: blue;
}
",
"",
],
]
`;

exports[`localIdentName option should use hash prefix: warnings 1`] = `Array []`;
7 changes: 7 additions & 0 deletions test/fixtures/modules/localIdentName.css
@@ -0,0 +1,7 @@
:local(.test) {
background: red;
}

:local(._test) {
background: blue;
}
107 changes: 107 additions & 0 deletions test/localIdentName-option.test.js
@@ -0,0 +1,107 @@
const path = require('path');

const { webpack, evaluated } = require('./helpers');

describe('localIdentName option', () => {
it('should have hash', async () => {
const config = {
loader: {
options: {
localIdentName: '[name]--[local]--[hash:base64:5]',
context: path.resolve(__dirname),
},
},
};
const testId = './modules/localIdentName.css';
const stats = await webpack(testId, config);
const { modules } = stats.toJson();
const module = modules.find((m) => m.id === testId);
const evaluatedModule = evaluated(module.source, modules);

expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
expect(evaluatedModule.locals).toMatchSnapshot('locals');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it('should have path naming with context', async () => {
const config = {
loader: {
options: {
localIdentName: '[path]-[name]--[local]',
context: path.resolve(__dirname),
},
},
};
const testId = './modules/localIdentName.css';
const stats = await webpack(testId, config);
const { modules } = stats.toJson();
const module = modules.find((m) => m.id === testId);
const evaluatedModule = evaluated(module.source, modules);

expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
expect(evaluatedModule.locals).toMatchSnapshot('locals');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it('should use hash prefix', async () => {
const config = {
loader: {
options: { localIdentName: '[local]--[hash]', hashPrefix: 'x' },
},
};
const testId = './modules/localIdentName.css';
const stats = await webpack(testId, config);
const { modules } = stats.toJson();
const module = modules.find((m) => m.id === testId);
const evaluatedModule = evaluated(module.source, modules);

expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
expect(evaluatedModule.locals).toMatchSnapshot('locals');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it('should prefixes leading hyphen + digit with underscore', async () => {
const config = { loader: { options: { localIdentName: '-1[local]' } } };
const testId = './modules/localIdentName.css';
const stats = await webpack(testId, config);
const { modules } = stats.toJson();
const module = modules.find((m) => m.id === testId);
const evaluatedModule = evaluated(module.source, modules);

expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
expect(evaluatedModule.locals).toMatchSnapshot('locals');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it('should prefixes two leading hyphens with underscore', async () => {
const config = { loader: { options: { localIdentName: '--[local]' } } };
const testId = './modules/localIdentName.css';
const stats = await webpack(testId, config);
const { modules } = stats.toJson();
const module = modules.find((m) => m.id === testId);
const evaluatedModule = evaluated(module.source, modules);

expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
expect(evaluatedModule.locals).toMatchSnapshot('locals');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it('should saves underscore prefix in exported class names', async () => {
const config = { loader: { options: { localIdentName: '[local]' } } };
const testId = './modules/localIdentName.css';
const stats = await webpack(testId, config);
const { modules } = stats.toJson();
const module = modules.find((m) => m.id === testId);
const evaluatedModule = evaluated(module.source, modules);

expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
expect(evaluatedModule.locals).toMatchSnapshot('locals');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});
});
2 changes: 0 additions & 2 deletions test/modules-option.test.js
Expand Up @@ -21,8 +21,6 @@ describe('modules option', () => {
const module = modules.find((m) => m.id === testId);
const evaluatedModule = evaluated(module.source, modules);

// console.log(module)

expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
expect(evaluatedModule.locals).toMatchSnapshot('locals');
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
Expand Down

0 comments on commit 58dd0d3

Please sign in to comment.