diff --git a/conf.js b/conf.js index fdda263..3480b74 100644 --- a/conf.js +++ b/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'); - } - }; -} diff --git a/hw4-spec.js b/hw4-spec.js deleted file mode 100644 index 3b22e85..0000000 --- a/hw4-spec.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -describe('Application part 4', function () { - - it('should ...', function () { - fail('part 4 tests not implemented yet'); - }); - -}); diff --git a/package.json b/package.json index d230bac..e3ee6bc 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/spec/helpers/points-reporter.js b/spec/helpers/points-reporter.js new file mode 100644 index 0000000..d7f5336 --- /dev/null +++ b/spec/helpers/points-reporter.js @@ -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() }; diff --git a/spec/helpers/reporter.js b/spec/helpers/reporter.js new file mode 100644 index 0000000..deb72d7 --- /dev/null +++ b/spec/helpers/reporter.js @@ -0,0 +1 @@ +jasmine.getEnv().addReporter(require('./points-reporter').reporter); diff --git a/hw2-spec.js b/spec/hw2-spec.js similarity index 93% rename from hw2-spec.js rename to spec/hw2-spec.js index 4387169..7c27c25 100644 --- a/hw2-spec.js +++ b/spec/hw2-spec.js @@ -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); +} diff --git a/hw3-spec.js b/spec/hw3-spec.js similarity index 93% rename from hw3-spec.js rename to spec/hw3-spec.js index a5808d4..880f27a 100644 --- a/hw3-spec.js +++ b/spec/hw3-spec.js @@ -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); +} diff --git a/spec/hw4-spec.js b/spec/hw4-spec.js new file mode 100644 index 0000000..c826981 --- /dev/null +++ b/spec/hw4-spec.js @@ -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); +} diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json new file mode 100644 index 0000000..51a1a34 --- /dev/null +++ b/spec/support/jasmine.json @@ -0,0 +1,9 @@ +{ + "spec_dir": "spec", + "spec_files": [ + "hw3-spec.js" + ], + "helpers": [ + "helpers/reporter.js" + ] +}