| 411 | ) |
| 412 | }, |
| 413 | async dumpFiles(pattern) { |
| 414 | let files = await context.fs.glob(pattern) |
| 415 | return `\n${files |
| 416 | .slice() |
| 417 | .sort((a: [string], z: [string]) => { |
| 418 | let aParts = a[0].split('/') |
| 419 | let zParts = z[0].split('/') |
| 420 | |
| 421 | let aFile = aParts.at(-1) |
| 422 | let zFile = zParts.at(-1) |
| 423 | |
| 424 | // Sort by depth, shallow first |
| 425 | if (aParts.length < zParts.length) return -1 |
| 426 | if (aParts.length > zParts.length) return 1 |
| 427 | |
| 428 | // Sort by folder names, alphabetically |
| 429 | for (let i = 0; i < aParts.length - 1; i++) { |
| 430 | let diff = aParts[i].localeCompare(zParts[i]) |
| 431 | if (diff !== 0) return diff |
| 432 | } |
| 433 | |
| 434 | // Sort by filename, sort files named `index` before others |
| 435 | if (aFile?.startsWith('index') && !zFile?.startsWith('index')) return -1 |
| 436 | if (zFile?.startsWith('index') && !aFile?.startsWith('index')) return 1 |
| 437 | |
| 438 | // Sort by filename, alphabetically |
| 439 | return a[0].localeCompare(z[0]) |
| 440 | }) |
| 441 | .map(([file, content]) => `--- ${file} ---\n${content || '<EMPTY>'}`) |
| 442 | .join('\n\n') |
| 443 | .trim()}\n` |
| 444 | }, |
| 445 | async expectFileToContain(filePath, contents) { |
| 446 | return retryAssertion(async () => { |
| 447 | let fileContent = await this.read(filePath) |