1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

WIP on documentation and sample test

This commit is contained in:
vrde 2015-12-17 19:23:56 +01:00
parent 6c5a2e0869
commit e24cca1c12
4 changed files with 93 additions and 2 deletions

View File

@ -2,7 +2,8 @@
"parser": "babel-eslint",
"env": {
"browser": true,
"es6": true
"es6": true,
"mocha": true
},
"rules": {
"new-cap": [2, {newIsCap: true, capIsNew: false}],

View File

@ -35,7 +35,11 @@
"devDependencies": {
"babel-eslint": "^3.1.11",
"babel-jest": "^5.2.0",
"jest-cli": "^0.4.0"
"chai": "^3.4.1",
"chai-as-promised": "^5.1.0",
"jest-cli": "^0.4.0",
"mocha": "^2.3.4",
"wd": "^0.4.0"
},
"dependencies": {
"alt": "^0.16.5",

52
tests/README.md Normal file
View File

@ -0,0 +1,52 @@
# Welcome to our test suite, let me be your guide
Dear reader, first of all thanks for taking your time reading this document.
The purpose of this document is to give you an overview on what we want to test
and how we are doing it.
# How it works (bird's-eye view)
You will notice that the setup is a bit convoluted. This section will explain
you why. Testing single functions in JavaScript is not that hard (if you don't
need to interact with the DOM), and can be easily achieved using frameworks
like [Mocha](https://mochajs.org/). Integration and cross browser testing is,
on the other side, a huge [PITA](https://saucelabs.com/selenium/selenium-grid).
Moreover, "browser testing" includes also "mobile browser testing". Moreover,
the same browser (type and version) can behave in a different way on different
operating systems.
To achieve that you can have your own cluster of machines with different
operating systems and browsers or, if you don't want to spend the rest of your
life configuring an average of 100 browsers for each different operating
system, you can pay someone else to do that.
We decided to use [saucelabs](https://saucelabs.com/) cloud (they support [over
700 combinations](https://saucelabs.com/platforms/) of operating systems and
browsers) to run our tests.
## Components and tools
The components involved are:
- **[Selenium WebDriver](https://www.npmjs.com/package/wd)**: it's a library
that can control a browser. You can use the **WebDriver** to load new URLs,
click around, fill out forms, submit forms etc. It's basically a way to
control remotely a browser. There are other implementations in Python, PHP,
Java, etc.
- **[Selenium Grid](https://github.com/SeleniumHQ/selenium/wiki/Grid2)**: it's
the controller for the cluster of machines/devices that can run browsers.
Selenium Grid is able to scale by distributing tests on several machines,
manage multiple environments from a central point, making it easy to run the
tests against a vast combination of browsers / OS, minimize the maintenance
time for the grid by allowing you to implement custom hooks to leverage
virtual infrastructure for instance.
- **[Saucelabs](https://saucelabs.com/)**: a private company providing a
cluster to run your tests on over 700 combinations of browsers/operating
systems. (They do other things, check out their websites).
## Anatomy of a test
A test is a `.js` file. We use [Mocha](https://mochajs.org/) and [Should](https://shouldjs.github.io/).

34
tests/test-login.js Normal file
View File

@ -0,0 +1,34 @@
'use strict';
const wd = require('wd');
const chai = require("chai");
const chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
describe('Login logs users in', function() {
let browser;
before(function() {
browser = wd.promiseChainRemote('ondemand.saucelabs.com', 80,
process.env.ONION_SAUCELABS_USER || 'ascribe',
process.env.ONION_SAUCELABS_APIKEY || 'b072b4f2-6302-42f6-a25d-47162666ca66')
return browser.init({ browserName: 'chrome' });
});
beforeEach(function() {
return browser.get('http://www.ascribe.ninja/app/login');
});
after(function() {
return browser.quit();
});
it('should contain "Log in" in the title', function() {
return browser.title().should.become('Log in');
});
});