Skip to content

Commit

Permalink
Reimplemented testing
Browse files Browse the repository at this point in the history
Testing should only run if `test` passed, otherwise it will run the app.
  • Loading branch information
zekrom-vale committed Apr 10, 2024
1 parent 12b8473 commit e12fb29
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ jobs:
run: |
npm i -g electron
npm i -g electron-mocha
electron-mocha
electron-mocha test
45 changes: 33 additions & 12 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const { URL } = require('url');
process.env.NODE_ENV = process.platform
const config = require("config")

// TESTING EXPORT OBJECT exports
Object.defineProperty(exports, "__esModule", { value: true });

// Error
function error(msg, name=""){
console.warn(`${name}: ${msg}`);
Expand Down Expand Up @@ -53,6 +56,9 @@ function platform(plat=process.platform, test=false){
var home=path.join(app.getAppPath(), config.get("R.path.home"))
// Must use ! as / is an issue with paths
var exec = `sed -i${_i} 's!R_HOME_DIR=.*$!R_HOME_DIR="${home}"!' ${execPath}`
// START TEST CODE
if(test) return exec
// END TEST CODE
if(execPortable && config.get("R.path.fixHome"))shell(exec)
break
default:
Expand All @@ -76,6 +82,8 @@ function startR(){
)
childProcess.stdout.on('data', data => console.log(`Rout: ${data}`))
childProcess.stderr.on('data', data => console.warn(`Rerr: ${data}`))
// TESTING EXPORT childProcess
exports.childProcess=childProcess
}

// Keep a global reference of the window object, if you don't, the window will
Expand Down Expand Up @@ -107,6 +115,8 @@ async function createWindow(){
}

mainWindow = new BrowserWindow(config.get("window.config"))
// TESTING EXPORT mainWindow
exports.mainWindow=mainWindow

////////////////////////////////////////////////////////////////////////////////
// Connect to Shiny
Expand Down Expand Up @@ -202,20 +212,31 @@ function cleanUpApplication(quit=true){
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.

app.on('ready', createWindow)
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if(mainWindow === null) createWindow()
})
// TESTING SWITCH START SHOULD ALWAYS BE TRUE
if (process.argv[2] != "test"){
app.on('ready', createWindow)
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if(mainWindow === null) createWindow()
})

// Quit when all windows are closed.
app.on('window-all-closed', function () {
// Quit when all windows are closed.
app.on('window-all-closed', function () {

console.log(now()+'::window-all-closed')
cleanUpApplication()
if(config.get("app.quitOnClose"))app.quit()
})
console.log(now()+'::window-all-closed')
cleanUpApplication()
if(config.get("app.quitOnClose"))app.quit()
})
}
// TESTING CODE ONLY / WHEN REQUIRED
else{
exports.startR = startR
exports.createWindow = createWindow
exports.cleanUpApplication = cleanUpApplication
exports.platform = platform
}
// TESTING SWITCH END


// In this file you can include the rest of your app's specific main process
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e12fb29

Please sign in to comment.