Parcourir la source

initial tests

Girish Ramakrishnan il y a 8 ans
Parent
commit
93db1f454b
3 fichiers modifiés avec 135 ajouts et 1 suppressions
  1. 1 1
      README.md
  2. 21 0
      test/package.json
  3. 113 0
      test/test.js

+ 1 - 1
README.md

@@ -31,7 +31,7 @@ The e2e tests are located in the `test/` folder and require [nodejs](http://node
 cd nodebb-app/test
 
 npm install
-USERNAME=<cloudron username> PASSWORD=<cloudron password> mocha --bail test.js
+mocha --bail test.js
 ```
 
 ## Debugging

+ 21 - 0
test/package.json

@@ -0,0 +1,21 @@
+{
+  "name": "test",
+  "version": "1.0.0",
+  "description": "",
+  "main": "test.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "devDependencies": {
+    "ejs": "^2.3.4",
+    "expect.js": "^0.3.1",
+    "mkdirp": "^0.5.1",
+    "mocha": "^2.3.4",
+    "rimraf": "^2.4.4",
+    "selenium-server-standalone-jar": "^2.53.0",
+    "selenium-webdriver": "^2.53.3",
+    "superagent": "^1.4.0"
+  }
+}

+ 113 - 0
test/test.js

@@ -0,0 +1,113 @@
+#!/usr/bin/env node
+
+'use strict';
+
+var execSync = require('child_process').execSync,
+    expect = require('expect.js'),
+    path = require('path'),
+    superagent = require('superagent'),
+    webdriver = require('selenium-webdriver');
+
+var by = webdriver.By,
+    Keys = webdriver.Key,
+    until = webdriver.until;
+
+process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
+
+describe('Application life cycle test', function () {
+    this.timeout(0);
+
+    var chrome = require('selenium-webdriver/chrome');
+    var server, browser = new chrome.Driver(), uploadedImageUrl;
+    var username = 'admin', password = 'changeme';
+
+    before(function (done) {
+        var seleniumJar= require('selenium-server-standalone-jar');
+        var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
+        server = new SeleniumServer(seleniumJar.path, { port: 4444 });
+        server.start();
+
+        done();
+    });
+
+    after(function (done) {
+        browser.quit();
+        server.stop();
+        done();
+    });
+
+    var LOCATION = 'nodebbtest';
+    var TEST_TIMEOUT = parseInt(process.env.TEST_TIMEOUT, 10) || 5000;
+    var app;
+    var email, token;
+
+    function login(done) {
+        browser.manage().deleteAllCookies();
+        browser.get('https://' + app.fqdn + '/login');
+        browser.executeScript('localStorage.clear();')
+
+        browser.get('https://' + app.fqdn + '/login');
+        browser.wait(until.elementLocated(by.id('username')), TEST_TIMEOUT).then(function () {
+            browser.findElement(by.id('username')).sendKeys(username);
+            browser.findElement(by.id('password')).sendKeys(password);
+            browser.findElement(by.id('login')).click();
+            browser.wait(until.elementLocated(by.xpath('//a[contains(text(), "Announcements")]')), TEST_TIMEOUT).then(function () { done(); });
+        });
+    }
+
+    xit('build app', function () {
+        execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('install app', function () {
+        execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('can get app information', function () {
+        var inspect = JSON.parse(execSync('cloudron inspect'));
+
+        app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
+
+        expect(app).to.be.an('object');
+    });
+
+    it('can login', function (done) {
+        login(done);
+    });
+
+    it('backup app', function () {
+        execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('restore app', function () {
+        execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+
+    it('can login', function (done) {
+        login(done);
+    });
+
+    it('can restart app', function (done) {
+        execSync('cloudron restart');
+        done();
+    });
+
+    it('can login', function (done) {
+        login(done);
+    });
+
+    it('move to different location', function () {
+        execSync('cloudron install --wait --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+        var inspect = JSON.parse(execSync('cloudron inspect'));
+        app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
+        expect(app).to.be.an('object');
+    });
+
+    it('can login', function (done) {
+        login(done);
+    });
+
+    it('uninstall app', function () {
+        execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+    });
+});