mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
test: Update protractor to v3 and use mocha
This commit is contained in:
@@ -131,7 +131,7 @@
|
|||||||
"mongodb": "^2.0.46",
|
"mongodb": "^2.0.46",
|
||||||
"mongoskin": "~0.6.1",
|
"mongoskin": "~0.6.1",
|
||||||
"phantomjs": "^1.9",
|
"phantomjs": "^1.9",
|
||||||
"protractor": "~2.5.1",
|
"protractor": "^3.1.1",
|
||||||
"rewire": "^2.3.3",
|
"rewire": "^2.3.3",
|
||||||
"rimraf": "^2.4.3",
|
"rimraf": "^2.4.3",
|
||||||
"run-sequence": "^1.1.4",
|
"run-sequence": "^1.1.4",
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
// An example configuration file.
|
'use strict'
|
||||||
|
|
||||||
|
require('babel-register');
|
||||||
|
require('babel-polyfill');
|
||||||
|
|
||||||
exports.config = {
|
exports.config = {
|
||||||
// The address of a running selenium server.
|
specs: 'test/e2e/**/*.js',
|
||||||
|
baseUrl: 'http://localhost:3003/',
|
||||||
|
directConnect: true,
|
||||||
seleniumAddress: 'http://localhost:4444/wd/hub',
|
seleniumAddress: 'http://localhost:4444/wd/hub',
|
||||||
|
framework: 'mocha',
|
||||||
// Capabilities to be passed to the webdriver instance.
|
mochaOpts: {
|
||||||
capabilities: {
|
reporter: 'spec',
|
||||||
'browserName': 'firefox'
|
slow: 6000,
|
||||||
|
timeout: 10000,
|
||||||
|
compilers: 'js:babel-register'
|
||||||
},
|
},
|
||||||
|
onPrepare: () => {
|
||||||
|
browser.ignoreSynchronization = true;
|
||||||
|
let chai = require('chai');
|
||||||
|
let chaiAsPromised = require('chai-as-promised');
|
||||||
|
|
||||||
// Spec patterns are relative to the current working directly when
|
chai.use(chaiAsPromised);
|
||||||
// protractor is called.
|
global.expect = chai.expect;
|
||||||
specs: ['test/e2e/e2e.js'],
|
},
|
||||||
|
|
||||||
// A base URL for your application under test. Calls to protractor.get()
|
|
||||||
// with relative paths will be prepended with this.
|
|
||||||
baseUrl: 'http://localhost:3003',
|
|
||||||
|
|
||||||
// Options to be passed to Jasmine-node.
|
|
||||||
jasmineNodeOpts: {
|
|
||||||
showColors: true,
|
|
||||||
defaultTimeoutInterval: 90000,
|
|
||||||
isVerbose: true,
|
|
||||||
displayPendingSpec: true
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -297,11 +297,12 @@ gulp.task('test:e2e:safe', ['test:prepare', 'test:prepare:server'], (cb) => {
|
|||||||
* Note: As it stands, protractor wont report pending specs
|
* Note: As it stands, protractor wont report pending specs
|
||||||
*/
|
*/
|
||||||
let match = stdout.match(/(\d+) tests?.*(\d) failures?/);
|
let match = stdout.match(/(\d+) tests?.*(\d) failures?/);
|
||||||
|
|
||||||
testResults.push({
|
testResults.push({
|
||||||
suite: 'End-to-End Specs',
|
suite: 'End-to-End Specs\t',
|
||||||
pass: parseInt(match[1]) - parseInt(match[2]),
|
pass: testCount(stdout, /(\d+) passing/),
|
||||||
fail: parseInt(match[2]),
|
fail: testCount(stdout, /(\d+) failing/),
|
||||||
pend: 0
|
pend: testCount(stdout, /(\d+) pending/)
|
||||||
});
|
});
|
||||||
support.forEach(kill);
|
support.forEach(kill);
|
||||||
cb();
|
cb();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"rules": {
|
"rules": {
|
||||||
"one-var": 0,
|
"one-var": 0,
|
||||||
|
"func-names": 0,
|
||||||
"max-nested-callbacks": 0,
|
"max-nested-callbacks": 0,
|
||||||
"no-unused-expressions": 0,
|
"no-unused-expressions": 0,
|
||||||
"mocha/no-exclusive-tests": 2,
|
"mocha/no-exclusive-tests": 2,
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
{
|
{
|
||||||
"rules": {
|
|
||||||
"func-names": 0,
|
|
||||||
"no-var": 0,
|
|
||||||
"prefer-template": 0
|
|
||||||
},
|
|
||||||
"globals": {
|
"globals": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"by": true,
|
"by": true,
|
||||||
"element": true,
|
"element": true
|
||||||
"jasmine": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
describe('front page', function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
browser.ignoreSynchronization = true;
|
|
||||||
browser.get('/');
|
|
||||||
browser.sleep(1000);
|
|
||||||
});
|
|
||||||
|
|
||||||
// based on https://github.com/angular/protractor/issues/114#issuecomment-29046939
|
|
||||||
afterEach(function () {
|
|
||||||
var currentSpec = jasmine.getEnv().currentSpec;
|
|
||||||
var passed = currentSpec.results().passed();
|
|
||||||
if (!passed) {
|
|
||||||
var filename = 'exception_' + currentSpec.description + '.png';
|
|
||||||
browser.takeScreenshot().then(function (png) {
|
|
||||||
var buffer = new Buffer(png, 'base64');
|
|
||||||
var stream = fs.createWriteStream(filename);
|
|
||||||
stream.write(buffer);
|
|
||||||
stream.end();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('shows the front page', function () {
|
|
||||||
var button = element(by.id('play-btn'));
|
|
||||||
expect(button.getText()).toEqual('Join for free');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not login when using wrong credentials', function () {
|
|
||||||
var button = element(by.id('play-btn'));
|
|
||||||
button.click();
|
|
||||||
browser.sleep(1000);
|
|
||||||
element(by.model('loginUsername')).sendKeys('username');
|
|
||||||
element(by.model('loginPassword')).sendKeys('pass');
|
|
||||||
var login = element(by.css('#loginForm input[value="Login"]'));
|
|
||||||
login.click();
|
|
||||||
var alertDialog = browser.switchTo().alert();
|
|
||||||
expect(alertDialog.getText()).toMatch('Uh-oh - your username or password is incorrect.\n- Make sure your username or email is typed correctly.\n- You may have signed up with Facebook, not email. Double-check by trying Facebook login.\n- If you forgot your password, click "Forgot Password" on the habitica.com website\'s login form.');
|
|
||||||
alertDialog.accept();
|
|
||||||
});
|
|
||||||
|
|
||||||
xit('registers a new user', function () {
|
|
||||||
var button = element(by.id('play-btn'));
|
|
||||||
button.click();
|
|
||||||
browser.sleep(1000);
|
|
||||||
var registerTab = element(by.linkText('Register'));
|
|
||||||
registerTab.click();
|
|
||||||
element(by.model('registerVals.username')).sendKeys('user');
|
|
||||||
element(by.model('registerVals.email')).sendKeys('user@example.com');
|
|
||||||
element(by.model('registerVals.password')).sendKeys('pass');
|
|
||||||
element(by.model('registerVals.confirmPassword')).sendKeys('pass');
|
|
||||||
var register = element(by.css('#registrationForm input[value="Register"]'));
|
|
||||||
register.click();
|
|
||||||
browser.sleep(1000);
|
|
||||||
browser.getCurrentUrl().then(function (url) {
|
|
||||||
expect(url).not.toMatch(/static\/front/);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
62
test/e2e/front-page.test.js
Normal file
62
test/e2e/front-page.test.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
describe('Static Front Page', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
browser.get('/');
|
||||||
|
browser.sleep(1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
// based on https://github.com/angular/protractor/issues/114#issuecomment-29046939
|
||||||
|
afterEach(async function () {
|
||||||
|
let lastTest = this.currentTest;
|
||||||
|
|
||||||
|
if (lastTest.state === 'failed') {
|
||||||
|
let filename = `exception_${lastTest.title}.png`;
|
||||||
|
let png = await browser.takeScreenshot();
|
||||||
|
let buffer = new Buffer(png, 'base64');
|
||||||
|
let stream = fs.createWriteStream(filename);
|
||||||
|
|
||||||
|
stream.write(buffer);
|
||||||
|
stream.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows the front page', async () => {
|
||||||
|
let button = element(by.id('play-btn'));
|
||||||
|
await expect(button.getText()).to.eventually.eql('Join for free');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not login when using wrong credentials', async () => {
|
||||||
|
let button = element(by.id('play-btn'));
|
||||||
|
button.click();
|
||||||
|
browser.sleep(1000);
|
||||||
|
element(by.model('loginUsername')).sendKeys('username');
|
||||||
|
element(by.model('loginPassword')).sendKeys('pass');
|
||||||
|
let login = element(by.css('#loginForm input[value="Login"]'));
|
||||||
|
login.click();
|
||||||
|
browser.sleep(1000);
|
||||||
|
let alertDialog = browser.switchTo().alert();
|
||||||
|
|
||||||
|
await expect(alertDialog.getText()).to.eventually.match(/username or password is incorrect./);
|
||||||
|
|
||||||
|
alertDialog.accept();
|
||||||
|
});
|
||||||
|
|
||||||
|
xit('registers a new user', function () {
|
||||||
|
let button = element(by.id('play-btn'));
|
||||||
|
button.click();
|
||||||
|
browser.sleep(1000);
|
||||||
|
let registerTab = element(by.linkText('Register'));
|
||||||
|
registerTab.click();
|
||||||
|
element(by.model('registerVals.username')).sendKeys('user');
|
||||||
|
element(by.model('registerVals.email')).sendKeys('user@example.com');
|
||||||
|
element(by.model('registerVals.password')).sendKeys('pass');
|
||||||
|
element(by.model('registerVals.confirmPassword')).sendKeys('pass');
|
||||||
|
let register = element(by.css('#registrationForm input[value="Register"]'));
|
||||||
|
register.click();
|
||||||
|
browser.sleep(1000);
|
||||||
|
browser.getCurrentUrl().then(function (url) {
|
||||||
|
expect(url).not.toMatch(/static\/front/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user