Skip to content

paladinarcher/CT-Template

Repository files navigation

For initial project set up click here. Delete this line afterwards

Overview

  • overview of project goes here example...
    • Modern features brought to IRC. Push notifications, link previews, new message markers, and more bring IRC to the 21st century.
    • Always connected. Remains connected to IRC servers while you are offline.
    • Cross platform. It doesn't matter what OS you use, it just works wherever Node.js runs.
    • Responsive interface. The client works smoothly on every desktop, smartphone and tablet.
    • Synchronized experience. Always resume where you left off no matter what device.

Installation and usage

Setup

npm install

Mocha Tests

npm test

Nightwatch Tests

npx nightwatch tests/nightwatch/example.js

Running stable releases

  • running and stable releases info goes here

Running from source

The following commands install and run the development version of:

* git commands goes here

Development setup

Simply follow the instructions to run The project from source above, on your own fork.

Contininuous Testing Snippets

  • Mocha
  • Nightwatch
  • Jenkins

Unit Testing

Mocha Tests

Setup

Comand Line:
Install Mocha by running:
        
            npm install --save-dev mocha
        
    
Install Chai by running:
        
            npm i --save-dev chai 
        
    
Test Example Test File:
        
            var assert = require('assert');
                describe('Array', function() {
                describe('#indexOf()', function() {
                    it('should return -1 when the value is not present', function() {
                    assert.equal([1, 2, 3].indexOf(4), -1);
                    });
                });
            });
        
    
Test Script
Set up a test script in package.json:
        
            "scripts": {
                "test": "mocha"
            }  
        
    
Run Test
        
            npm test
        
    

Mocha Tools/Snippest

describe()
describe() - is simply a way to group tests in Mocha. Describe() takes two arguments, the first is the name of the test group, and the second is a callback function.
Snippet:
    
        describe('string name', function(){
            // can nest more describe()'s here, or tests go here
        });
    
it()
it() is used for an individual test case. it() should be written as if you were saying it out loud: “It should equal zero”, “It should log the user in”, etc. it() takes two arguments, a string explaining what the test should do, and a callback function which contains our actual test:
Snippet:
    
        it('should...', function(){
            // Test case goes here
        });
    
Assert
Assert - There are a number of different assertion tests included with assert. Chai provides the following assertion styles:
Assert Style:

var assert = require('chai').assert;
var numbers = [1, 2, 3, 4, 5];

assert.isArray(numbers, 'is array of numbers'); assert.include(numbers, 2, 'array contains 2'); assert.lengthOf(numbers, 5, 'array contains 5 numbers');

Expect style:


var expect = require('chai').expect;
var numbers = [1, 2, 3, 4, 5];

expect(numbers).to.be.an('array').that.includes(2);
expect(numbers).to.have.lengthOf(5);

Should style:


var should = require('chai').should();
var numbers = [1, 2, 3, 4, 5];

numbers.should.be.an('array').that.includes(2);
numbers.should.have.lengthOf(5);

Example

// Require the built in 'assertion' library
var assert = require('assert');
// Create a group of tests about Arrays
describe('Array', function() {
    // Within our Array group, Create a group of tests for indexOf
    describe('#indexOf()', function() {
        // A string explanation of what we're testing
        it('should return -1 when the value is not present', function(){
            // Our actual test: -1 should equal indexOf(...)
            assert.equal(-1, [1,2,3].indexOf(4));
        });
    });
});

End to End Testing

Nightwatch Tests

Setup

To run Nightwatch locally we will need a standalone Selenium server locally, as well as a webdriver, so we can use Chrome/Firefox to test our applications locally.
Prequisite:
JDK Needs to be installed
Comand Line:
Add nightwatch to you project by running:

npm install nightwatch geckodriver chromedriver --save-dev

Test successfull installation by running:

npx nightwatch node_modules/nightwatch/examples/tests/ecosia.js
Running Tests
Global

    nightwatch [source] [options]

Project specific

    npx nightwatch [source] [options]

Example - single test:

    nightwatch tests/one/firstTest.js

Example - 2 individual tests:

    nightwatch tests/one/firstTest.js tests/secondTest.js

Example - 1 individual test and 1 folder:

    nightwatch tests/one/test.js tests/utils

Test Example:


module.exports = {
    'Demo test Google' : function (client) {
        client
        .url('http://www.google.com')
        .waitForElementVisible('body', 1000)
        .assert.title('Google')
        .assert.visible('input[type=text]')
        .setValue('input[type=text]', 'rembrandt van rijn')
        .waitForElementVisible('button[name=btnG]', 1000)
        .click('button[name=btnG]')
        .pause(1000)
        .assert.containsText('ol#rso li:first-child',
            'Rembrandt - Wikipedia')
        .end()
    }
}

