|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Facebook, Inc. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +'use strict'; |
| 9 | + |
| 10 | +const getCSSModuleLocalIdent = require('../getCSSModuleLocalIdent'); |
| 11 | + |
| 12 | +const rootContext = '/path'; |
| 13 | +const defaultClassName = 'class'; |
| 14 | +const options = { context: undefined, hashPrefix: '', regExp: null }; |
| 15 | + |
| 16 | +const tests = [ |
| 17 | + { |
| 18 | + resourcePath: '/path/to/file.module.css', |
| 19 | + expected: 'file_class__13tFD', |
| 20 | + }, |
| 21 | + { |
| 22 | + resourcePath: '/path/to/file.module.scss', |
| 23 | + expected: 'file_class__3lYUI', |
| 24 | + }, |
| 25 | + { |
| 26 | + resourcePath: '/path/to/file.module.sass', |
| 27 | + expected: 'file_class__2KnOB', |
| 28 | + }, |
| 29 | + { |
| 30 | + resourcePath: '/path/to/file.name.module.css', |
| 31 | + expected: 'file_name_class__1OzEh', |
| 32 | + }, |
| 33 | +]; |
| 34 | + |
| 35 | +describe('getCSSModuleLocalIdent', () => { |
| 36 | + tests.forEach(test => { |
| 37 | + const { className = defaultClassName, expected, resourcePath } = test; |
| 38 | + it(JSON.stringify({ resourcePath, className }), () => { |
| 39 | + const ident = getCSSModuleLocalIdent( |
| 40 | + { |
| 41 | + resourcePath, |
| 42 | + rootContext, |
| 43 | + }, |
| 44 | + '[hash:base64]', |
| 45 | + className, |
| 46 | + options |
| 47 | + ); |
| 48 | + expect(ident).toBe(expected); |
| 49 | + }); |
| 50 | + }); |
| 51 | +}); |
0 commit comments