From 915eb47d4db3db3a9a72b574ac4491d4eaeb7131 Mon Sep 17 00:00:00 2001 From: SergioCrisostomo Date: Wed, 11 Feb 2015 11:49:16 +0100 Subject: [PATCH] add HTML files server --- Gruntfile.js | 10 ++++++++++ Tests/gruntfile-options.js | 10 +++++++++- Tests/httpServer.js | 27 +++++++++++++++++++++++++++ package.json | 1 + 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Tests/httpServer.js diff --git a/Gruntfile.js b/Gruntfile.js index 956113503..1870a3134 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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) { diff --git a/Tests/gruntfile-options.js b/Tests/gruntfile-options.js index 094a18383..74f0c6cc7 100644 --- a/Tests/gruntfile-options.js +++ b/Tests/gruntfile-options.js @@ -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, diff --git a/Tests/httpServer.js b/Tests/httpServer.js new file mode 100644 index 000000000..d775f5bf1 --- /dev/null +++ b/Tests/httpServer.js @@ -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); +} diff --git a/package.json b/package.json index 4e52722a8..02ddf2432 100644 --- a/package.json +++ b/package.json @@ -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" } }