@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs'
22import { fileURLToPath , URL } from 'node:url'
33import { describe , expect , it } from 'vitest'
44
5- import { distPlaygroundContentIncludes } from '../../uno.config'
5+ import distPlaygroundUnoConfigDefault from '../../uno.config'
66import {
77 playgroundBuildAnalyzeMode ,
88 playgroundBuildVisualizerConfig ,
@@ -14,6 +14,21 @@ import {
1414 playgroundVueChunkGroup ,
1515} from '../../vite.config'
1616
17+ // `granularContent(options)` возвращает `{ filesystem, pipeline: { include } }`.
18+ // Раскрываем эту структуру из дефолтного экспорта конфига, чтобы проверить,
19+ // какие исходники реально сканирует playground.
20+ const distPlaygroundContent = ( distPlaygroundUnoConfigDefault as {
21+ content : { filesystem : string [ ] ; pipeline : { include : RegExp [ ] } }
22+ } ) . content
23+ const distPlaygroundContentIncludes = distPlaygroundContent . pipeline . include
24+
25+ // Директория выбранного компонента (`GrButton`) в собранном `dist/` —
26+ // вычисляем из filesystem-glob'а, чтобы проверки опирались на реальный
27+ // абсолютный путь, а не на хардкод.
28+ const distPlaygroundGrButtonDir = distPlaygroundContent . filesystem [ 0 ] . replace ( / \/ \* \* .* $ / , '' )
29+ const distPlaygroundGrButtonFile = `${ distPlaygroundGrButtonDir } /index.js`
30+ const distPlaygroundGrModalFile = `${ distPlaygroundGrButtonDir . replace ( / G r B u t t o n $ / , 'GrModal' ) } /index.js`
31+
1732const distPlaygroundPackageJson = readFileSync (
1833 fileURLToPath ( new URL ( '../../package.json' , import . meta. url ) ) ,
1934 'utf8' ,
@@ -61,9 +76,20 @@ describe('playground config', () => {
6176 } )
6277 } )
6378
64- it ( 'сканирует только isolated исходники playground и не подхватывает dist артефакты' , ( ) => {
65- expect ( distPlaygroundContentIncludes . some ( re => re . test ( '/repo/apps/playground/src/main.ts' ) ) ) . toBe ( true )
66- expect ( distPlaygroundContentIncludes . some ( re => re . test ( '/repo/apps/other-playground/src/App.vue' ) ) ) . toBe ( false )
79+ it ( 'сканирует исходники приложения и только выбранные dist-компоненты granularity, не подхватывая лишние артефакты' , ( ) => {
80+ // filesystem нацелен строго на выбранный компонент (`GrButton`) в `dist/`,
81+ // а не на произвольные dist-артефакты.
82+ expect (
83+ distPlaygroundContent . filesystem . some ( glob => / p a c k a g e s \/ g r a n u l a r i t y \/ d i s t \/ c o m p o n e n t s \/ G r B u t t o n \/ / . test ( glob ) ) ,
84+ ) . toBe ( true )
85+
86+ // Шаблоны исходников приложения (`.vue`) подхватываются стандартным фильтром.
87+ expect ( distPlaygroundContentIncludes . some ( re => re . test ( '/repo/apps/playground/src/App.vue' ) ) ) . toBe ( true )
88+
89+ // Таргетированный include разрешает только директорию выбранного компонента,
90+ // не затрагивая невыбранные компоненты и произвольные dist-артефакты.
91+ expect ( distPlaygroundContentIncludes . some ( re => re . test ( distPlaygroundGrButtonFile ) ) ) . toBe ( true )
92+ expect ( distPlaygroundContentIncludes . some ( re => re . test ( distPlaygroundGrModalFile ) ) ) . toBe ( false )
6793 expect ( distPlaygroundContentIncludes . some ( re => re . test ( '/repo/dist/index.js' ) ) ) . toBe ( false )
6894 } )
6995
@@ -91,7 +117,7 @@ describe('playground config', () => {
91117 expect ( distPlaygroundUnoConfig ) . toContain ( 'presetGranularNode(granularOptions)' )
92118 expect ( distPlaygroundUnoConfig ) . toContain ( 'granularContent(granularOptions)' )
93119 expect ( distPlaygroundUnoConfig ) . toContain ( 'providers: [granularityProvider]' )
94- expect ( distPlaygroundUnoConfig ) . toContain ( "{ provider: '@feugene/granularity', names: [...granularPresetComponents] }" )
120+ expect ( distPlaygroundUnoConfig ) . toContain ( "{provider: '@feugene/granularity', names: [...granularPresetComponents]}" )
95121 expect ( distPlaygroundUnoConfig ) . toContain ( 'tokensFile: granularPresetThemeFiles[0]' )
96122 } )
97123} )
0 commit comments