Skip to content

Commit

Permalink
Added E2E tests (hql287#279)
Browse files Browse the repository at this point in the history
* Installed Spectron

* Added tests

* Added Mocha and custom script for E2E test

* Updated Tests

* Make sure the E2E test is run by Mocha instead of Jest

* Fixed linting error
  • Loading branch information
hql287 authored Apr 9, 2018
1 parent 28581da commit f41bcc1
Show file tree
Hide file tree
Showing 6 changed files with 1,387 additions and 1,245 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
commonjs: true
es6: true
browser: true
mocha: true
globals:
# JEST GLOBALS
jest: false
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ module.exports = {
// verbose: true,
collectCoverage: true,
setupFiles: ['./jest.shim.js', './jest.setup.js'],
testPathIgnorePatterns: [
'<rootDir>/test/'
]
};
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
"dev": "webpack-dev-server --mode development",
"build": "webpack --env.production --mode production",
"test": "jest",
"test:e2e": "mocha",
"test:watch": "jest --watch",
"dist:linux": "electron-builder --linux",
"dist:win": "electron-builder --win",
"dist:mac": "electron-builder --mac",
"dist": "electron-builder -mwl",
"release:linux": "yarn run build && yarn run dist:linux",
"release:win": "yarn run build && yarn run dist:win",
"release:mac": "yarn run build && yarn run dist:mac",
"release": "yarn run build && yarn run dist",
"lint": "find . -name \"*.js\" -o -name \"*.jsx\" | grep -v -f .gitignore | xargs eslint",
"prettier:base": "prettier --write",
Expand Down Expand Up @@ -54,6 +57,7 @@
"redux": "^3.7.2",
"redux-actions": "^2.3.0",
"reselect": "^3.0.1",
"spectron": "^3.8.0",
"styled-components": "^3.2.1",
"uuid": "^3.2.1"
},
Expand Down Expand Up @@ -88,6 +92,7 @@
"jest": "^22.4.2",
"jest-styled-components": "^5.0.0",
"lint-staged": "^7.0.0",
"mocha": "^5.0.5",
"pre-commit": "^1.2.2",
"prettier": "^1.11.1",
"react-hot-loader": "^4.0.0",
Expand Down
17 changes: 17 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const path = require('path');
const { Application } = require('spectron');
const appPath = path.join(__dirname, '../dist/mac/Manta.app/Contents/MacOS/Manta');

function initializeSpectron() {
return new Application({
path: appPath,
env: {
ELECTRON_ENABLE_LOGGING: true,
ELECTRON_ENABLE_STACK_DUMPING: true,
NODE_ENV: 'development',
},
startTimeout: 10000,
});
}

module.exports = { initializeSpectron };
181 changes: 181 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
const testhelper = require('./helper.js');
const app = testhelper.initializeSpectron();
const { expect } = require('chai');

describe('Application launch', () => {
before(() => app.start());
after(() => {
if (app && app.isRunning()) {
return app.stop();
}
});

describe('start up', () => {
let tourWindow, mainWindow, previewWindow;

beforeEach(() =>
app.client.windowHandles().then(handles => {
tourWindow = handles.value[2]; // Tour
mainWindow = handles.value[1]; // Manta
previewWindow = handles.value[0]; // Previewer
})
);

it('it should create 3 windows', () =>
app.client
.waitUntilWindowLoaded()
.getWindowCount()
.then(count => {
expect(count).to.equal(3);
}));

// Tour Window
describe('it should create tourWindow', () => {
beforeEach(() => app.client.waitUntilWindowLoaded().window(tourWindow));

it('with correct title', () =>
app.client.browserWindow.getTitle().then(title => {
expect(title).to.equal('Tour');
}));

it('with correct size and placed in the center of the primary screen', () => {
let displayWidth, displayHeight;
return app.client.electron.screen
.getPrimaryDisplay()
.then(res => {
displayWidth = res.bounds.width;
displayHeight = res.bounds.height;
})
.browserWindow.getBounds()
.then(res => {
// Check Size
expect(res.width).to.equal(700);
expect(res.height).to.equal(600);
// Check Position
const winX = (displayWidth - res.width) / 2;
const winY = (displayHeight - res.height) / 2;
expect(winX).to.equal(res.x);
expect(winY).to.equal(res.y);
});
});

it('with correct properties', () =>
app.client.browserWindow
.isMinimized()
.then(isMinimized => {
expect(isMinimized).to.be.false;
})
.browserWindow.isResizable()
.then(isResizable => {
expect(isResizable).to.be.false;
})
.browserWindow.isMovable()
.then(isMovable => {
expect(isMovable).to.be.false;
})
.browserWindow.isDevToolsOpened()
.then(isDevToolsOpened => {
expect(isDevToolsOpened).to.be.false;
}));

// TODO
// Need to be able to retrive appConfig in order to test this
it('with correct visibility and focus', () =>
app.client.browserWindow
.isVisible()
.then(isVisible => {
expect(isVisible).to.be.false;
})
.browserWindow.isFocused()
.then(isFocused => {
expect(isFocused).to.be.false;
}));
});

// Main Window
describe('it should create mainWindow', () => {
beforeEach(() => app.client.waitUntilWindowLoaded().window(mainWindow));

it('with correct title', () =>
app.client.browserWindow.getTitle().then(title => {
expect(title).to.equal('Manta');
}));

it('with correct properties', () =>
app.client.browserWindow
.isMinimized()
.then(isMinimized => {
expect(isMinimized).to.be.false;
})
.browserWindow.isResizable()
.then(isResizable => {
expect(isResizable).to.be.true;
})
.browserWindow.isMovable()
.then(isMovable => {
expect(isMovable).to.be.true;
})
.browserWindow.isDevToolsOpened()
.then(isDevToolsOpened => {
expect(isDevToolsOpened).to.be.false;
}));

// TODO
// Need to be able to retrive appConfig in order to test this
it('with correct visibility and focus', () =>
app.client.browserWindow
.isVisible()
.then(isVisible => {
expect(isVisible).to.be.true;
})
.browserWindow.isFocused()
.then(isFocused => {
expect(isFocused).to.be.true;
}));
});

// Preview Window
describe('it should create previewWindow', () => {
beforeEach(() =>
app.client.waitUntilWindowLoaded().window(previewWindow)
);

it('with correct title', () =>
app.client.browserWindow.getTitle().then(title => {
expect(title).to.equal('Previewer');
}));

it('with correct properties', () =>
app.client.browserWindow
.isMinimized()
.then(isMinimized => {
expect(isMinimized).to.be.false;
})
.browserWindow.isResizable()
.then(isResizable => {
expect(isResizable).to.be.true;
})
.browserWindow.isMovable()
.then(isMovable => {
expect(isMovable).to.be.true;
})
.browserWindow.isDevToolsOpened()
.then(isDevToolsOpened => {
expect(isDevToolsOpened).to.be.false;
}));

// TODO
// Need to be able to retrive appConfig in order to test this
it('with correct visibility and focus', () =>
app.client.browserWindow
.isVisible()
.then(isVisible => {
expect(isVisible).to.be.false;
})
.browserWindow.isFocused()
.then(isFocused => {
expect(isFocused).to.be.false;
}));
});
});
});
Loading

0 comments on commit f41bcc1

Please sign in to comment.