File size: 1,604 Bytes
78fee96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { existsSync } from "fs"
import fs from "fs/promises"
import path, { dirname } from "path"
import puppeteer from "puppeteer"
import { fileURLToPath } from "url"
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const browser = await puppeteer.launch({
  headless: false,
  ignoreDefaultArgs: ["--mute-audio"],
  args: ["--autoplay-policy=no-user-gesture-required"],
})
const page = await browser.newPage()
await page.goto("http://localhost:3000/edit?disableFileSystem=true", {
  waitUntil: "networkidle0",
})

// open midi file

page.on("dialog", async (dialog) => {
  console.log(dialog.type())
  console.log(dialog.message())
  console.log(dialog.defaultValue())
  await dialog.accept()
})

await page.click("#tab-file", { delay: 200 })
const [fileChooser] = await Promise.all([
  page.waitForFileChooser(),
  page.click('label[for="OpenButtonInputFile"]'),
])
const midiFilePath = path.resolve(__dirname, "test.mid")
await fileChooser?.accept([midiFilePath])

await page.click("#button-play")

await page.waitForTimeout(10000)

const metrics = await page.metrics()
const result = JSON.stringify(metrics, null, 2)

const writeFile = async (dir, prefix, content) => {
  let count = 0
  while (true) {
    const filePath = path.resolve(dir, `${prefix}${count}.json`)
    if (existsSync(filePath)) {
      count++
    } else {
      await fs.mkdir(dir, { recursive: true })
      await fs.writeFile(filePath, content, { encoding: "utf-8" })
      break
    }
  }
}

await writeFile(path.resolve(__dirname, "output"), "metrics", result)

await browser.close()