Skip to main content

How it works

After the setup, every time you run your Playwright tests, the @test2doc/playwright reporter will attempt to cleanup previously generated files and directories and automatically generate a new markdown file in your specified Docusaurus docs directory for each test file and/or top-level describe block found in your Playwright test files.

Note: Any test files with a .setup.ts (or .setup.js) extension are automatically ignored and will not generate documentation. This is to prevent Playwright global setup/auth files from appearing in your docs.

Cleanup Step​

The cleanup step is designed to maintain a tidy output directory by removing outdated files and directories created by the Test2Doc reporter.

The cleanup step runs automatically after all your tests have finished, right before the new documentation is written. If a test fails, the reporter stops before cleanup, so your existing docs are left untouched (unless you set IGNORE_TEST_FAILURES).

What Happens During Cleanup​

  • File Deletion: Any files prefixed with test2doc- (e.g., test2doc-login.md) will be deleted from the output directory. This ensures that only the most recent documentation files are retained.
  • Directory Management: Directories that contain files not generated by the Test2Doc reporter will not be deleted. This prevents the loss of any handwritten documentation or other important files.

Note It is safe to place your handwritten files in directories generated by Test2Doc. However, be mindful that if you clean up tests associated with that directory and put handwritten files into it, that the directory may become an orphan and only contain the handwritten files.

Multiple test suites, one docs site​

Cleanup removes every test2doc-* file under outputDir, including its subdirectories, whichever test suite generated it. That includes files you added by hand with a test2doc- prefix, such as a saved screenshot.

If several packages write to the same Docusaurus site, give each one its own subdirectory as its outputDir, for example docs/playwright-utils. Otherwise every run deletes the pages the other packages generated.