Skip to content

Commit

Permalink
ci:Functional tests 1st try
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Dec 4, 2016
1 parent d8612b6 commit 7877387
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/*
npm-debug.log
selenium-debug.log
tasks/node_modules/*
tasks/json/*
tasks/npm-debug.log
Expand Down
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ plugins/
.travis.yml
.eslintrc.json
.eslintignore
abe.json
abe.json
selenium-debug.log
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ node_js:
- "7"
env:
- NODE_ENV=PROD
before_install:
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16"
install:
- npm install
before_script:
- npm run distribute
script:
- npm run test-coveralls
- npm run test-func
- npm run lint
1 change: 0 additions & 1 deletion dump.rdb

This file was deleted.

90 changes: 90 additions & 0 deletions nightwatch.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const SCREENSHOT_PATH = "./screenshots/";
const BINPATH = './node_modules/nightwatch/bin/';

module.exports = {
"src_folders": [
"tests/functional"
],
"output_folder": "./reports",
"test_runner" : "mocha",
"selenium": {
"start_process": true,
"server_path": "./node_modules/nightwatch/bin/selenium.jar",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver"
}
},
"test_settings": {
"default": {
"launch_url" : "http://localhost:3003/abe/editor",
"silent": true,
"screenshots": {
"enabled": false,
"path": ''
},
"globals": {
"waitForConditionTimeout": 3000
},
"desiredCapabilities" : {
"browserName" : "chrome",
"javascriptEnabled" : true,
"acceptSslCerts" : true,
"chromeOptions" : {
"args" : ["start-fullscreen"]
}
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts" : true,
"chromeOptions" : {
"args" : ["start-fullscreen"]
}
}
}
}
}
/**
* selenium-download does exactly what it's name suggests;
* downloads (or updates) the version of Selenium (& chromedriver)
* on your localhost where it will be used by Nightwatch.
/the following code checks for the existence of `selenium.jar` before trying to run our tests.
*/

require('fs').stat(BINPATH + 'selenium.jar', function (err, stat) { // got it?
if (err || !stat || stat.size < 1) {
require('selenium-download').ensure(BINPATH, function(error) {
if (error) throw new Error(error); // no point continuing so exit!
console.log('✔ Selenium & Chromedriver downloaded to:', BINPATH);
});
}
});

function padLeft (count) {
return count < 10 ? '0' + count : count.toString();
}

var FILECOUNT = 0;
/**
* The default is to save screenshots to the root of your project even though
* there is a screenshots path in the config object above! ... so we need a
* function that returns the correct path for storing our screenshots.
* While we're at it, we are adding some meta-data to the filename, specifically
* the Platform/Browser where the test was run and the test (file) name.
*/
function imgpath (browser) {
var a = browser.options.desiredCapabilities;
var meta = [a.platform];
meta.push(a.browserName ? a.browserName : 'any');
meta.push(a.version ? a.version : 'any');
meta.push(a.name); // this is the test filename so always exists.
var metadata = meta.join('~').toLowerCase().replace(/ /g, '');
return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_';
}

