forked from szwacz/electron-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
19,619 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ Thumbs.db | |
/app/app.js | ||
/app/main.js | ||
/app/**/*.map | ||
|
||
# Sublime Text project files | ||
*.sublime-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { expect } from "chai"; | ||
import testUtils from "./utils"; | ||
import { browser } from '@wdio/globals'; | ||
import { expect } from 'chai'; | ||
|
||
describe("application launch", function() { | ||
beforeEach(testUtils.beforeEach); | ||
afterEach(testUtils.afterEach); | ||
|
||
it("shows hello world text on screen after launch", function() { | ||
return this.app.client.$("#greet").then(element => { | ||
return element.getText().then(text => { | ||
expect(text).to.equal("Hello World!"); | ||
}); | ||
}); | ||
describe('Hello World', () => { | ||
it('shows hello world text on screen after launch', async () => { | ||
try { | ||
const element = await $('#greet'); | ||
const text = await element.getText(); | ||
expect(text).to.equal('Hello World!'); | ||
} catch (error) { | ||
console.error('Test failed with error:', error); | ||
throw error; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,87 @@ | ||
import electron from "electron"; | ||
import { Application } from "spectron"; | ||
import path from 'path'; | ||
import { Application } from 'spectron'; | ||
import { fileURLToPath } from 'url'; | ||
import fs from 'fs'; | ||
|
||
const beforeEach = function() { | ||
this.timeout(10000); | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const beforeEach = function () { | ||
this.timeout(30000); // Increased timeout | ||
|
||
console.log('Setting up Spectron application...'); | ||
const appPath = path.join(__dirname, '..'); // Path to the project root | ||
const mainPath = path.join(appPath, 'app', 'main.js'); // Path to main.js | ||
console.log(`App path: ${appPath}`); | ||
console.log(`Main path: ${mainPath}`); | ||
console.log( | ||
`Directory contents of app folder: ${fs.readdirSync(path.join(appPath, 'app'))}`, | ||
); | ||
|
||
this.app = new Application({ | ||
path: electron, | ||
args: ["."], | ||
chromeDriverArgs: ["remote-debugging-port=9222"] | ||
path: require('electron'), | ||
args: [mainPath], // Point directly to main.js | ||
env: { | ||
ELECTRON_ENABLE_LOGGING: true, | ||
ELECTRON_ENABLE_STACK_DUMPING: true, | ||
NODE_ENV: 'test', | ||
}, | ||
startTimeout: 20000, | ||
waitTimeout: 20000, | ||
}); | ||
return this.app.start(); | ||
|
||
console.log('Starting application...'); | ||
return this.app | ||
.start() | ||
.then(() => { | ||
console.log('Application started. Waiting for window to load...'); | ||
return this.app.client.waitUntilWindowLoaded(); | ||
}) | ||
.then(() => { | ||
console.log('Window loaded. Getting window bounds...'); | ||
return this.app.browserWindow.getBounds(); | ||
}) | ||
.then((bounds) => { | ||
console.log('Window bounds:', bounds); | ||
console.log('Setup complete.'); | ||
}) | ||
.catch((error) => { | ||
console.error('Error during setup:', error); | ||
if (error.message.includes('timeout')) { | ||
console.error( | ||
'Timeout error. Current app state:', | ||
this.app.isRunning() ? 'running' : 'not running', | ||
); | ||
console.error('Electron path:', this.app.electron); | ||
console.error( | ||
'Main process pid:', | ||
this.app.mainProcess ? this.app.mainProcess.pid : 'unknown', | ||
); | ||
} | ||
throw error; | ||
}); | ||
}; | ||
|
||
const afterEach = function() { | ||
const afterEach = function () { | ||
this.timeout(30000); // Increased timeout | ||
|
||
if (this.app && this.app.isRunning()) { | ||
return this.app.stop(); | ||
console.log('Stopping application...'); | ||
return this.app | ||
.stop() | ||
.then(() => { | ||
console.log('Application stopped.'); | ||
}) | ||
.catch((error) => { | ||
console.error('Error stopping application:', error); | ||
throw error; | ||
}); | ||
} | ||
return undefined; | ||
console.log('Application was not running.'); | ||
return Promise.resolve(); | ||
}; | ||
|
||
export default { | ||
beforeEach, | ||
afterEach | ||
afterEach, | ||
}; |
Oops, something went wrong.