Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Trippnology committed Sep 14, 2024
2 parents 20aff6c + 02a4361 commit 749c4fe
Show file tree
Hide file tree
Showing 11 changed files with 19,619 additions and 113 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ Thumbs.db
/app/app.js
/app/main.js
/app/**/*.map

# Sublime Text project files
*.sublime-*
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2015-2021 Jakub Szwacz
Copyright (c) 2024 Rikki Tripp

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# electron-boilerplate

Minimalistic, very easy to understand boilerplate for [Electron runtime](https://www.electronjs.org/). Tested on Windows, macOS and Linux.
Minimalistic, very easy to understand boilerplate for [Electron runtime](https://www.electronjs.org/). Tested on Windows, macOS and Linux.

This project contains only bare minimum of tooling and dependencies to provide you with simple to understand and extensible base (but still, this is fully functional Electron environment). The boilerplate doesn't impose on you any frontend technologies, so feel free to pick your favourite.

# Quick start
## Quick start

Make sure you have [Node.js](https://nodejs.org) installed, then type...

```
git clone https://github.com/szwacz/electron-boilerplate.git
git clone https://github.com/trippnology/electron-boilerplate.git
cd electron-boilerplate
npm install
npm start
```

...and you have a running desktop application on your screen.

# Structure of the project
## Structure of the project

The application consists of two main folders...

Expand All @@ -27,64 +29,73 @@ The build process compiles the content of the `src` folder and puts it into the

The drawback of this design is that `app` folder contains some files which should be git-ignored and some which shouldn't (see `.gitignore` file). But this two-folders split makes development builds much faster.

# Development
## Development

## Starting the app
### Starting the app

```
npm start
```

## The build pipeline
### The build pipeline

Build process uses [Webpack](https://webpack.js.org/). The entry-points are `src/main.js` and `src/app.js`. Webpack will follow all `import` statements starting from those files and compile code of the whole dependency tree into one `.js` file for each entry point.

[Babel](http://babeljs.io/) is also utilised, but mainly for its great error messages. Electron under the hood runs latest Chromium, hence most of the new JavaScript features are already natively supported.

## Environments
### Environments

Environment variables are done in a slightly unusual way (not via `process.env`). Env files are plain JSONs in `config` directory, and build process dynamically links one of them as an `env` module. You can import it wherever in code you need access to the environment.

Environmental variables are done in a bit different way (not via `process.env`). Env files are plain JSONs in `config` directory, and build process dynamically links one of them as an `env` module. You can import it wherever in code you need access to the environment.
```js
import env from "env";
import env from 'env';
console.log(env.name);
```

## Adding npm modules to your app
### Adding npm modules to your app

Remember to respect the split between `dependencies` and `devDependencies` in `package.json` file. Your distributable app will contain only modules listed in `dependencies` after running the release script.

*Side note:* If the module you want to use in your app is a native one (not pure JavaScript but compiled binary) you should first run `npm install name_of_npm_module` and then `npm run postinstall` to rebuild the module for Electron. You need to do this once after you're first time installing the module. Later on, the postinstall script will fire automatically with every `npm install`.
_Side note:_ If the module you want to use in your app is a native one (not pure JavaScript but compiled binary) you should first run `npm install name_of_npm_module` and then `npm run postinstall` to rebuild the module for Electron. You need to do this once after you're first time installing the module. Later on, the postinstall script will fire automatically with every `npm install`.

# Testing
## Testing

Run all tests:

```
npm test
```

## Unit
### Unit

```
npm run unit
```

Using [electron-mocha](https://github.com/jprichardson/electron-mocha) test runner with the [Chai](http://chaijs.com/api/assert/) assertion library. You can put your spec files wherever you want within the `src` directory, just name them with the `.spec.js` extension.

## End to end
### End to end

```
npm run e2e
```

Using [Mocha](https://mochajs.org/) and [Spectron](http://electron.atom.io/spectron/). This task will run all files in `e2e` directory with `.e2e.js` extension.

# Making a release
## Making a release

To package your app into an installer use command:

```
npm run release
```

Once the packaging process finished, the `dist` directory will contain your distributable file.

[Electron-builder](https://github.com/electron-userland/electron-builder) is handling the packaging process. Follow dosc over there to customise your build.
[Electron-builder](https://github.com/electron-userland/electron-builder) is handling the packaging process. Follow docs over there to customise your build.

You can package your app cross-platform from a single operating system, [electron-builder kind of supports this](https://www.electron.build/multi-platform-build), but there are limitations and asterisks. That's why this boilerplate doesn't do that by default.

## History

This project was originally created by [Jakub Szwacz](https://github.com/szwacz/electron-boilerplate), but was later abandoned. This version by [Trippnology](https://trippnology.com) simply updated many of the components and got it working again. The major version number has been bumped to reflect this.
24 changes: 12 additions & 12 deletions e2e/hello_world.e2e.js
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;
}
});
});
86 changes: 74 additions & 12 deletions e2e/utils.js
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,
};
Loading

0 comments on commit 749c4fe

Please sign in to comment.