module.exports.imgpath = imgpath;
module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
"url": "git://github.com/AdFabConnect/abejs.git"
},
"scripts": {
"postinstall": "node nightwatch.conf.js",
"lint": "eslint src --fix",
"test": "mocha --recursive --compilers js:babel-register --require babel-polyfill",
"test-cov": "istanbul cover _mocha -- --recursive --compilers js:babel-register --require babel-polyfill",
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --recursive --compilers js:babel-register --require babel-polyfill -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"pretest-func": "ROOT=$PWD/tests/demo ./dist/index.js serve -p 3003 &",
"test-func": "sleep 6 && node_modules/.bin/nightwatch --config nightwatch.conf.js",
"posttest-func":"killall node",
"start": "node --debug --harmony ./dist/server/index.js",
"startpm2": "pm2 startOrRestart ./processes.json",
"babel": "babelify --presets [ es2015 ] src/server/public/scripts/template-engine.js -o src/server/public/scripts/template-engine-compiled.js",
Expand All @@ -27,6 +31,7 @@
"build:front": "npm run js:admin && npm run js:users && npm run js:engine && npm run sass",
"build:scripts": "npm run build:front && ./node_modules/.bin/babel --presets es2015,stage-0 -d dist/server src/server/ && ./node_modules/.bin/babel --presets es2015,stage-0 -d dist/cli src/cli/ && npm run mvasset",
"compile": "./node_modules/.bin/babel --presets es2015,stage-0 -d dist/ src/ && cp -r src/cli/core/config/config.json dist/cli/core/config/config.json",
"distribute": "npm run build:front && npm run compile && npm run mvasset",
"watchdev": "npm run build:front && npm run compile && npm run mvasset && nodemon --debug --exec npm run compile && npm run mvasset --kill-others",
"startdev": "npm run build:front && npm run compile && npm run mvasset && node src/tasks/nodemon.js & npm run watch --kill-others",
"startdevOnly": "npm run js:admin && npm run js:users && npm run js:engine && node src/tasks/nodemon.js & npm run watch --kill-others"
Expand Down Expand Up @@ -109,9 +114,11 @@
"eslint": "^3.6.0",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^3.0.2",
"nightwatch": "^0.9.9",
"node-sass": "^3.7.0",
"nodemon": "^1.8.1",
"parallelshell": "^2.0.0",
"selenium-download": "^2.0.7",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0",
"watchify": "^3.4.0"
Expand Down
16 changes: 10 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ program
.alias('gp')
.description('save post to file with type from folder')
.option('-t, --type [type]', 'posts status draft|other')
.option('-t, --path [path]', 'path /relative/path')
.option('-p, --path [path]', 'path /relative/path')
.option('-d, --destination [destination]', 'folder to save result')
.action(function(options){
var dir = process.cwd()
Expand Down Expand Up @@ -88,26 +88,30 @@ program
.command('serve')
.alias('s')
.description('create http server for abe')
.action(function(dest, options){
.option('-p, --port [number]', 'change port of the web server')
.option('-i, --interactive', 'open browser on web server startup')
.action(function(options){
var dir = process.cwd()
if(process.env.ROOT) {
dir = process.env.ROOT
}
var environment = process.env
environment.ROOT = dir
if (typeof port !== 'undefined' && port !== null) {
environment.PORT = port
if(options.port != null) {
environment.PORT = options.port
}
var command
if (__dirname.indexOf('dist') > -1) {
command = 'node --harmony ./dist/server/index.js'
}else {
command = path.join(__dirname, '..', 'node_modules', '.bin', 'babel-node') + ' --harmony ./src/server/index.js'
}

if(options.interactive != null) {
command = 'OPENURL=1 ' + command
}
process.chdir(__dirname + '/../')
console.log('website started : ' + dir)
var cp = exec(command,{}, function (err, out, code) {
var cp = exec(command,{env: environment}, function (err, out, code) {
if (err instanceof Error) throw err
process.stderr.write(err)
process.stdout.write(out)
Expand Down
2 changes: 1 addition & 1 deletion src/server/views/partials/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="panel panel-default">
<div class="panel-heading">
<h1>
<small class="accor-manager-header-title">Abe</small>
<small class="manager-header-title">Abe</small>
</h1>
</div>
<div class="panel-body">
Expand Down
1 change: 1 addition & 0 deletions tests/demo
Submodule demo added at a4f23d
47 changes: 47 additions & 0 deletions tests/functional/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
describe('Abe', function() {

describe('operations', function() {

before(function(client, done) {
done();
});

after(function(client, done) {
client.end(function() {
done();
});
});

afterEach(function(client, done) {
done();
});

beforeEach(function(client, done) {
done();
});

it('Create a single article', function(client) {
client
.url('http://localhost:3003/abe/editor')
.waitForElementVisible('body')
.assert.title('Abe')
.click('select[id="level-1"] option:nth-child(2)')
.click('select[name="selectTemplate"] option[value="single"]')
.waitForElementVisible('div[data-precontrib-templates=single]', 1000)
.setValue('div[data-precontrib-templates=single] > div > input', 'ftest')
.click('button[type="submit"]')
.waitForElementVisible('form[id="abeForm"]', 2000)
.assert.urlEquals("http://localhost:3003/abe/editor/articles/ftest.html", "Clicked URL Matches with URL of the New Window")
.end();
});

it('The created single article is found in the manager', function(client) {
client
.useXpath()
.url('http://localhost:3003/abe/editor')
.waitForElementVisible('//body')
.assert.containsText("//table[@id='navigation-list']/tbody/tr[1]/td[2]/a", "/articles/ftest.html")
.end();
});
});
});
11 changes: 11 additions & 0 deletions tests/intern.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define({
capabilities: {
'browserstack.selenium_version': '2.45.0'
},
environments: [{ browserName: 'chrome' }],
maxConcurrency: 2,
tunnel: 'NullTunnel',
suites: [],
functionalSuites: [ 'tests/functional/index' ],
excludeInstrumentation: /^(?:tests|test|node_modules)\//
});

0 comments on commit 7877387

Please sign in to comment.