-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explore: Add e2e-testing with Spectron (#1773)
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
Showing
9 changed files
with
760 additions
and
5 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 |
---|---|---|
|
@@ -64,7 +64,7 @@ dev-server: | |
|
||
.PHONY: test | ||
test: | ||
@npx jest | ||
@npx jest --config=./jest.config.js | ||
|
||
|
||
# Build web app | ||
|
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
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 |
---|---|---|
@@ -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); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
globals: { | ||
config: { | ||
appVersion: 'foo', | ||
}, | ||
}, | ||
roots: ['e2e'], | ||
testRegex: '(/.*\\.[jt]sx?)|(test\\.[jt]sx?)$', | ||
}; |
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
Oops, something went wrong.