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

Add first end2end test using Spectron #19

Merged
merged 2 commits into from
Apr 25, 2017
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Development
npm start
```

Run end2end tests
```bash
npm run test:features
```

## DevTools

Toggle DevTools:
Expand Down
23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"email": "[email protected]"
},
"contributors": [
"Marcio Barrios <[email protected]>"
"Marcio Barrios <[email protected]>",
"Teba Rojo <[email protected]>"
],
"repository": "https://github.com/sloth-tools/sloth-app",
"license": "MIT",
Expand All @@ -33,7 +34,6 @@
"react-redux": "^5.0.3",
"redux": "^3.6.0",
"redux-thunk": "^2.2.0",
"standard-version": "^4.0.0",
"user-home": "^2.0.0"
},
"devDependencies": {
Expand All @@ -46,7 +46,8 @@
"babel-preset-react": "^6.22.0",
"babel-preset-stage-0": "^6.1.18",
"browser-sync": "^2.9.3",
"chai": "^3.4.1",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"electron": "^1.5.0",
"electron-builder": "^13.8.2",
"electron-devtools-installer": "^2.1.0",
Expand All @@ -55,12 +56,14 @@
"eslint-plugin-react": "^6.9.0",
"mocha": "^3.2.0",
"npm-run-all": "^4.0.1",
"rimraf": "^2.5.4"
"rimraf": "^2.5.4",
"spectron": "^3.6.1",
"standard-version": "^4.0.0"
},
"scripts": {
"bump": "standard-version",
"prettier": "prettier --trailing-comma all --single-quote --write --jsx-bracket-same-line --bracket-spacing 'app/**/*.js'",
"lint": "eslint --no-ignore scripts app test *.js",
"prettier": "prettier --trailing-comma all --single-quote --write --jsx-bracket-same-line --bracket-spacing 'app/**/*.js' 'spec/**/*.js'",
"lint": "eslint --no-ignore scripts app spec *.js",
"lint:staged": "lint-staged",
"postinstall": "install-app-deps",
"start": "npm run private:compile -- --source-maps true && run-p -r private:watch private:serve",
Expand All @@ -69,13 +72,19 @@
"private:watch": "npm run private:compile -- --source-maps true --watch --skip-initial-build",
"private:serve": "babel-node scripts/serve.js",
"private:compile": "babel app/ --copy-files --out-dir build",
"private:clean": "rimraf build"
"private:clean": "rimraf build",
"test:features": "mocha --compilers js:babel-core/register spec/features/**/*.js"
},
"lint-staged": {
"app/**/*.js": [
"npm run prettier",
"eslint --fix",
"git add"
],
"spec/**/*.js": [
"prettier --single-quote --write",
"eslint --fix",
"git add"
]
},
"pre-commit": "lint:staged",
Expand Down
23 changes: 23 additions & 0 deletions spec/features/global-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import path from 'path';
import { Application } from 'spectron';

const electronPath = path.join(
__dirname,
'..',
'..',
'node_modules',
'.bin',
'electron'
);

const appPath = path.join(__dirname, '..', '..');

const app = new Application({
path: electronPath,
env: { SPECTRON: true },
args: [appPath]
});

const stopApp = app => app && app.isRunning() && app.stop();

export { app, stopApp };
23 changes: 23 additions & 0 deletions spec/features/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';

import { app, stopApp } from './global-helpers';

global.before(function() {
chai.should();
chai.use(chaiAsPromised);
});

describe('App starts', function() {
this.timeout(15000);

beforeEach(() => app.start());
after(done => done());
afterEach(() => stopApp(app));

it('loads the app', () => {
return app.client
.waitUntilWindowLoaded()
.browserWindow.isVisible().should.eventually.be.true;
});
});