From 909c26cb609643ed46e2330e37a12c4021e5578a Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Wed, 22 May 2013 23:40:02 -0300 Subject: [PATCH 01/13] Fix identation --- tests/path.js.test.html | 118 ++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/tests/path.js.test.html b/tests/path.js.test.html index 9d870fa..def3b72 100644 --- a/tests/path.js.test.html +++ b/tests/path.js.test.html @@ -5,143 +5,143 @@ -
-

Test Suite

+
+

Test Suite

- 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 +149,7 @@

Test Suite

is not suitable for use. The expected test results are as follows:

- + @@ -176,12 +176,12 @@

Test Suite

- +
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


-

Expected

-
F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)::H(one=10, two=N/A)
+

Expected

+
F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)::H(one=10, two=N/A)

Actual

Grade

From 5d25cdb0b2285d6364e0d0c2fa432014a9913131 Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Thu, 23 May 2013 02:06:56 -0300 Subject: [PATCH 02/13] Clear tests/path.js.test.html --- tests/path.js.test.html | 46 +---------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/tests/path.js.test.html b/tests/path.js.test.html index def3b72..f3fbb7c 100644 --- a/tests/path.js.test.html +++ b/tests/path.js.test.html @@ -4,21 +4,6 @@ PathJS Test @@ -180,12 +140,8 @@

Test Suite



-

Expected

-
F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)::H(one=10, two=N/A)

Actual

-

Grade

-
From c6477e85d16e45c2ed9c955d5cdbff36b0714ae7 Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Thu, 23 May 2013 02:09:11 -0300 Subject: [PATCH 03/13] Ignore some files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore 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 From 266173333f500688b5cf6b1a16d6b08d0fff7b86 Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Thu, 23 May 2013 02:17:55 -0300 Subject: [PATCH 04/13] Add grunt file --- Gruntfile.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Gruntfile.js diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..188ca64 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,52 @@ +module.exports = function(grunt) { + grunt.initConfig({ + + connect: { + server: { + options: { + port: 9001, + base: '.' + } + } + }, + + webdriver: { + dev: { + options: { + logLevel: 'silent', + browser: 'firefox', + binary: null + }, + url: 'http://localhost:9001/tests/path.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']); + +}; From 58a7eeeb83124650789811c77cf813013afc7423 Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Thu, 23 May 2013 02:10:05 -0300 Subject: [PATCH 05/13] Add travis configuration file --- .travis.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .travis.yml 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 From c36e01069d26d0bfa3dbd8295d04cb2da4871f74 Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Thu, 23 May 2013 02:18:26 -0300 Subject: [PATCH 06/13] Fix some jshint warnings --- path.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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]); From d053988fd1f02f85b2753c323ee84a6261b36f1a Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Thu, 23 May 2013 02:19:49 -0300 Subject: [PATCH 07/13] Add a sample test --- tests/spec/pathjsSpec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/spec/pathjsSpec.js diff --git a/tests/spec/pathjsSpec.js b/tests/spec/pathjsSpec.js new file mode 100644 index 0000000..9e89765 --- /dev/null +++ b/tests/spec/pathjsSpec.js @@ -0,0 +1,26 @@ +var assertions = buster.assertions, + assert = assertions.assert, + refute = assertions.refute, + host = "http://localhost:9001/tests/path.js.test.html", + selector_console = "div#actual"; + +exports.name = "Simple Test"; +exports.tests = [ + { + name: "checks the following routes: root -> #A", + func: function(done) { + exports.driver + .getTitle(function(error, title) { + assert.equals( title, 'PathJS Test' ); + }) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]' ); + }) + .url( host+"#A" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]' ); + }) + .end(done); + } + } +]; From 1a5b790a2bd44a830bf3ac5611dece44c3bbe454 Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Thu, 23 May 2013 03:39:53 -0300 Subject: [PATCH 08/13] Improve test --- tests/spec/pathjsSpec.js | 50 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/spec/pathjsSpec.js b/tests/spec/pathjsSpec.js index 9e89765..7d02bc2 100644 --- a/tests/spec/pathjsSpec.js +++ b/tests/spec/pathjsSpec.js @@ -7,7 +7,7 @@ var assertions = buster.assertions, exports.name = "Simple Test"; exports.tests = [ { - name: "checks the following routes: root -> #A", + name: "checks the following routes: root -> #A -> #B -> #C -> #D1 -> #D2 -> #E/params/1/parse -> #E/params/2/parse -> #E/params/3/check -> #F -> #G -> #H -> #H/10 -> #H/10/20", func: function(done) { exports.driver .getTitle(function(error, title) { @@ -20,6 +20,54 @@ exports.tests = [ .getText(selector_console, function(error, text){ assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]' ); }) + .url( host+"#B" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]' ); + }) + .url( host+"#C" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]' ); + }) + .url( host+"#D1" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE' ); + }) + .url( host+"#D2" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE' ); + }) + .url( host+"#E/params/1/parse" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)' ); + }) + .url( host+"#E/params/2/parse" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)' ); + }) + .url( host+"#E/params/3/check" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)' ); + }) + .url( host+"#F" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]' ); + }) + .url( host+"#G" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]' ); + }) + .url( host+"#H" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)' ); + }) + .url( host+"#H/10" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)' ); + }) + .url( host+"#H/10/20" ) + .getText(selector_console, function(error, text){ + assert.equals( text, 'F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)' ); + }) .end(done); } } From 348ff7c06b3db56b6b8c047f364e868dd212d2f1 Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Thu, 23 May 2013 03:44:32 -0300 Subject: [PATCH 09/13] Fix identation and clean the html --- tests/path.min.js.test.html | 199 ++++++++++++++---------------------- 1 file changed, 78 insertions(+), 121 deletions(-) diff --git a/tests/path.min.js.test.html b/tests/path.min.js.test.html index bdcb2e1..40aad89 100644 --- a/tests/path.min.js.test.html +++ b/tests/path.min.js.test.html @@ -4,184 +4,141 @@ PathJS Test -
-

