Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore: Add e2e-testing with Spectron #1773

Merged
merged 6 commits into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dev-server:

.PHONY: test
test:
@npx jest
@npx jest --config=./jest.config.js


# Build web app
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ _Note: Simplenote API features such as sharing and publishing will not work with
- **`make package-win32`**
- **`make package-linux`**

## Testing

Unit tests are run with `npm test`.

End-to-end tests are run with `npm run test-e2e`.
Note that the `Spectron` version corresponds with the version of `Electron` we are using and so at the time of writing this is pinned at version 6.
Use the corresponding API docs for `webdriver-io` which correspond to the `Specron` version.
At the time of writing you will want to refer to the [webdriver-io v4.13 API docs](http://v4.webdriver.io/v4.13/api.html).

## Coding Guidelines

Please adhere to the same guidelines as found in [wp-calypso](https://github.com/Automattic/wp-calypso/blob/master/docs/coding-guidelines.md).
Expand All @@ -32,6 +41,7 @@ Please adhere to the same guidelines as found in [wp-calypso](https://github.com
- [Electron](https://electronjs.org/) for wrapping the JavaScript application.

## Simplenote for Other Platforms

[simplenote-electron](https://github.com/Automattic/simplenote-electron) is the official Simplenote desktop app for Windows and Linux.

For other platforms, see:
Expand Down
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Migrate TransitionDelayEnter to React hooks [#1784](https://github.com/Automattic/simplenote-electron/pull/1784)
- Added git hooks to run format, lints, and tests [#1790](https://github.com/Automattic/simplenote-electron/pull/1790)
- Added React Hooks Eslinnt Plugin [#1789](https://github.com/Automattic/simplenote-electron/pull/1789)
- Added end-to-end testing with Spectron [#1773](https://github.com/Automattic/simplenote-electron/pull/1773)

## [v1.13.0]

Expand Down
5 changes: 4 additions & 1 deletion desktop/app.js
Original file line number Diff line number Diff line change
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
46 changes: 46 additions & 0 deletions e2e/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'regenerator-runtime/runtime';
import path from 'path';
import rimraf from 'rimraf';
import { Application } from 'spectron';

const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

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

beforeAll(async () => {
await app.start();
const userData = await app.electron.remote.app.getPath('userData');
await app.stop();
await new Promise(resolve => rimraf(userData, () => resolve()));
await app.start();
}, 10000);

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

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

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

app.client
.$('#login__field-username')
.setValue(process.env.TEST_USERNAME as string);
app.client
.$('#login__field-password')
.setValue(process.env.TEST_PASSWORD as string);

await wait(500);

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

await app.client.waitUntilWindowLoaded();
await app.client.waitForExist('.note-list', 10000);
}, 20000);
});
9 changes: 9 additions & 0 deletions jest.config.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
globals: {
config: {
appVersion: 'foo',
},
},
roots: ['e2e'],
testRegex: '(/.*\\.[jt]sx?)|(test\\.[jt]sx?)$',
};
1 change: 1 addition & 0 deletions lib/auth/index.jsx
Original file line number Diff line number Diff line change
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
Loading