Skip to content

Commit b9a34d4

Browse files
author
fureev
committed
fix: test
1 parent b94146c commit b9a34d4

2 files changed

Lines changed: 53 additions & 8 deletions

File tree

apps/playground-5/src/__tests__/config.test.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { readFileSync } from 'node:fs'
22
import { fileURLToPath, URL } from 'node:url'
33
import { describe, expect, it } from 'vitest'
44

5-
import {
6-
playground5ContentIncludes,
5+
import playground5UnoConfigDefault, {
76
playground5GranularityLayer,
87
} from '../../uno.config'
98
import {
@@ -12,6 +11,19 @@ import {
1211
playground5VueChunkGroup,
1312
} from '../../vite.config'
1413

14+
// `granularContent(options)` возвращает `{ filesystem, pipeline: { include } }`.
15+
// Раскрываем эту структуру из дефолтного экспорта конфига.
16+
const playground5Content = (playground5UnoConfigDefault as {
17+
content: { filesystem: string[]; pipeline: { include: RegExp[] } }
18+
}).content
19+
const playground5ContentIncludes = playground5Content.pipeline.include
20+
21+
// Директория выбранного компонента (`GrButton`) в собранном `dist/`,
22+
// вычисленная из filesystem-glob'а (реальный абсолютный путь).
23+
const playground5GrButtonDir = playground5Content.filesystem[0].replace(/\/\*\*.*$/, '')
24+
const playground5GrButtonFile = `${playground5GrButtonDir}/index.js`
25+
const playground5GrModalFile = `${playground5GrButtonDir.replace(/GrButton$/, 'GrModal')}/index.js`
26+
1527
const playground5MainEntry = readFileSync(
1628
fileURLToPath(new URL('../main.ts', import.meta.url)),
1729
'utf8',
@@ -60,8 +72,15 @@ describe('playground-5 config', () => {
6072
expect(playground5UnoConfig).toContain('granularContent(granularOptions)')
6173
expect(playground5UnoConfig).toContain('layer: playground5GranularityLayer')
6274
expect(playground5GranularityLayer).toBe('granular')
75+
// Шаблоны исходников приложения (`.vue`) подхватываются стандартным фильтром.
6376
expect(playground5ContentIncludes.some(re => re.test('/repo/apps/playground-5/src/App.vue'))).toBe(true)
64-
expect(playground5ContentIncludes.some(re => re.test('/repo/apps/playground-6/src/App.vue'))).toBe(false)
77+
// filesystem и таргетированный include нацелены строго на выбранный компонент
78+
// (`GrButton`) в `dist/`, не затрагивая невыбранные компоненты и артефакты.
79+
expect(
80+
playground5Content.filesystem.some(glob => /packages\/granularity\/dist\/components\/GrButton\//.test(glob)),
81+
).toBe(true)
82+
expect(playground5ContentIncludes.some(re => re.test(playground5GrButtonFile))).toBe(true)
83+
expect(playground5ContentIncludes.some(re => re.test(playground5GrModalFile))).toBe(false)
6584
expect(playground5MainEntry).toContain('await Promise.all([')
6685
expect(playground5MainEntry).toContain("import('./reset')")
6786
expect(playground5MainEntry).toContain("import('./granularity')")

apps/playground/src/__tests__/distPlaygroundConfig.test.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs'
22
import { fileURLToPath, URL } from 'node:url'
33
import { describe, expect, it } from 'vitest'
44

5-
import { distPlaygroundContentIncludes } from '../../uno.config'
5+
import distPlaygroundUnoConfigDefault from '../../uno.config'
66
import {
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(/GrButton$/, 'GrModal')}/index.js`
31+
1732
const 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 => /packages\/granularity\/dist\/components\/GrButton\//.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

Comments
 (0)