Test Suite

-

- 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 - is anything but perfect, the test is a failure, and this version of Path.JS - is not suitable for use. The expected test results are as follows: -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
A[action] True action of A, as it is looped
A[exit] Exit method of A, as we move to next route
B[enter] Enter method of B, as it is looped
B[action] True action of B, as it is looped
C[action] True action of C
C[exit] Exit method of C, as we move to next route
RESCUE Rescue a route that wasn't found (D1)
RESCUE Rescue a route that wasn't found (D2)
E[enter](parse) Enter method of a param parsed route
E[action](parse id=1) True action of the route, with param of id=1
E[enter](parse) Enter method of the same route again
E[action](parse id=2) True action of the route, with param of id=2
E[action](check id=3) True action of the next route, with param id=3
E[exit](check) Exit method of parameterized route
F[enter] Enter method of F again, our final route
F[action] True action of F, our final route
G[enter 1] First enter method of G
G[enter 2] Second enter method of G
G[enter 3] Third enter method of G
G[enter 4] Last enter method of G - Returns false, stops execution
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
+
+

Test Suite

+

+ 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 + is anything but perfect, the test is a failure, and this version of Path.JS + is not suitable for use. The expected test results are as follows: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
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
A[action] True action of A, as it is looped
A[exit] Exit method of A, as we move to next route
B[enter] Enter method of B, as it is looped
B[action] True action of B, as it is looped
C[action] True action of C
C[exit] Exit method of C, as we move to next route
RESCUE Rescue a route that wasn't found (D1)
RESCUE Rescue a route that wasn't found (D2)
E[enter](parse) Enter method of a param parsed route
E[action](parse id=1) True action of the route, with param of id=1
E[enter](parse) Enter method of the same route again
E[action](parse id=2) True action of the route, with param of id=2
E[action](check id=3) True action of the next route, with param id=3
E[exit](check) Exit method of parameterized route
F[enter] Enter method of F again, our final route
F[action] True action of F, our final route
G[enter 1] First enter method of G
G[enter 2] Second enter method of G
G[enter 3] Third enter method of G
G[enter 4] Last enter method of G - Returns false, stops execution
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


-

Expected

-
F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse)::E[action](parse id=1)::E[enter](parse)::E[action](parse id=2)::E[action](check id=3)::E[exit](check)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)::H(one=10, two=N/A)
+

Expected

+
F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse)::E[action](parse id=1)::E[enter](parse)::E[action](parse id=2)::E[action](check id=3)::E[exit](check)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)::H(one=10, two=N/A)

Actual

Grade

From 3afa645d7c6ed1717b15b130f98554be0acf78af Mon Sep 17 00:00:00 2001 From: Igor Lima Date: Thu, 23 May 2013 03:45:02 -0300 Subject: [PATCH 10/13] Remove variables unusable --- tests/path.js.test.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/path.js.test.html b/tests/path.js.test.html index f3fbb7c..e2fc6dd 100644 --- a/tests/path.js.test.html +++ b/tests/path.js.test.html @@ -4,8 +4,6 @@ PathJS Test