mirror of
https://github.com/gromlab-ru/svg-sprites.git
synced 2026-07-22 04:40:17 +03:00
Добавлены exact modes: - vue@vite и vue@webpack - nuxt@vite и nuxt@webpack - svelte@vite, svelte@webpack и sveltekit@vite - angular@application и angular@webpack - astro@vite - solid@vite, solid@webpack и solid-start@vite - preact@vite и preact@webpack - qwik@vite - lit@vite и lit@webpack - alpine@vite и alpine@webpack Для каждого mode реализованы изолированный adapter, нативный framework-компонент, declarations, manifest, CSS и внешний asset URL. Добавлены production integration-стенды с генерацией, typecheck, сборкой и Playwright-проверкой рендера спрайта и Viewer. Обновлены Viewer, RU/EN-гайды, README, technical reference и AI skills. Итоговая матрица включает 29 exact modes. Проверки: - 48 unit-тестов - 29 integration E2E-тестов
53 lines
2.1 KiB
JavaScript
53 lines
2.1 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import fs from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
import test from 'node:test'
|
|
|
|
import { generateSprite, isSpriteMode } from '../dist/index.js'
|
|
|
|
const MODES = [
|
|
{ mode: 'preact@vite', target: 'vite', asset: /sprite\.svg\?no-inline/ },
|
|
{ mode: 'preact@webpack', target: 'webpack', asset: /new URL\('\.\.\/sprite\.svg', import\.meta\.url\)\.href/ },
|
|
]
|
|
|
|
function fixture() {
|
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), 'svg-sprites-preact-'))
|
|
fs.mkdirSync(path.join(rootDir, 'icons'))
|
|
fs.writeFileSync(
|
|
path.join(rootDir, 'icons', 'check.svg'),
|
|
'<svg viewBox="0 0 24 24"><path fill="#16a34a" d="M2 12l6 6L22 4" /></svg>',
|
|
)
|
|
return rootDir
|
|
}
|
|
|
|
test('generates every isolated Preact family contract', async () => {
|
|
for (const contract of MODES) {
|
|
assert.equal(isSpriteMode(contract.mode), true)
|
|
const result = await generateSprite(fixture(), {
|
|
mode: contract.mode,
|
|
name: 'app-icons',
|
|
generatedNotice: false,
|
|
})
|
|
const component = fs.readFileSync(path.join(result.generatedDir, 'preact', 'preact-component.js'), 'utf8')
|
|
const componentTypes = fs.readFileSync(path.join(result.generatedDir, 'preact', 'preact-component.d.ts'), 'utf8')
|
|
const manifest = fs.readFileSync(result.manifestPath, 'utf8')
|
|
|
|
assert.equal(result.mode, contract.mode)
|
|
assert.equal(result.target, contract.target)
|
|
assert.deepEqual(fs.readdirSync(path.join(result.generatedDir, 'preact')).sort(), [
|
|
'preact-component.d.ts',
|
|
'preact-component.js',
|
|
'preact-component.module.css',
|
|
])
|
|
assert.match(component, /import \{ h \} from 'preact'/)
|
|
assert.match(component, /export const AppIconsIcon/)
|
|
assert.match(component, contract.asset)
|
|
assert.match(componentTypes, /FunctionalComponent<AppIconsIconProps>/)
|
|
assert.match(manifest, /"framework": "preact"/)
|
|
assert.match(manifest, new RegExp(`"mode": ${JSON.stringify(contract.mode)}`))
|
|
assert.doesNotMatch(component, /customElements|HTMLElement|gromlab-sprite-viewer/)
|
|
assert.equal(fs.existsSync(path.join(result.generatedDir, 'preact', 'preact-component.tsx')), false)
|
|
}
|
|
})
|