mirror of
https://github.com/gromlab-ru/svg-sprites.git
synced 2026-07-22 04:40:17 +03:00
test: добавить площадку интеграционного тестирования
- добавлены consumer fixtures для React и Next.js - добавлены typecheck, production build и браузерные smoke-тесты - добавлена интеграционная проверка в CI
This commit is contained in:
8
integration/scripts/apps.mjs
Normal file
8
integration/scripts/apps.mjs
Normal file
@@ -0,0 +1,8 @@
|
||||
export const apps = [
|
||||
{ id: 'react-vite', kind: 'static', output: 'dist' },
|
||||
{ id: 'react-webpack', kind: 'static', output: 'dist' },
|
||||
{ id: 'next-app-turbopack', kind: 'next' },
|
||||
{ id: 'next-app-webpack', kind: 'next' },
|
||||
{ id: 'next-pages-turbopack', kind: 'next' },
|
||||
{ id: 'next-pages-webpack', kind: 'next' },
|
||||
]
|
||||
31
integration/scripts/run-workspaces.mjs
Normal file
31
integration/scripts/run-workspaces.mjs
Normal file
@@ -0,0 +1,31 @@
|
||||
import { spawn } from 'node:child_process'
|
||||
import process from 'node:process'
|
||||
|
||||
import { apps } from './apps.mjs'
|
||||
|
||||
const script = process.argv[2]
|
||||
const requestedApps = new Set(process.argv.slice(3))
|
||||
|
||||
if (!script) {
|
||||
throw new Error('Usage: node scripts/run-workspaces.mjs <script> [app ...]')
|
||||
}
|
||||
|
||||
const selectedApps = requestedApps.size === 0
|
||||
? apps
|
||||
: apps.filter(({ id }) => requestedApps.has(id))
|
||||
|
||||
for (const { id } of selectedApps) {
|
||||
console.log(`\n[${id}] npm run ${script}`)
|
||||
|
||||
const exitCode = await new Promise((resolve, reject) => {
|
||||
const child = spawn('npm', ['run', script, '--workspace', `@svg-sprites-fixtures/${id}`, '--if-present'], {
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32',
|
||||
})
|
||||
|
||||
child.once('error', reject)
|
||||
child.once('exit', (code) => resolve(code ?? 1))
|
||||
})
|
||||
|
||||
if (exitCode !== 0) process.exit(exitCode)
|
||||
}
|
||||
45
integration/scripts/serve-static.mjs
Normal file
45
integration/scripts/serve-static.mjs
Normal file
@@ -0,0 +1,45 @@
|
||||
import fs from 'node:fs'
|
||||
import http from 'node:http'
|
||||
import path from 'node:path'
|
||||
|
||||
const [directory, portValue] = process.argv.slice(2)
|
||||
|
||||
if (!directory || !portValue) {
|
||||
throw new Error('Usage: node scripts/serve-static.mjs <directory> <port>')
|
||||
}
|
||||
|
||||
const root = path.resolve(directory)
|
||||
const mimeTypes = {
|
||||
'.css': 'text/css; charset=utf-8',
|
||||
'.html': 'text/html; charset=utf-8',
|
||||
'.js': 'text/javascript; charset=utf-8',
|
||||
'.json': 'application/json; charset=utf-8',
|
||||
'.svg': 'image/svg+xml',
|
||||
}
|
||||
|
||||
const server = http.createServer((request, response) => {
|
||||
const pathname = decodeURIComponent(new URL(request.url ?? '/', 'http://localhost').pathname)
|
||||
const requestedPath = pathname.endsWith('/') ? `${pathname}index.html` : pathname
|
||||
const filePath = path.resolve(root, `.${requestedPath}`)
|
||||
|
||||
if (filePath !== root && !filePath.startsWith(`${root}${path.sep}`)) {
|
||||
response.writeHead(403).end('Forbidden')
|
||||
return
|
||||
}
|
||||
|
||||
const resolvedPath = fs.existsSync(filePath) && fs.statSync(filePath).isFile()
|
||||
? filePath
|
||||
: path.join(root, 'index.html')
|
||||
|
||||
if (!fs.existsSync(resolvedPath)) {
|
||||
response.writeHead(404).end('Not found')
|
||||
return
|
||||
}
|
||||
|
||||
response.setHeader('Content-Type', mimeTypes[path.extname(resolvedPath)] ?? 'application/octet-stream')
|
||||
fs.createReadStream(resolvedPath).pipe(response)
|
||||
})
|
||||
|
||||
server.listen(Number(portValue), '127.0.0.1', () => {
|
||||
console.log(`Serving ${root} on http://127.0.0.1:${portValue}`)
|
||||
})
|
||||
Reference in New Issue
Block a user