netlify-publisher
v1.0.0
Published
Zip a Playwright (or any static) HTML report and publish it to Netlify as a deploy, returning a shareable URL.
Maintainers
Readme
netlify-publisher
Zip a Playwright (or any static) HTML report and publish it to Netlify as a deploy, returning a shareable URL.
Each publish creates a new immutable deploy of your Netlify site, so every test run gets its own permanent link like https://<deploy-id>--<your-site>.netlify.app.
Requirements
- Node.js 18 or newer (uses the built-in
fetch) - A Netlify site and a personal access token
Installation
npm install netlify-publisherUsage
As a library
import { publishReport } from "netlify-publisher";
const deployUrl = await publishReport({
siteId: "your-netlify-site-id", // or set NETLIFY_SITE_ID env variable
token: "your-netlify-token", // or set NETLIFY_TOKEN env variable
reportDir: "playwright-report", // or set REPORT_FOLDER env variable
title: "smoke test report", // or set NETLIFY_TITLE env variable
});
console.log(deployUrl); // https://<deploy-id>--<your-site>.netlify.appNote:
publishReport()reads env variables directly fromprocess.env— it does not load a.envfile itself (only the CLI does that, viadotenv). If you're callingpublishReport()from your own script and rely on a.envfile, load it yourself first, e.g.import "dotenv/config";at the top of that script.
In a Playwright custom reporter
import { publishReport } from "netlify-publisher";
class MyReporter {
async onEnd(result) {
if (process.env.POST_RESULTS) {
const deployUrl = await publishReport();
console.info(deployUrl);
}
}
}
export default MyReporter;From the command line
npx netlify-publisher [reportDir]The CLI loads a .env file automatically (via dotenv) and prints the deploy URL to stdout. reportDir can also be passed as npx netlify-publisher <reportDir>; otherwise the REPORT_FOLDER env variable is required.
Options
siteId, token, reportDir, and title are all required — pass each as an option or set its env variable fallback. There are no silent defaults for any of them; publishReport() throws immediately, listing every missing one together, if any are missing.
| Option | Env variable | Required | Description |
| --------------- | ----------------- | -------- | ------------------------------------------------------------------------------------------------------------------- |
| siteId | NETLIFY_SITE_ID | Yes | Netlify site ID (Site settings → General → Site ID). |
| token | NETLIFY_TOKEN | Yes | Netlify personal access token. |
| reportDir | REPORT_FOLDER | Yes | Path to the report folder to publish. |
| title | NETLIFY_TITLE | Yes | Deploy title shown in the Netlify deploys list. |
| zipFolderName | — | No | Folder the report is nested under in the deployed site (e.g. report is served at /playwright-report/). Defaults to the report folder's own name. Pass false to serve the report from the site root (/index.html). |
Returns
publishReport() resolves with the deploy_ssl_url of the created deploy — a permanent HTTPS link to this specific version of the report.
License
MIT
