From b5097875532b0487049cf5f66f0a3e10f0c1af7e Mon Sep 17 00:00:00 2001
From: Kevin Gibbons
Date: Wed, 26 Jun 2024 15:38:57 -0700
Subject: [PATCH] Markup: also insert snapshot warning in multipage (#3348)
---
scripts/insert_snapshot_warning.js | 35 +++++++++++++++++++-----------
scripts/snapshot_warning.html | 10 +++++++++
2 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/scripts/insert_snapshot_warning.js b/scripts/insert_snapshot_warning.js
index e2d02e6bfc..92b0f48cc3 100644
--- a/scripts/insert_snapshot_warning.js
+++ b/scripts/insert_snapshot_warning.js
@@ -2,7 +2,7 @@
const fs = require('fs');
const path = require('path');
-const { JSDOM } = require('jsdom');
+const { JSDOM, VirtualConsole } = require('jsdom');
const { execSync } = require('child_process');
const COMMIT = String(execSync('git rev-parse --verify HEAD')).trim();
@@ -13,21 +13,30 @@ const WARNING_CSS = fs.readFileSync(path.join(__dirname, 'snapshot_warning.css')
console.log('Inserting snapshot reference warning...');
-JSDOM.fromFile('./out/index.html', { contentType: 'text/html; charset=utf-8' }).then((dom) => {
- const { document } = dom.window;
+const virtualConsole = new VirtualConsole();
+virtualConsole.on('error', () => {
+ // Suppress warnings from e.g. CSS features not supported by JSDOM
+});
- const style = document.createElement('style');
- style.textContent = WARNING_CSS;
- document.head.append(style);
+(async () => {
+ let files = ['out/index.html', ...fs.readdirSync('out/multipage').filter(f => f.endsWith('.html')).map(f => 'out/multipage/' + f)];
+ for (let file of files) {
+ console.log(file);
+ let dom = await JSDOM.fromFile(file, { contentType: 'text/html; charset=utf-8', virtualConsole });
+ const { document } = dom.window;
- // insert WARNING_HTML in beginning of body so it renders
- // first even on slower devices and browsers
- document.body.insertAdjacentHTML('afterbegin', WARNING_HTML);
+ const style = document.createElement('style');
+ style.textContent = WARNING_CSS;
+ document.head.append(style);
- fs.writeFileSync('./out/index.html', dom.serialize(), 'utf8');
+ // insert WARNING_HTML in beginning of body so it renders
+ // first even on slower devices and browsers
+ document.body.insertAdjacentHTML('afterbegin', WARNING_HTML);
+ fs.writeFileSync(file, dom.serialize(), 'utf8');
+ }
console.log('Done!');
-}).catch((reason) => {
- console.error(reason);
- process.exitCode = 1;
+})().catch(e => {
+ console.error(e);
+ process.exit(1);
});
diff --git a/scripts/snapshot_warning.html b/scripts/snapshot_warning.html
index 3e2043ea2f..e0e3108b76 100644
--- a/scripts/snapshot_warning.html
+++ b/scripts/snapshot_warning.html
@@ -13,3 +13,13 @@
living specification.
+