| 587 | } |
| 588 | |
| 589 | public async destroy(): Promise<void> { |
| 590 | try { |
| 591 | require('console').time('destroyed next instance') |
| 592 | |
| 593 | if (this.isDestroyed) { |
| 594 | throw new Error(`next instance already destroyed`, { |
| 595 | cause: this.isDestroyed, |
| 596 | }) |
| 597 | } |
| 598 | this.isDestroyed = Error() |
| 599 | Error.captureStackTrace(this.isDestroyed, this.destroy) |
| 600 | |
| 601 | this.emit('destroy', []) |
| 602 | await this.stop().catch(console.error) |
| 603 | |
| 604 | if (process.env.TRACE_PLAYWRIGHT) { |
| 605 | await fs |
| 606 | .cp( |
| 607 | path.join(this.testDir, this.distDir, 'trace'), |
| 608 | path.join( |
| 609 | __dirname, |
| 610 | '../../traces', |
| 611 | `${path |
| 612 | .relative( |
| 613 | path.join(__dirname, '../../'), |
| 614 | process.env.TEST_FILE_PATH! |
| 615 | ) |
| 616 | .replace(/\//g, '-')}`, |
| 617 | `next-trace` |
| 618 | ), |
| 619 | { recursive: true } |
| 620 | ) |
| 621 | .catch((e) => { |
| 622 | require('console').error(e) |
| 623 | }) |
| 624 | } |
| 625 | |
| 626 | if (!process.env.NEXT_TEST_SKIP_CLEANUP) { |
| 627 | // Faster than `await fs.rm`. Benchmark before change. |
| 628 | rmSync(this.testDir, { recursive: true, force: true }) |
| 629 | if (this.tmpRepoDir) { |
| 630 | rmSync(this.tmpRepoDir, { recursive: true, force: true }) |
| 631 | } |
| 632 | } |
| 633 | require('console').timeEnd(`destroyed next instance`) |
| 634 | } catch (err) { |
| 635 | require('console').error('Error while destroying', err) |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | public get url() { |
| 640 | return this._url |