increase test coverage
extend test coverage
This commit is contained in:
@@ -6,7 +6,7 @@ import string from 'vite-plugin-string'
|
||||
|
||||
const root = process.cwd()
|
||||
const extensionsRoot = resolve(root, 'src/editor/extensions')
|
||||
const outDir = resolve(root, 'dist/editor')
|
||||
const outDir = resolve(root, 'dist/editor/extensions')
|
||||
|
||||
const htmlStringPlugin = string({
|
||||
include: [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { cp, mkdir } from 'node:fs/promises'
|
||||
import { resolve } from 'node:path'
|
||||
import { cp, mkdir, readFile, writeFile } from 'node:fs/promises'
|
||||
import { createInstrumenter } from 'istanbul-lib-instrument'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
|
||||
const root = process.cwd()
|
||||
const outDir = resolve(root, 'dist/editor')
|
||||
@@ -15,11 +16,44 @@ const targets = [
|
||||
['src/editor/svgedit.css', 'svgedit.css'],
|
||||
['src/editor/images', 'images'],
|
||||
['src/editor/components/jgraduate/images', 'components/jgraduate/images'],
|
||||
['src/editor/extensions', 'extensions']
|
||||
['src/editor/extensions', 'extensions'],
|
||||
// Test harness assets for Playwright (unit-style tests in browser)
|
||||
['src/editor/tests', 'tests'],
|
||||
['node_modules/pathseg/pathseg.js', 'tests/vendor/pathseg/pathseg.js']
|
||||
]
|
||||
|
||||
for (const [src, dest] of targets) {
|
||||
await cp(resolve(root, src), resolve(outDir, dest), { recursive: true })
|
||||
}
|
||||
|
||||
// Instrument svgcanvas sources when collecting coverage so Playwright runs hit instrumented code.
|
||||
const svgCanvasSrc = resolve(root, 'packages/svgcanvas')
|
||||
const svgCanvasDest = resolve(outDir, 'tests/vendor/svgcanvas')
|
||||
await cp(svgCanvasSrc, svgCanvasDest, { recursive: true })
|
||||
if (process.env.COVERAGE === 'true') {
|
||||
const instrumenter = createInstrumenter({ compact: false })
|
||||
const instrumentPaths = [
|
||||
'common/util.js',
|
||||
'core/touch.js',
|
||||
'core/namespaces.js',
|
||||
'core/utilities.js',
|
||||
'core/math.js',
|
||||
'core/path.js',
|
||||
'core/coords.js',
|
||||
'core/units.js',
|
||||
'core/draw.js',
|
||||
'core/history.js',
|
||||
'core/recalculate.js',
|
||||
'core/clear.js'
|
||||
]
|
||||
for (const relativePath of instrumentPaths) {
|
||||
const sourceFile = resolve(svgCanvasSrc, relativePath)
|
||||
const destFile = resolve(svgCanvasDest, relativePath)
|
||||
const code = await readFile(sourceFile, 'utf8')
|
||||
const instrumented = instrumenter.instrumentSync(code, sourceFile)
|
||||
await mkdir(dirname(destFile), { recursive: true })
|
||||
await writeFile(destFile, instrumented, 'utf8')
|
||||
}
|
||||
}
|
||||
|
||||
console.info('Copied static editor assets to dist/editor')
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { spawn } from 'node:child_process'
|
||||
import { copyFile, mkdir } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { existsSync } from 'node:fs'
|
||||
|
||||
@@ -36,9 +37,19 @@ const ensureBrowser = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const seedNycFromVitest = async () => {
|
||||
const vitestCoverage = join(process.cwd(), 'coverage', 'coverage-final.json')
|
||||
if (existsSync(vitestCoverage)) {
|
||||
const nycOutputDir = join(process.cwd(), '.nyc_output')
|
||||
await mkdir(nycOutputDir, { recursive: true })
|
||||
await copyFile(vitestCoverage, join(nycOutputDir, 'vitest.json'))
|
||||
}
|
||||
}
|
||||
|
||||
if (await hasPlaywright()) {
|
||||
await ensureBrowser()
|
||||
await run('rimraf', ['.nyc_output/*'], { shell: true })
|
||||
await seedNycFromVitest()
|
||||
await run('npx', ['playwright', 'test'])
|
||||
await run('npx', ['nyc', 'report', '--reporter', 'text-summary', '--reporter', 'json-summary'])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user