// Builds a scratch config and data dir so the browser tests drive a real daemon with // known feeds, rather than whatever happens to be on the machine. const fs = require('fs'); const path = require('path'); const os = require('os'); const root = path.join(os.tmpdir(), 'ipx-ui-test'); const TOKEN = 'testtokentesttokentesttoken12345'; // fixed, so tests need not scrape a log // Called from playwright.config.js at load time, NOT as globalSetup: Playwright starts // webServer *before* globalSetup, so a config written there does not exist yet when the // daemon launches -- it would fall back to the real config and fight the live daemon. function prepare() { fs.rmSync(root, { recursive: true, force: true }); for (const d of ['config', 'data', 'downloads']) { fs.mkdirSync(path.join(root, d), { recursive: true }); } fs.writeFileSync(path.join(root, 'config', 'config.toml'), ` [general] download_dir = "${path.join(root, 'downloads')}" socket = "${path.join(root, 'ipx.sock')}" schedule = "every 60m" max_new_per_check = 1 [torrent] enabled = false [web] enabled = true bind = "127.0.0.1:8791" token = "${TOKEN}" [feeds.test-show] url = "http://127.0.0.1:8792/show.xml" auto_download = true # Downloads its image, so the UI has a file that is not playable to deal with. [feeds.picture-blog] url = "http://127.0.0.1:8792/pics.xml" auto_download = true media_types = ["image"] [feeds.test-subscriptions] url = "http://127.0.0.1:8792/subs.opml" auto_download = false `); } module.exports = { prepare, root, TOKEN };