Tools:

.assert - when an assertion fails, the test ends, skipping all other assertions.
.verify - when an assertion fails, the test logs the failure and continues with other assertions.

assert[.not].attributeContains()

    this.demoTest = function (browser) {
        browser.assert.attributeContains('#someElement', 'href', 'google.com');
    };  

assert[.not].attributeEquals()

    this.demoTest = function (browser) {
        browser.assert.attributeEquals("body", "data-attr", "some value");
    };

assert[.not].containsText()

    this.demoTest = function (browser) {
        browser.assert.containsText("#main", "The Night Watch");
    };

assert[.not].cssClassPresent()

    this.demoTest = function (browser) {
        browser.assert.cssClassPresent("#main", "container");
        browser.assert.cssClassPresent('#main', ['visible', 'container']);
        browser.assert.cssClassPresent('#main', 'visible container');
    };

assert[.not].cssProperty()

    this.demoTest = function (browser) {
        browser.assert.cssProperty("#main", "display", "block");
    };

assert[.not].domPropertyContains()

    this.demoTest = function (browser) {
        browser.assert.domPropertyContains('#main', 'classList', 'visible');
    // in case the resulting property is an array, several elements could be specified
    browser.assert.domPropertyEquals('#main', 'classList', ['class-one', 'class-two']);
    browser.assert.domPropertyEquals('#main', 'classList', 'class-one,class-two');
};
assert[.not].domPropertyEquals()

    this.demoTest = function (browser) {
        browser.assert.domPropertyEquals('#main', 'className', 'visible');
    // deep equal will be performed
    browser.assert.domPropertyEquals('#main', 'classList', ['class-one', 'class-two']);
  
    // split on ',' and deep equal will be performed
    browser.assert.domPropertyEquals('#main', 'classList', 'class-one,class-two']);
};
assert[.not].elementPresent()

    this.demoTest = function (browser) {
        browser.assert.elementPresent("#main");
    };

assert[.not].title()

    this.demoTest = function (browser) {
        browser.assert.title("Nightwatch.js");
    };      

assert[.not].urlContains()

    this.demoTest = function (browser) {
        browser.assert.urlContains('nightwatchjs.org');
    };

assert[.not].urlEquals()

    this.demoTest = function (browser) {
        browser.assert.urlEquals('https://www.google.com');
    };

assert[.not].value()

    this.demoTest = function (browser) {
        browser.assert.value("form.login input[type=text]", "username");
    };

assert[.not].valueContains()

    this.demoTest = function (browser) {
        browser.assert.valueContains("form.login input[type=text]", "username");
    };

assert[.not].visible()

    this.demoTest = function (browser) {
        browser.assert.visible('.should_be_visible');
        browser.assert.visible({selector: '.should_be_visible'});
        browser.assert.visible({selector: '.should_be_visible', supressNotFoundErrors: true});
    };

Language Chains

The following are provided as chainable getters to improve the readability of your assertions. They do not provide testing capabilities and the order is not important.

  • to
  • be
  • been
  • is
  • that
  • which
  • and
  • has
  • have
  • with
  • at
  • does
  • of
.equal(value)/.contain(value)/.match(regex)

this.demoTest = function (browser) {
    browser.expect.element('#main').text.to.equal('The Night Watch');
browser.expect.element('#main').text.to.contain('The Night Watch');

browser.expect.element('#main').to.have.css('display').which.equals('block');

};

.startWith(value)/.endWith(value)


this.demoTest = function (browser) {
    browser.expect.element('#main').text.to.endWith('Watch');
    
    browser.expect.element('#main').text.to.startWith('The');
};

.not


this.demoTest = function (browser) {
    browser.expect.element('#main').text.to.not.equal('The Night Watch');
    
    browser.expect.element('#main').text.to.not.contain('The Night Watch');
    
    browser.expect.element('#main').to.have.css('display').which.does.not.equal('block');
};

.before(ms)/.after(ms)


this.demoTest = function (browser) {
    browser.expect.element('#main').text.to.contain('The Night Watch').before(1000);
    
    browser.expect.element('#main').text.to.not.contain('The Night Watch').after(500);
};      

expect.cookie()


browser.expect.cookie('cookie-name', ['cookie-domain'])


this.demoTest = function (browser) {
    browser.expect.cookie('cookie-name').to.contain('cookie-value');
    browser.expect.cookie('cookie-name').to.match(/regex/);
    browser.expect.cookie('loginCookie', 'example.org').to.contain('cookie-value');
};

