Skip to content

Commit 40b82e5

Browse files
tebsuesteibar
authored andcommitted
test(end2end): Add first test using Spectron
1 parent bd525dc commit 40b82e5

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

package.json

+14-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"react-redux": "^5.0.3",
3434
"redux": "^3.6.0",
3535
"redux-thunk": "^2.2.0",
36-
"standard-version": "^4.0.0",
3736
"user-home": "^2.0.0"
3837
},
3938
"devDependencies": {
@@ -46,7 +45,8 @@
4645
"babel-preset-react": "^6.22.0",
4746
"babel-preset-stage-0": "^6.1.18",
4847
"browser-sync": "^2.9.3",
49-
"chai": "^3.4.1",
48+
"chai": "^3.5.0",
49+
"chai-as-promised": "^6.0.0",
5050
"electron": "^1.5.0",
5151
"electron-builder": "^13.8.2",
5252
"electron-devtools-installer": "^2.1.0",
@@ -55,12 +55,14 @@
5555
"eslint-plugin-react": "^6.9.0",
5656
"mocha": "^3.2.0",
5757
"npm-run-all": "^4.0.1",
58-
"rimraf": "^2.5.4"
58+
"rimraf": "^2.5.4",
59+
"spectron": "^3.6.1",
60+
"standard-version": "^4.0.0"
5961
},
6062
"scripts": {
6163
"bump": "standard-version",
62-
"prettier": "prettier --trailing-comma all --single-quote --write --jsx-bracket-same-line --bracket-spacing 'app/**/*.js'",
63-
"lint": "eslint --no-ignore scripts app test *.js",
64+
"prettier": "prettier --trailing-comma all --single-quote --write --jsx-bracket-same-line --bracket-spacing 'app/**/*.js' 'spec/**/*.js'",
65+
"lint": "eslint --no-ignore scripts app spec *.js",
6466
"lint:staged": "lint-staged",
6567
"postinstall": "install-app-deps",
6668
"start": "npm run private:compile -- --source-maps true && run-p -r private:watch private:serve",
@@ -69,13 +71,19 @@
6971
"private:watch": "npm run private:compile -- --source-maps true --watch --skip-initial-build",
7072
"private:serve": "babel-node scripts/serve.js",
7173
"private:compile": "babel app/ --copy-files --out-dir build",
72-
"private:clean": "rimraf build"
74+
"private:clean": "rimraf build",
75+
"test:features": "mocha --compilers js:babel-core/register spec/features/**/*.js"
7376
},
7477
"lint-staged": {
7578
"app/**/*.js": [
7679
"npm run prettier",
7780
"eslint --fix",
7881
"git add"
82+
],
83+
"spec/**/*.js": [
84+
"prettier --single-quote --write",
85+
"eslint --fix",
86+
"git add"
7987
]
8088
},
8189
"pre-commit": "lint:staged",

spec/features/global-helpers.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import path from 'path';
2+
import { Application } from 'spectron';
3+
4+
const electronPath = path.join(
5+
__dirname,
6+
'..',
7+
'..',
8+
'node_modules',
9+
'.bin',
10+
'electron'
11+
);
12+
13+
const appPath = path.join(__dirname, '..', '..');
14+
15+
const app = new Application({
16+
path: electronPath,
17+
env: { SPECTRON: true },
18+
args: [appPath]
19+
});
20+
21+
const stopApp = app => app && app.isRunning() && app.stop();
22+
23+
export { app, stopApp };

spec/features/test.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import chai from 'chai';
2+
import chaiAsPromised from 'chai-as-promised';
3+
4+
import { app, stopApp } from './global-helpers';
5+
6+
global.before(function() {
7+
chai.should();
8+
chai.use(chaiAsPromised);
9+
});
10+
11+
describe('App starts', function() {
12+
this.timeout(15000);
13+
14+
beforeEach(() => app.start());
15+
after(done => done());
16+
afterEach(() => stopApp(app));
17+
18+
it('loads the app', () => {
19+
return app.client
20+
.waitUntilWindowLoaded()
21+
.browserWindow.isVisible().should.eventually.be.true;
22+
});
23+
});

0 commit comments

Comments
 (0)