From 70a1261e012fd56cfd7ae710ef4758135feaab1d Mon Sep 17 00:00:00 2001 From: Alexander Wunschik Date: Sat, 1 Jul 2017 16:25:37 +0200 Subject: [PATCH] first attempt to write dynamic tests --- gulpfile.js | 34 ++++++++++++++++- package.json | 2 + test/gemini/tests/dynamic/dynamic.gemini.js | 30 +++++++++++++++ test/gemini/tests/dynamic/dynamic.tmpl.html | 22 +++++++++++ test/gemini/tests/dynamic/noOptions.test.json | 38 +++++++++++++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 test/gemini/tests/dynamic/dynamic.gemini.js create mode 100644 test/gemini/tests/dynamic/dynamic.tmpl.html create mode 100644 test/gemini/tests/dynamic/noOptions.test.json diff --git a/gulpfile.js b/gulpfile.js index dc1b2700..8b1217d0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,6 +13,7 @@ var opn = require('opn'); var exec = require('child_process').exec; var spawn = require('child_process').spawn; var webserver = require('gulp-webserver'); +var ejs = require('ejs'); var geminiConfig = require('./test/gemini/gemini.config.js'); var ENTRY = './index.js'; @@ -122,7 +123,37 @@ function startDevWebserver(options, cb) { var opt = options || {}; return gulp.src('./').pipe(webserver(Object.assign(opt, { path: '/', - port: geminiConfig.webserver.port + port: geminiConfig.webserver.port, + middleware: function(req, res, next) { + var dynamicTestBase = '/test/gemini/tests/dynamic/'; + var url = req.url; + if (url.startsWith(dynamicTestBase)) { + // get testcase from url + var testName = url.split(dynamicTestBase)[1]; + + // if testcase exists open settings + var testConfig = require('.' + req.url + '.test'); + testConfig.name = testName; + + // render and send + var templateFile = '.' + dynamicTestBase + 'dynamic.tmpl.html'; + ejs.renderFile(templateFile, testConfig, {}, function(err, html){ + if (err) { + res.statusCode = 500; + res.write('error rendering "'+ templateFile + '" (' + err + ')'); + res.end(); + return err; + } + res.writeHead(200, { + 'Content-Length': Buffer.byteLength(html), + 'Content-Type': 'text/html; charset=utf-8' + }); + res.write(html); + res.end(); + }); + } + next(); + } }))); } @@ -205,6 +236,7 @@ function runGemini(mode, cb) { } else { // The tests returned no error. Kill the dev-webserver and exit server.emit('kill'); + gutil.log("Webbrowser stopped"); cb(); } }); diff --git a/package.json b/package.json index 4073c096..c01d4be3 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "scripts": { "gulp": "gulp", "test": "mocha --compilers js:babel-core/register", + "dev-server": "gulp webserver", "gemini-update": "gulp gemini-update", "gemini-test": "gulp gemini-test", "build": "gulp", @@ -52,6 +53,7 @@ "babel-runtime": "^6.22.0", "babelify": "^7.3.0", "clean-css": "^4.0.2", + "ejs": "^2.5.6", "eslint": "^3.15.0", "gemini": "^5.0.0-alpha.3", "gulp": "^3.9.1", diff --git a/test/gemini/tests/dynamic/dynamic.gemini.js b/test/gemini/tests/dynamic/dynamic.gemini.js new file mode 100644 index 00000000..e4ae41b8 --- /dev/null +++ b/test/gemini/tests/dynamic/dynamic.gemini.js @@ -0,0 +1,30 @@ +gemini.suite('timline', function(suite) { + var fs = require('fs'); + var path = require('path'); + var baseDir = '/test/gemini/tests/dynamic/'; + + var files = fs.readdirSync('.' + baseDir); + for (var i in files) { + var file = files[i]; + if(path.extname(file) === ".test.json") { + var name = file.split('.test.json')[0]; + + suite.setUrl(baseDir + '/' + name) + .before(function(actions) { + actions.wait(1000); + }) + .setCaptureElements('#timeline') + .capture(name); + + } + } + + /* + suite.setUrl('/test/gemini/tests/dynamic/noOptions') + .before(function(actions) { + actions.wait(1000); + }) + .setCaptureElements('#timeline') + .capture('noOptions'); + */ +}); diff --git a/test/gemini/tests/dynamic/dynamic.tmpl.html b/test/gemini/tests/dynamic/dynamic.tmpl.html new file mode 100644 index 00000000..a43fe87b --- /dev/null +++ b/test/gemini/tests/dynamic/dynamic.tmpl.html @@ -0,0 +1,22 @@ + + + + Timeline | <%- name %> + + + + + +
+ + + diff --git a/test/gemini/tests/dynamic/noOptions.test.json b/test/gemini/tests/dynamic/noOptions.test.json new file mode 100644 index 00000000..0424ba2a --- /dev/null +++ b/test/gemini/tests/dynamic/noOptions.test.json @@ -0,0 +1,38 @@ +{ + "data": [ + { + "content": "item 1", + "id": 1, + "start": "2014-04-20" + }, + { + "content": "item 2", + "id": 2, + "start": "2014-04-14" + }, + { + "content": "item 3", + "id": 3, + "start": "2014-04-18" + }, + { + "content": "item 4", + "end": "2014-04-19", + "id": 4, + "start": "2014-04-16" + }, + { + "content": "item 5", + "id": 5, + "start": "2014-04-25" + }, + { + "content": "item 6", + "id": 6, + "start": "2014-04-27", + "type": "point" + } + ], + + "options": {} +}