expect.element()


    browser.element('#selector')

.a(type)Suggest edits


this.demoTest = function (browser) {
    browser.expect.element('#q').to.be.an('input');
    browser.expect.element('#q').to.be.an('input', 'Testing if #q is an input');
    browser.expect.element('#w').to.be.a('span');
}

.active


this.demoTest = function (browser) {
    browser.expect.element('#main').to.be.active;
    browser.expect.element('#main').to.not.be.active;
    browser.expect.element('#main').to.be.active.before(100);
};

.attribute(name)


this.demoTest = function (browser) {
    browser.expect.element('body').to.have.attribute('data-attr');
    browser.expect.element('body').to.not.have.attribute('data-attr');
    browser.expect.element('body').to.not.have.attribute('data-attr', 'Testing if body does not have data-attr');
    browser.expect.element('body').to.have.attribute('data-attr').before(100);
    browser.expect.element('body').to.have.attribute('data-attr')
        .equals('some attribute');
    browser.expect.element('body').to.have.attribute('data-attr')
        .not.equals('other attribute');
    browser.expect.element('body').to.have.attribute('data-attr')
        .which.contains('something');
    browser.expect.element('body').to.have.attribute('data-attr')
        .which.matches(/^something\ else/);
};

.css(property)


this.demoTest = function (browser) {
    browser.expect.element('#main').to.have.css('display');
    browser.expect.element('#main').to.have.css('display', 'Testing for display');
    browser.expect.element('#main').to.not.have.css('display');
    browser.expect.element('#main').to.have.css('display').before(100);
    browser.expect.element('#main').to.have.css('display').which.equals('block');
    browser.expect.element('#main').to.have.css('display').which.contains('some value');
    browser.expect.element('#main').to.have.css('display').which.matches(/some\ value/);
};

.enabled


this.demoTest = function (browser) {
    browser.expect.element('#weblogin').to.be.enabled;
    browser.expect.element('#main').to.not.be.enabled;
    browser.expect.element('#main').to.be.enabled.before(100);
};

.present


this.demoTest = function (browser) {
    browser.expect.element('#main').to.be.present;
    browser.expect.element('#main').to.not.be.present;
    browser.expect.element('#main').to.be.present.before(100);
};

.property(name)


this.demoTest = function (browser) {
    browser.expect.element('body').to.have.property('className').equals('test-class');
    browser.expect.element('body').to.have.property('className').matches(/^something\ else/);
    browser.expect.element('body').to.not.have.property('classList').equals('test-class');
    browser.expect.element('body').to.have.property('classList').deep.equal(['class-one', 'class-two']);
    browser.expect.element('body').to.have.property('classList').contain('class-two');
};

.selected


this.demoTest = function (browser) {
    browser.expect.element('#main').to.be.selected;
    browser.expect.element('#main').to.not.be.selected;
    browser.expect.element('#main').to.be.selected.before(100);
};

.text


this.demoTest = function (browser) {
    browser.expect.element('#main').text.to.equal('The Night Watch');
    browser.expect.element('#main').text.to.not.equal('The Night Watch');
    browser.expect.element('#main').text.to.equal('The Night Watch').before(100);
    browser.expect.element('#main').text.to.contain('The Night Watch');
    browser.expect.element('#main').text.to.match(/The\ Night\ Watch/);
};

.value


this.demoTest = function (browser) {
    browser.expect.element('#q').to.have.value.that.equals('search');
    browser.expect.element('#q').to.have.value.not.equals('search');
    browser.expect.element('#q').to.have.value.which.contains('search');
    browser.expect.element('#q').to.have.value.which.matches(/search/);
};

.visible


this.demoTest = function (browser) {
    browser.expect.element('#main').to.be.visible;
    browser.expect.element('#main').to.not.be.visible;
    browser.expect.element('#main').to.be.visible.before(100);
};

expect.elements()


    browser.elements('#selector')

.elements().count


this.demoTest = function (browser) {
    browser.expect.elements('div').count.to.equal(10);
    browser.expect.elements('p').count.to.not.equal(1);
}

.expect.title()

this.demoTest = function (browser) {
    browser.expect.title().to.contain('value');
    browser.expect.title().to.match(/value/);
};

.expect.url()


this.demoTest = function (browser) {
    browser.expect.url().to.contain('https://');
    browser.expect.url().to.endWith('.org');
};

Continuous Testing

Jenkins

About

Repo set up with continuous testing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published