24 lines
1.2 KiB
JavaScript
24 lines
1.2 KiB
JavaScript
import puppeteer from 'puppeteer'
|
|
import fs from 'node:fs'
|
|
|
|
const filePath = 'scratch/lite-test.ifc'
|
|
fs.writeFileSync(filePath, 'ISO-10303-21;\nENDSEC;\nEND-ISO-10303-21;\n')
|
|
|
|
const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox'] })
|
|
const page = await browser.newPage()
|
|
const logs = []
|
|
page.on('console', (msg) => logs.push(`${msg.type()}: ${msg.text()}`))
|
|
page.on('pageerror', (err) => logs.push(`pageerror: ${err.message}`))
|
|
page.on('requestfailed', (req) => logs.push(`requestfailed: ${req.method()} ${req.url()} ${req.failure()?.errorText}`))
|
|
page.on('response', async (res) => {
|
|
if (res.url().includes('/graphql')) logs.push(`response: ${res.status()} ${res.url()}`)
|
|
})
|
|
await page.goto('http://localhost:5174', { waitUntil: 'networkidle0', timeout: 30000 })
|
|
const input = await page.$('#file-input')
|
|
await input.uploadFile(filePath)
|
|
await page.click('#upload-button')
|
|
await page.waitForFunction(() => document.querySelector('#log')?.textContent?.includes('Project:') || document.querySelector('#log')?.textContent?.includes('Error:'), { timeout: 20000 })
|
|
const text = await page.$eval('#log', (el) => el.textContent)
|
|
console.log(JSON.stringify({ text, logs }, null, 2))
|
|
await browser.close()
|