Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Sep 4, 2022
1 parent acb209a commit 58a777f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/config/index.md
Expand Up @@ -724,10 +724,10 @@ RegExp pattern for files that will return an empty CSS file.

#### css.modules

- **Type**: `{ classNamesStrategy? }`
- **Type**: `{ classNameStrategy? }`
- **Default**: `{}`

#### css.modules.classNamesStrategy
#### css.modules.classNameStrategy

- **Type**: `'stable' | 'scoped' | 'non-scoped'`
- **Default**: `'stable'`
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/config.ts
Expand Up @@ -184,7 +184,7 @@ export function resolveConfig(
resolved.css ??= {}
if (typeof resolved.css === 'object') {
resolved.css.modules ??= {}
resolved.css.modules.classNamesStrategy ??= 'stable'
resolved.css.modules.classNameStrategy ??= 'stable'
}

resolved.cache ??= { dir: '' }
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/cssEnabler.ts
Expand Up @@ -60,7 +60,7 @@ export function CSSEnablerPlugin(ctx: Vitest): VitePlugin[] {
// return proxy for css modules, so that imported module has names:
// styles.foo returns a "foo" instead of "undefined"
// we don't use code content to generate hash for "scoped", because it's empty
const scopeStrategy = (typeof ctx.config.css !== 'boolean' && ctx.config.css.modules?.classNamesStrategy) || 'stable'
const scopeStrategy = (typeof ctx.config.css !== 'boolean' && ctx.config.css.modules?.classNameStrategy) || 'stable'
const proxyReturn = getCSSModuleProxyReturn(scopeStrategy, relative(ctx.config.root, id))
const code = `export default new Proxy(Object.create(null), {
get(_, style) {
Expand Down
6 changes: 3 additions & 3 deletions packages/vitest/src/node/plugins/index.ts
Expand Up @@ -102,14 +102,14 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest())
},
}

const classNamesStrategy = preOptions.css && preOptions.css?.modules?.classNamesStrategy
const classNameStrategy = preOptions.css && preOptions.css?.modules?.classNameStrategy

if (classNamesStrategy !== 'scoped') {
if (classNameStrategy !== 'scoped') {
config.css ??= {}
config.css.modules ??= {}
config.css.modules.generateScopedName = (name: string, filename: string) => {
const root = getRoot()
return generateScopedClassName(classNamesStrategy, name, relative(root, filename))!
return generateScopedClassName(classNameStrategy, name, relative(root, filename))!
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/types/config.ts
Expand Up @@ -376,13 +376,13 @@ export interface InlineConfig {
*
* When excluded, the CSS files will be replaced with empty strings to bypass the subsequent processing.
*
* @default { include: [], modules: { classNamesStrategy: false } }
* @default { include: [], modules: { classNameStrategy: false } }
*/
css?: boolean | {
include?: RegExp | RegExp[]
exclude?: RegExp | RegExp[]
modules?: {
classNamesStrategy?: CSSModuleScopeStrategy
classNameStrategy?: CSSModuleScopeStrategy
}
}
/**
Expand Down
4 changes: 2 additions & 2 deletions test/css/testing.mjs
Expand Up @@ -4,8 +4,8 @@ const configs = [
['test/default-css', {}],
['test/process-css', { include: [/App\.css/] }],
['test/process-module', { include: [/App\.module\.css/] }],
['test/scope-module', { include: [/App\.module\.css/], modules: { classNamesStrategy: 'scoped' } }],
['test/non-scope-module', { include: [/App\.module\.css/], modules: { classNamesStrategy: 'non-scoped' } }],
['test/scope-module', { include: [/App\.module\.css/], modules: { classNameStrategy: 'scoped' } }],
['test/non-scope-module', { include: [/App\.module\.css/], modules: { classNameStrategy: 'non-scoped' } }],
]

async function runTests() {
Expand Down

0 comments on commit 58a777f

Please sign in to comment.