Browse Source

first attempt to write dynamic tests

gemini
Alexander Wunschik 7 years ago
parent
commit
70a1261e01
5 changed files with 125 additions and 1 deletions
  1. +33
    -1
      gulpfile.js
  2. +2
    -0
      package.json
  3. +30
    -0
      test/gemini/tests/dynamic/dynamic.gemini.js
  4. +22
    -0
      test/gemini/tests/dynamic/dynamic.tmpl.html
  5. +38
    -0
      test/gemini/tests/dynamic/noOptions.test.json

+ 33
- 1
gulpfile.js View File

@ -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();
}
});

+ 2
- 0
package.json View File

@ -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",

+ 30
- 0
test/gemini/tests/dynamic/dynamic.gemini.js View File

@ -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');
*/
});

+ 22
- 0
test/gemini/tests/dynamic/dynamic.tmpl.html View File

@ -0,0 +1,22 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Timeline | <%- name %></title>
<script src="/dist/vis.js"></script>
<link href="/dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#timeline {
width: 1024px;
}
</style>
</head>
<body>
<div id="timeline" class="gemini-test-timeline"></div>
<script type="text/javascript">
var container = document.getElementById('timeline');
var items = new vis.DataSet(<%- JSON.stringify(data) %>);
var options = <%- JSON.stringify(options) %>;
var timeline = new vis.Timeline(container, items, options);
</script>
</body>
</html>

+ 38
- 0
test/gemini/tests/dynamic/noOptions.test.json View File

@ -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": {}
}

Loading…
Cancel
Save