diff options
author | Peter 'Pita' Martischka <petermartischka@googlemail.com> | 2012-11-13 07:29:57 -0800 |
---|---|---|
committer | Peter 'Pita' Martischka <petermartischka@googlemail.com> | 2012-11-13 07:29:57 -0800 |
commit | 4c095202bdee57cb3720333fc2699a8e92fc087f (patch) | |
tree | 4349bbc37ecc6c1e53c7c7cf59671c29672d291d /src/node | |
parent | b28afe4c4704427f23c3daf8e72cae7a185ed49f (diff) | |
parent | 03d3cd9f2495dbfa6f33e53766f16107de851976 (diff) | |
download | etherpad-lite-4c095202bdee57cb3720333fc2699a8e92fc087f.zip |
Merged branch feature/frontend-tests
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/hooks/express/tests.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js new file mode 100644 index 00000000..7921da5a --- /dev/null +++ b/src/node/hooks/express/tests.js @@ -0,0 +1,46 @@ +var path = require("path"); +var fs = require("fs"); + +exports.expressCreateServer = function (hook_name, args, cb) { + args.app.get('/tests/frontend/specs_list.js', function(req, res){ + fs.readdir('tests/frontend/specs', function(err, files){ + if(err){ return res.send(500); } + + res.send("var specs_list = " + JSON.stringify(files.sort()) + ";\n"); + }); + }); + + var url2FilePath = function(url){ + var subPath = url.substr("/tests/frontend".length); + if (subPath == ""){ + subPath = "index.html" + } + subPath = subPath.split("?")[0]; + + var filePath = path.normalize(__dirname + "/../../../../tests/frontend/") + filePath += subPath.replace("..", ""); + return filePath; + } + + args.app.get('/tests/frontend/specs/*', function (req, res) { + var specFilePath = url2FilePath(req.url); + var specFileName = path.basename(specFilePath); + + fs.readFile(specFilePath, function(err, content){ + if(err){ return res.send(500); } + + content = "describe(" + JSON.stringify(specFileName) + ", function(){ " + content + " });"; + + res.send(content); + }); + }); + + args.app.get('/tests/frontend/*', function (req, res) { + var filePath = url2FilePath(req.url); + res.sendfile(filePath); + }); + + args.app.get('/tests/frontend', function (req, res) { + res.redirect('/tests/frontend/'); + }); +}
\ No newline at end of file |