( match: string | RegExp, base = '', assets = 'assets', matchAll = false, )
| 220 | } |
| 221 | |
| 222 | export function findAssetFile( |
| 223 | match: string | RegExp, |
| 224 | base = '', |
| 225 | assets = 'assets', |
| 226 | matchAll = false, |
| 227 | ): string | undefined { |
| 228 | const assetsDir = path.join(testDir, 'dist', base, assets) |
| 229 | let files: string[] |
| 230 | try { |
| 231 | files = fs.readdirSync(assetsDir) |
| 232 | } catch (e) { |
| 233 | if (e.code === 'ENOENT') { |
| 234 | return undefined |
| 235 | } |
| 236 | throw e |
| 237 | } |
| 238 | if (matchAll) { |
| 239 | const matchedFiles = files.filter((file) => file.match(match)) |
| 240 | return matchedFiles.length |
| 241 | ? matchedFiles |
| 242 | .map((file) => |
| 243 | fs.readFileSync(path.resolve(assetsDir, file), 'utf-8'), |
| 244 | ) |
| 245 | .join('') |
| 246 | : undefined |
| 247 | } else { |
| 248 | const matchedFile = files.find((file) => file.match(match)) |
| 249 | return matchedFile |
| 250 | ? fs.readFileSync(path.resolve(assetsDir, matchedFile), 'utf-8') |
| 251 | : undefined |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | export function readManifest(base = ''): Manifest { |
| 256 | return JSON.parse( |
no test coverage detected