const { files, ...opts } = window.__args__

if (!opts.interactive) {
  require('./console')
}

const { Mocha, helpers } = require('../mocha')
const { ipcRenderer: ipc } = require('electron')

// Expose Mocha
window.mocha = Mocha

try {
  opts.script.forEach((script) => {
    const tag = document.createElement('script')
    tag.src = script
    tag.async = false
    document.head.appendChild(tag)
  })
} catch (error) {
  ipc.send('mocha-error', {
    message: error.message,
    stack: error.stack
  })
}

ipc.on('mocha-start', () => {
  try {
    helpers.runMocha(opts, files, (...args) => {
      ipc.send('mocha-done', ...args)
    })
  } catch ({ message, stack }) {
    ipc.send('mocha-error', { message, stack })
  }
})

// Request re-run on reload in --interactive mode
ipc.send('mocha-ready-to-run')

@@ -229,16 +229,39 @@
 %0A%0Atry %7B%0A
+  if (opts.script) %7B%0A  
   opts.s
@@ -284,24 +284,26 @@
 cript) =%3E %7B%0A
+  
     const ta
@@ -339,24 +339,26 @@
 cript')%0A    
+  
 tag.src = sc
@@ -362,24 +362,26 @@
  script%0A    
+ 
+ 
 tag.async = 
@@ -386,16 +386,18 @@
 = false%0A
+  
     docu
@@ -425,18 +425,24 @@
 (tag)%0A  
+  %7D)%0A  
 %7D
-)
 %0A%7D catch

Make --script optional