-
-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a68bb4
commit 58dd0d3
Showing
4 changed files
with
283 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 []`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
:local(.test) { | ||
background: red; | ||
} | ||
|
||
:local(._test) { | ||
background: blue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters