added points reporter
This commit is contained in:
18
conf.js
18
conf.js
@@ -1,4 +1,5 @@
|
||||
exports.config = {
|
||||
|
||||
seleniumAddress: 'http://localhost:4444/wd/hub',
|
||||
|
||||
capabilities: {
|
||||
@@ -6,26 +7,13 @@ exports.config = {
|
||||
'phantomjs.cli.args': ['--ignore-ssl-errors=true']
|
||||
},
|
||||
|
||||
suites: {
|
||||
hw2: 'hw2-spec.js',
|
||||
hw3: 'hw3-spec.js',
|
||||
hw4: 'hw4-spec.js'
|
||||
},
|
||||
|
||||
jasmineNodeOpts: {
|
||||
showColors: true
|
||||
},
|
||||
|
||||
onPrepare: function() {
|
||||
jasmine.getEnv().addReporter(getReporter());
|
||||
jasmine.getEnv()
|
||||
.addReporter(require('./spec/helpers/points-reporter').reporter);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function getReporter() {
|
||||
return {
|
||||
suiteDone: function(result) {
|
||||
console.log('Suite ' + result.description + ' done');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
describe('Application part 4', function () {
|
||||
|
||||
it('should ...', function () {
|
||||
fail('part 4 tests not implemented yet');
|
||||
});
|
||||
|
||||
});
|
||||
@@ -5,12 +5,11 @@
|
||||
"update": "webdriver-manager update",
|
||||
"postinstall": "npm run update",
|
||||
"start": "webdriver-manager start",
|
||||
"hw2tests": "protractor ./conf.js --suite=hw2",
|
||||
"hw3tests": "jasmine-node --matchall hw3-spec.js",
|
||||
"hw4tests": "protractor ./conf.js --suite=hw4"
|
||||
"hw2tests": "protractor ./conf.js --specs spec/hw2-spec.js",
|
||||
"hw3tests": "jasmine",
|
||||
"hw4tests": "protractor ./conf.js --specs spec/hw4-spec.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jasmine-node": "^1.14.5",
|
||||
"phantomjs": "^2.1.7",
|
||||
"protractor": "^4.0.11",
|
||||
"request": "^2.79.0"
|
||||
|
||||
66
spec/helpers/points-reporter.js
Normal file
66
spec/helpers/points-reporter.js
Normal file
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
function extendIt(oldIt) {
|
||||
return function (description, testFunction) {
|
||||
var regEx1 = /^(function )?\(([^)]+)\)/;
|
||||
var regEx2 = /^\w+\s*=>/;
|
||||
var hasArguments = testFunction.toString().match(regEx1)
|
||||
|| testFunction.toString().match(regEx2);
|
||||
|
||||
return {
|
||||
deductedOnFailure: hasArguments
|
||||
? getSpecWithDone : getSpecWithoutDone
|
||||
};
|
||||
|
||||
function getSpecWithDone(deduction) {
|
||||
var spec = oldIt(description, function(done) {
|
||||
spec.result.deduction = deduction;
|
||||
testFunction(done);
|
||||
});
|
||||
}
|
||||
|
||||
function getSpecWithoutDone(deduction) {
|
||||
var spec = oldIt(description, function() {
|
||||
spec.result.deduction = deduction;
|
||||
testFunction();
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
function reporter() {
|
||||
var counter = new PointCounter(10);
|
||||
var allTestsEnabled = true;
|
||||
|
||||
return {
|
||||
specDone: function(result) {
|
||||
if (result.status !== 'passed') {
|
||||
counter.subtract(result.deduction);
|
||||
}
|
||||
if (result.status === 'pending' || result.status === 'disabled') {
|
||||
allTestsEnabled = false;
|
||||
}
|
||||
},
|
||||
|
||||
suiteDone: function(result) {
|
||||
if (allTestsEnabled) {
|
||||
console.log('\nRESULT: ' + counter.getResult() + ' POINTS');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function PointCounter(maxPoints) {
|
||||
var count = maxPoints;
|
||||
|
||||
this.getResult = function() {
|
||||
return Math.max(0, count);
|
||||
};
|
||||
|
||||
this.subtract = function(howMany) {
|
||||
count -= howMany;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { extendIt: extendIt, reporter: reporter() };
|
||||
1
spec/helpers/reporter.js
Normal file
1
spec/helpers/reporter.js
Normal file
@@ -0,0 +1 @@
|
||||
jasmine.getEnv().addReporter(require('./points-reporter').reporter);
|
||||
@@ -4,6 +4,8 @@ var BASE_URL = 'http://localhost:3000/';
|
||||
|
||||
describe('Application part 2', function () {
|
||||
|
||||
it = extendIt(it); fit = extendIt(fit); xit = extendIt(xit);
|
||||
|
||||
beforeEach(function() {
|
||||
goTo(BASE_URL);
|
||||
});
|
||||
@@ -18,7 +20,9 @@ describe('Application part 2', function () {
|
||||
link('menu-search').click();
|
||||
|
||||
expect(currentUrl()).toBe(getUrl('#/search'));
|
||||
});
|
||||
|
||||
}).deductedOnFailure(10);
|
||||
|
||||
|
||||
it('should insert contact with name and phone number', function () {
|
||||
|
||||
@@ -35,7 +39,9 @@ describe('Application part 2', function () {
|
||||
|
||||
expect(element(by.tagName('table')).getText()).toContain(sampleData.name);
|
||||
expect(element(by.tagName('table')).getText()).toContain(sampleData.phone);
|
||||
});
|
||||
|
||||
}).deductedOnFailure(10);
|
||||
|
||||
|
||||
it('selecting a contact should change its row\'s css class', function () {
|
||||
var name = getSampleData().name;
|
||||
@@ -46,7 +52,9 @@ describe('Application part 2', function () {
|
||||
var cssClassesList = rowContainingText(name).cssClasses();
|
||||
|
||||
expect(cssClassesList).toContain('selected');
|
||||
});
|
||||
|
||||
}).deductedOnFailure(2);
|
||||
|
||||
|
||||
it('should be able to edit contacts', function () {
|
||||
var sampleData = getSampleData();
|
||||
@@ -61,7 +69,9 @@ describe('Application part 2', function () {
|
||||
expect(currentUrl()).toBe(getUrl('#/search'));
|
||||
expect(element(by.tagName('table')).getText()).toContain(changedName);
|
||||
expect(element(by.tagName('table')).getText()).not.toContain(sampleData.name);
|
||||
});
|
||||
|
||||
}).deductedOnFailure(5);
|
||||
|
||||
|
||||
it('should ask confirmation on deleting', function () {
|
||||
var name = getSampleData().name;
|
||||
@@ -70,7 +80,9 @@ describe('Application part 2', function () {
|
||||
rowContainingText(name).elementWithCssClass('delete-link').click();
|
||||
|
||||
expect(element(by.id('simple-modal')).isPresent()).toBe(true, "can't find modal");
|
||||
});
|
||||
|
||||
}).deductedOnFailure(1);
|
||||
|
||||
|
||||
it('should delete contacts', function () {
|
||||
|
||||
@@ -86,7 +98,9 @@ describe('Application part 2', function () {
|
||||
expect(currentUrl()).toBe(getUrl('#/search'));
|
||||
|
||||
expect(element(by.tagName('table')).getText()).not.toContain(name);
|
||||
});
|
||||
|
||||
}).deductedOnFailure(1);
|
||||
|
||||
|
||||
it('should filter by name and phone', function () {
|
||||
|
||||
@@ -101,7 +115,8 @@ describe('Application part 2', function () {
|
||||
expect(element(by.tagName('table')).getText()).toContain('Jaak');
|
||||
expect(element(by.tagName('table')).getText()).toContain('Tiit');
|
||||
expect(element(by.tagName('table')).getText()).not.toContain('Tiina');
|
||||
});
|
||||
|
||||
}).deductedOnFailure(2);
|
||||
|
||||
});
|
||||
|
||||
@@ -202,3 +217,7 @@ function insertContact(name, phone) {
|
||||
input('phone-input').setValue(phone);
|
||||
link('save-link').click();
|
||||
}
|
||||
|
||||
function extendIt(it) {
|
||||
return require('./helpers/points-reporter').extendIt(it);
|
||||
}
|
||||
@@ -4,6 +4,8 @@ var BASE_URL = 'http://localhost:3000/';
|
||||
|
||||
describe('Application part 3', function() {
|
||||
|
||||
it = extendIt(it); fit = extendIt(fit); xit = extendIt(xit);
|
||||
|
||||
it('should insert contact with name and phone number', done => {
|
||||
var sampleData = getSampleData();
|
||||
var data = { name : sampleData.name, phone : sampleData.phone };
|
||||
@@ -15,7 +17,9 @@ describe('Application part 3', function() {
|
||||
expect(contacts.map(each => each.phone)).toContain(sampleData.phone);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
}).deductedOnFailure(10);
|
||||
|
||||
|
||||
it('should modify contact', done => {
|
||||
var name = getSampleData().name;
|
||||
@@ -34,7 +38,9 @@ describe('Application part 3', function() {
|
||||
expect(contacts.map(each => each.name)).toContain(nameChanged);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
}).deductedOnFailure(10);
|
||||
|
||||
|
||||
it('should delete contact', done => {
|
||||
var name = getSampleData().name;
|
||||
@@ -50,7 +56,9 @@ describe('Application part 3', function() {
|
||||
expect(contacts.map(each => each.name)).not.toContain(name);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
}).deductedOnFailure(5);
|
||||
|
||||
|
||||
it('should delete multiple contacts', done => {
|
||||
var name = 'Jack';
|
||||
@@ -70,7 +78,8 @@ describe('Application part 3', function() {
|
||||
expect(contacts.map(each => each.name)).not.toContain(name);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
}).deductedOnFailure(2);
|
||||
});
|
||||
|
||||
var request = require('request');
|
||||
@@ -131,3 +140,7 @@ function getSampleData() {
|
||||
function getUrl(path) {
|
||||
return BASE_URL.replace(/\/$/, '') + '/' + path;
|
||||
}
|
||||
|
||||
function extendIt(it) {
|
||||
return require('./helpers/points-reporter').extendIt(it);
|
||||
}
|
||||
17
spec/hw4-spec.js
Normal file
17
spec/hw4-spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
describe('Application part 4', function () {
|
||||
|
||||
it = extendIt(it); fit = extendIt(fit); xit = extendIt(xit);
|
||||
|
||||
it('should ...', function () {
|
||||
|
||||
fail('not implemented yet');
|
||||
|
||||
}).deductedOnFailure(10);
|
||||
|
||||
});
|
||||
|
||||
function extendIt(it) {
|
||||
return require('./helpers/points-reporter').extendIt(it);
|
||||
}
|
||||
9
spec/support/jasmine.json
Normal file
9
spec/support/jasmine.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"spec_dir": "spec",
|
||||
"spec_files": [
|
||||
"hw3-spec.js"
|
||||
],
|
||||
"helpers": [
|
||||
"helpers/reporter.js"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user