From 82d6da48e18519346554ea7070ff344ace5524a1 Mon Sep 17 00:00:00 2001 From: Mischa Date: Thu, 25 Jun 2026 07:32:32 +0200 Subject: [PATCH] =?UTF-8?q?test:=20add=20global=20teardown=20=E2=80=94=20s?= =?UTF-8?q?weep=20ui-test=20entries=20from=2002.post=20and=20dailies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playwright.config.js | 1 + tests/global-teardown.js | 57 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/global-teardown.js diff --git a/playwright.config.js b/playwright.config.js index 88b0651..a3a9af9 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -4,6 +4,7 @@ const { defineConfig, devices } = require('@playwright/test'); module.exports = defineConfig({ testDir: './tests/ui', globalSetup: './tests/global-setup.js', + globalTeardown: './tests/global-teardown.js', timeout: 30_000, retries: 0, projects: [ diff --git a/tests/global-teardown.js b/tests/global-teardown.js new file mode 100644 index 0000000..9441321 --- /dev/null +++ b/tests/global-teardown.js @@ -0,0 +1,57 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +function resolveUserDir() { + if (process.env.GRAV_USER_DIR) return process.env.GRAV_USER_DIR; + try { + const raw = execSync( + "docker inspect intotheeast_grav --format '{{range .Mounts}}{{if eq .Destination \"/var/www/html/user\"}}{{.Source}}{{end}}{{end}}'", + { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] } + ).trim(); + if (raw) return raw; + } catch (_) {} + return path.join(__dirname, '../user'); +} + +function sweepUiTestEntries(dir) { + if (!fs.existsSync(dir)) return 0; + const entries = fs.readdirSync(dir).filter(e => e.includes('ui-test')); + entries.forEach(e => fs.rmSync(path.join(dir, e), { recursive: true, force: true })); + return entries.length; +} + +module.exports = async function globalTeardown() { + const userDir = resolveUserDir(); + + // Read active trip slug from post-form.md + const postFormPath = path.join(userDir, 'pages/02.post/post-form.md'); + let dailiesDir = null; + if (fs.existsSync(postFormPath)) { + const content = fs.readFileSync(postFormPath, 'utf-8'); + const m = content.match(/parent:\s*['"]?\/trips\/([^/'"]+)\/dailies/); + if (m) { + const tripSlug = m[1]; + const tripsBase = path.join(userDir, 'pages/01.trips'); + const tripFolder = fs.readdirSync(tripsBase).find( + f => f === tripSlug || f.endsWith('.' + tripSlug) || f.includes(tripSlug) + ); + if (tripFolder) { + const dailiesBase = path.join(tripsBase, tripFolder); + const dailiesFolder = fs.readdirSync(dailiesBase).find( + f => f === 'dailies' || f === '01.dailies' || f.endsWith('.dailies') + ); + if (dailiesFolder) dailiesDir = path.join(dailiesBase, dailiesFolder); + } + } + } + + // Sweep both the post inbox and the active trip's dailies + const postInbox = path.join(userDir, 'pages/02.post'); + const n1 = sweepUiTestEntries(postInbox); + const n2 = dailiesDir ? sweepUiTestEntries(dailiesDir) : 0; + + if (n1 + n2 > 0) { + console.log(`[teardown] removed ${n1} ui-test entries from 02.post, ${n2} from dailies`); + } +};