diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d8d66e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +npm-debug.log +.grunt diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2261467 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: node_js +node_js: + - "0.8" +before_install: + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" + - sleep 3 # give xvfb some time to start + - "wget http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar" + - "java -jar selenium-server-standalone-2.31.0.jar &" + - sleep 3 # give some time to bind to sockets, etc +before_script: + - npm install -g grunt-cli + - npm install grunt grunt-contrib-jshint grunt-contrib-uglify grunt-webdriver grunt-contrib-connect +script: grunt -v diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..7f7f73d --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,61 @@ +module.exports = function(grunt) { + grunt.initConfig({ + + connect: { + server: { + options: { + port: 9001, + base: '.' + } + } + }, + + webdriver: { + pathjs: { + options: { + logLevel: 'silent', + browser: 'firefox', + binary: null + }, + url: 'http://localhost:9001/tests/path.js.test.html', + tests: ['./tests/spec/pathjsSpec.js'] + }, + pathjs_min: { + options: { + logLevel: 'silent', + browser: 'firefox', + binary: null + }, + url: 'http://localhost:9001/tests/path.min.js.test.html', + tests: ['./tests/spec/pathjsSpec.js'] + } + }, + + uglify: { + my_target: { + files: { + 'path.min.js': ['path.js'] + } + } + }, + + jshint: { + options: { + "globals": { + "exports": true, + "buster": true + } + }, + all: ['Gruntfile.js', 'path.js', 'tests/spec/**/*.js'] + } + + }); + + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-connect'); + grunt.loadNpmTasks('grunt-webdriver'); + + grunt.registerTask('default', ['jshint', 'uglify', 'connect', 'webdriver']); + +}; diff --git a/path.js b/path.js index d56a2d8..66e6a7a 100644 --- a/path.js +++ b/path.js @@ -41,7 +41,7 @@ var Path = { window.onpopstate = Path.history.popState; } else { if(Path.history.fallback){ - for(route in Path.routes.defined){ + for( var route in Path.routes.defined){ if(route.charAt(0) != "#"){ Path.routes.defined["#"+route] = Path.routes.defined[route]; Path.routes.defined["#"+route].path = "#"+route; @@ -105,7 +105,7 @@ var Path = { } }, 'listen': function () { - var fn = function(){ Path.dispatch(location.hash); } + var fn = function(){ Path.dispatch(location.hash); }; if (location.hash === "") { if (Path.routes.root !== null) { @@ -162,7 +162,7 @@ Path.core.route.prototype = { }, 'partition': function () { var parts = [], options = [], re = /\(([^}]+?)\)/g, text, i; - while (text = re.exec(this.path)) { + while( !!(text = re.exec(this.path)) ) { parts.push(text[1]); } options.push(this.path.split("(")[0]); diff --git a/tests/path.js.test.html b/tests/path.js.test.html index 9d870fa..0f11936 100644 --- a/tests/path.js.test.html +++ b/tests/path.js.test.html @@ -4,144 +4,101 @@
- Path.js uses a very straightforward method of testing. We manually construct + Path.js uses a very straightforward method of testing. We manually construct a series of method calls that the library should execute under normal working conditions. We then use JavaScript to simulate the URL changes, and compare the final result with what the result should actually be. If the end result @@ -149,7 +106,7 @@
| Token | Reason |
| Token | Reason |
| F[enter] | Enter method of F, as it is root |
| F[action] | True action of F, as it is root |
| A[enter] | Enter method of A, as it is looped |
| H(one=N/A, two=N/A) | Optional parameters with only the require part submitted |
| H(one=10, two=N/A) | Optional parameters with one optional part submitted |
| H(one=10, two=20) | Optional parameters two levels deep |
| H(one=10, two=N/A) | Testing "back" functionality |
| H(one=10, two=N/A) | Testing "back" functionality |