Skip to content

Commit

Permalink
Explore: Add e2e-testing with Spectron
Browse files Browse the repository at this point in the history
In this patch we're creating the most basic form of end-to-end testing
using the Spectron framework. This boots the app and verifies that it
opens.

The files aren't in the right spot and the structure of the tests need
to change but this gives us an idea of how to run these tests.
  • Loading branch information
dmsnell committed Dec 10, 2019
1 parent 8c5227f commit 2732d51
Show file tree
Hide file tree
Showing 5 changed files with 525 additions and 1 deletion.
5 changes: 4 additions & 1 deletion desktop/app.js
Expand Up @@ -73,7 +73,10 @@ module.exports = function main() {
mainWindow.loadUrl(url);
}

if (isDev || process.argv.includes('--devtools')) {
if (
'test' !== process.env.NODE_ENV &&
(isDev || process.argv.includes('--devtools'))
) {
mainWindow.openDevTools({ mode: 'detach' });
}

Expand Down
1 change: 1 addition & 0 deletions lib/auth/index.jsx
Expand Up @@ -113,6 +113,7 @@ export class Auth extends Component {
/>

<button
id="login__login-button"
className={submitClasses}
onClick={isCreatingAccount ? this.onSignUp : this.onLogin}
type="submit"
Expand Down
46 changes: 46 additions & 0 deletions lib/test/test.js
@@ -0,0 +1,46 @@
import 'regenerator-runtime/runtime';
import { Application } from 'spectron';
import electronPath from 'electron';
import path from 'path';

const app = new Application({
path: electronPath,
args: [path.join(__dirname, '..', '..')],
});

describe('E2E', () => {
beforeEach(async () => await app.start(), 10000);

afterEach(async () => app && app.isRunning() && (await app.stop()));

test('starts', async () => {
await app.client.waitUntilWindowLoaded();
expect(app.isRunning()).toEqual(true);
});

test('logs in', async () => {
await app.client.waitUntilWindowLoaded();

const username = app.client.$('#login__field-username');
const password = app.client.$('#login__field-password');

if (!username.isExisting()) {
await username.waitForExist();
}

if (!password.isExisting()) {
await password.waitForExist();
}

username.setValue(process.env.TEST_USERNAME);
password.setValue(process.env.TEST_PASSWORD);

await new Promise(resolve => setTimeout(resolve, 500));

await app.client.$('#login__login-button').click();

await app.client.waitUntilWindowLoaded();
await new Promise(resolve => setTimeout(resolve, 5000));
expect(await app.client.$('.simplenote-app').isExisting()).toEqual(true);
});
});

0 comments on commit 2732d51

Please sign in to comment.