File size: 2,765 Bytes
ef987bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | const fs = require('fs');
const path = require('path');
const { pathToFileURL } = require('url');
const { chromium } = require('playwright');
(async () => {
const root = process.cwd();
if (fs.existsSync(path.join(root, 'figma'))) throw new Error('figma folder should be removed');
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
if (entry.isDirectory() && entry.name.toLowerCase() === 'figma') throw new Error('no figma directory should remain');
}
const sourceFiles = [];
function walk(dir) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const p = path.join(dir, entry.name);
if (entry.isDirectory() && !['tests','logs','node_modules'].includes(entry.name)) walk(p);
if (entry.isFile() && /\.(js|jsx|ts|tsx)$/.test(entry.name)) sourceFiles.push(p);
}
}
walk(root);
const joined = sourceFiles.map(p => fs.readFileSync(p, 'utf8')).join('\n');
if (/from\s+['\"][^'\"]*figma|require\(['\"][^'\"]*figma|@\/components\/figma/.test(joined)) throw new Error('source should not keep stale figma imports after removing the folder');
const app = fs.readFileSync(path.join(root, 'src', 'app.js'), 'utf8');
if (!app.includes('sendPrompt')) throw new Error('application sendPrompt logic should remain present');
if (!fs.existsSync(path.join(root, 'package.json'))) throw new Error('project config should be preserved');
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
await page.goto(pathToFileURL(path.join(root, 'index.html')).href, { waitUntil: 'domcontentloaded' });
// Accept either the data-testid contract hooks OR the starter fixture's original
// ids (#prompt / #send / #output and a <main>/#app root). The instruction says the
// app logic must NOT change after removing figma/, so a solution that merely deletes
// the folder and keeps the fixture's original markup must still pass.
const appRoot = page.locator('[data-testid="app-root"], main, #app').first();
const promptInput = page.locator('[data-testid="prompt-input"], #prompt').first();
const sendButton = page.locator('[data-testid="send-button"], #send').first();
const outputArea = page.locator('[data-testid="output-area"], #output').first();
if (!(await appRoot.isVisible())) throw new Error('core page should still render after cleanup');
await promptInput.fill('hello restored app');
await sendButton.click();
await page.waitForTimeout(100);
const output = (await outputArea.textContent()) || '';
if (!/hello restored app/.test(output)) throw new Error('send/output area should keep working after figma cleanup');
await browser.close();
})().catch(err => { console.error(err && err.stack || err); process.exit(1); });
|