Skip to content

Commit

Permalink
add HTML files server
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioCrisostomo committed Feb 11, 2015
1 parent a1df0eb commit 915eb47
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
"use strict";
var fs = require('fs');
var path = require('path');
var http = require('http');
var build = (function(){
// travis testing
if (process.env && process.env.BUILD) return process.env.BUILD == 'default' ? 'all' : 'nocompat';
// local testing
else return process.argv[2] == null || process.argv[2] == 'all' ? 'all' : 'nocompat';
})();
require('./Tests/httpServer.js')(build);

module.exports = function(grunt) {

Expand Down
10 changes: 9 additions & 1 deletion Tests/gruntfile-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ var karmaOptions = {
captureTimeout: 60000 * 2,
singleRun: true,
frameworks: ['jasmine', 'sinon'],
files: ['Tests/Utilities/*.js', 'mootools-*.js'],
files: [
'Tests/Utilities/*.js',
'mootools-*.js',
{pattern: 'Source/**/*.*', included: false, served: true},
{pattern: 'Tests/**/*.*', included: false, served: true}
],
proxies: {
'/specsserver/': 'http://localhost:9000/'
},
sauceLabs: {
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY,
Expand Down
27 changes: 27 additions & 0 deletions Tests/httpServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";

var fs = require('fs');
var path = require('path');
var http = require('http');
var assets = require('./assets.js');

function getQuery(path){
var match = path.match(/=(\w+)/);
return match ? match[1] : null;
}

module.exports = function(build) {
http.createServer(function(req, res){

var src = '/base/mootools-' + build;
var customFunction = getQuery(req.url);

if (customFunction) return assets[customFunction].call(null, req, res, src);
var filePath = path.join(__dirname, req.url);
fs.readFile(filePath, 'utf-8', function (err, content) {
if (err) return console.log(err);
content = content.replace('mootoolsPath', src);
res.end(content);
});
}).listen(9000);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"karma-firefox-launcher": "~0.1.3",
"karma-ie-launcher": "~0.1",
"karma-safari-launcher": "~0.1",
"path": "^0.11.14",
"js-yaml": "^3.0.2"
}
}

0 comments on commit 915eb47

Please sign in to comment.