From 824d713d0298304b928677584a8409b76a89b2b3 Mon Sep 17 00:00:00 2001 From: Randy Date: Mon, 4 Apr 2016 16:53:22 +0200 Subject: [PATCH 01/19] Add app test --- src/app/controller.js | 14 ++++++++++++++ src/app/index.html | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/app/controller.js create mode 100644 src/app/index.html diff --git a/src/app/controller.js b/src/app/controller.js new file mode 100644 index 0000000..657c9e6 --- /dev/null +++ b/src/app/controller.js @@ -0,0 +1,14 @@ +angular.module('wsScriptLoader') + .controller('wsScriptLoaderController', ['wsScriptLoader', function(wsScriptLoader) { + + var wsScriptLoaderCtrl = this; + + wsScriptLoaderCtrl.scriptName = ""; + + wsScriptLoaderCtrl.addScript = function() { + console.info('Inserting script...'); + wsScriptLoader.insertScriptTag('myScript', function() { + console.info("Error : script already added !"); + }); + }; + }]); diff --git a/src/app/index.html b/src/app/index.html new file mode 100644 index 0000000..ffa809f --- /dev/null +++ b/src/app/index.html @@ -0,0 +1,20 @@ + + + + + wsScriptLoader unit test + + + + + + + + +
+ +

+ +
+ + From 18043a5c900a0621bf9f3fdda0221ddc8b367649 Mon Sep 17 00:00:00 2001 From: Randy Date: Mon, 4 Apr 2016 18:01:04 +0200 Subject: [PATCH 02/19] Update karma configuration file --- karma-src.conf.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/karma-src.conf.js b/karma-src.conf.js index ec87981..f5ea9cc 100644 --- a/karma-src.conf.js +++ b/karma-src.conf.js @@ -10,7 +10,7 @@ module.exports = function(config) { // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['mocha', 'chai-jquery', 'jquery-1.8.3', 'sinon-chai'], + frameworks: ['mocha', 'chai-jquery', 'jquery-1.8.3', 'sinon-chai', 'jasmine'], plugins: [ 'karma-mocha', @@ -20,15 +20,16 @@ module.exports = function(config) { 'karma-phantomjs-launcher', 'karma-jquery', 'karma-chai-jquery', - 'karma-mocha-reporter' + 'karma-mocha-reporter', + 'karma-jasmine' ], // list of files / patterns to load in the browser files: [ 'bower/angular/angular.js', 'bower/angular-mocks/angular-mocks.js', - 'src/**/*.js', - 'test/unit/**/*.js' + 'dist/ws-script-loader.js', + 'test/*.js' ], From 687897def0885f0bdd39b49a8a2a07bba577db61 Mon Sep 17 00:00:00 2001 From: Randy Date: Mon, 4 Apr 2016 18:01:48 +0200 Subject: [PATCH 03/19] Work in progress --- src/app/controller.js | 6 ++--- src/app/index.html | 5 +++-- test/wsScriptLoaderSpec.js | 46 ++++++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/app/controller.js b/src/app/controller.js index 657c9e6..163512a 100644 --- a/src/app/controller.js +++ b/src/app/controller.js @@ -5,10 +5,10 @@ angular.module('wsScriptLoader') wsScriptLoaderCtrl.scriptName = ""; - wsScriptLoaderCtrl.addScript = function() { + wsScriptLoaderCtrl.addScript = function(scriptName) { console.info('Inserting script...'); - wsScriptLoader.insertScriptTag('myScript', function() { - console.info("Error : script already added !"); + wsScriptLoader.insertScriptTag(scriptName, function() { + console.error("Error : script already added !"); }); }; }]); diff --git a/src/app/index.html b/src/app/index.html index ffa809f..dc87894 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -13,8 +13,9 @@
-

- +
+
+
diff --git a/test/wsScriptLoaderSpec.js b/test/wsScriptLoaderSpec.js index c513661..fc60c68 100755 --- a/test/wsScriptLoaderSpec.js +++ b/test/wsScriptLoaderSpec.js @@ -1,29 +1,57 @@ 'use strict'; -describe('', function() { +describe('wsScriptLoaderService test', function() { - var module; + var wsScriptLoader; var dependencies; dependencies = []; + var $scope, wsScriptLoaderService, mock; var hasModule = function(module) { - return dependencies.indexOf(module) >= 0; + return dependencies.indexOf(module) >= 0; }; beforeEach(function() { // Get module - module = angular.module('wsScriptLoader'); - dependencies = module.requires; + wsScriptLoader = angular.module('wsScriptLoader'); + dependencies = wsScriptLoader.requires; + }); + + beforeEach(function() { + mock = {alert: jasmine.createSpy()}; + module(function($provide) { + $provide.value('wsScriptLoader', mock); + }); + + inject(function($injector) { + wsScriptLoaderService = $injector.get('wsScriptLoader'); + }); }); it('should load module', function() { expect(hasModule('wsScriptLoader')).to.be.ok; }); - + /*** CHECK IF METHODS ARE DEFINED ***/ + + it('should have insertScriptTag defined', function() { + // expect(wsScriptLoaderService.insertScriptTag).toBeDefined(); + }); + + it('should have loadScriptTag defined', function() { + // expect(wsScriptLoaderService.loadScriptTag).toBeDefined(); + }); + + /*** CHECK IF METHODS WORK WELL ***/ + + // For insertScriptTag - + it('method insertScriptTag should add script node into body', function() { + // console.log(angular.element(document).find('script')); + }); + + it('method insertScriptTag should add script node into body', function() { - + }); -}); \ No newline at end of file +}); From 72a741ea74a8890bc32dff032788bbb16ccfe9f8 Mon Sep 17 00:00:00 2001 From: Randy Date: Tue, 5 Apr 2016 14:52:30 +0200 Subject: [PATCH 04/19] Change karma.con file --- karma-src.conf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/karma-src.conf.js b/karma-src.conf.js index f5ea9cc..a0fa5a5 100644 --- a/karma-src.conf.js +++ b/karma-src.conf.js @@ -10,7 +10,7 @@ module.exports = function(config) { // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['mocha', 'chai-jquery', 'jquery-1.8.3', 'sinon-chai', 'jasmine'], + frameworks: ['jasmine', 'chai-jquery', 'jquery-1.8.3', 'sinon-chai', 'mocha'], plugins: [ 'karma-mocha', @@ -29,7 +29,7 @@ module.exports = function(config) { 'bower/angular/angular.js', 'bower/angular-mocks/angular-mocks.js', 'dist/ws-script-loader.js', - 'test/*.js' + 'test/*.js', ], From fe3c38671ae6c29594f1ca565cd42a64357b5e2d Mon Sep 17 00:00:00 2001 From: Randy Date: Tue, 5 Apr 2016 19:20:51 +0200 Subject: [PATCH 05/19] Work in progress --- test/wsScriptLoaderSpec.js | 67 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/test/wsScriptLoaderSpec.js b/test/wsScriptLoaderSpec.js index fc60c68..3dd53cf 100755 --- a/test/wsScriptLoaderSpec.js +++ b/test/wsScriptLoaderSpec.js @@ -3,55 +3,70 @@ describe('wsScriptLoaderService test', function() { var wsScriptLoader; - var dependencies; - dependencies = []; - var $scope, wsScriptLoaderService, mock; + var dependencies = []; + var wsScriptLoaderService; var hasModule = function(module) { return dependencies.indexOf(module) >= 0; }; - beforeEach(function() { - // Get module - wsScriptLoader = angular.module('wsScriptLoader'); - dependencies = wsScriptLoader.requires; - }); - - beforeEach(function() { - mock = {alert: jasmine.createSpy()}; - module(function($provide) { - $provide.value('wsScriptLoader', mock); - }); + beforeEach(module('wsScriptLoader')); - inject(function($injector) { - wsScriptLoaderService = $injector.get('wsScriptLoader'); - }); - }); + beforeEach(inject(function($injector) { + wsScriptLoaderService = $injector.get('wsScriptLoader'); + })); it('should load module', function() { - expect(hasModule('wsScriptLoader')).to.be.ok; + dependencies = angular.module('wsScriptLoader').requires; + expect(hasModule('wsScriptLoader')).toBeTruthy(); }); /*** CHECK IF METHODS ARE DEFINED ***/ - it('should have insertScriptTag defined', function() { - // expect(wsScriptLoaderService.insertScriptTag).toBeDefined(); + it('insertScriptTag should be defined', function() { + expect(wsScriptLoaderService.insertScriptTag).toBeDefined(); }); - it('should have loadScriptTag defined', function() { - // expect(wsScriptLoaderService.loadScriptTag).toBeDefined(); + it('loadScriptTag should be defined', function() { + expect(wsScriptLoaderService.loadScriptTag).toBeDefined(); }); /*** CHECK IF METHODS WORK WELL ***/ // For insertScriptTag - it('method insertScriptTag should add script node into body', function() { - // console.log(angular.element(document).find('script')); + it('method insertScriptTag should execute the callback when script have already been added !', function() { + + // object created to use spies functionality + var data = { + scriptName: 'myScript', + callback: function() { + console.error('Script added !'); + } + }; + spyOn(data, 'callback'); // crate a spy to notice if the callback have been called + // First call + wsScriptLoaderService.insertScriptTag(data.scriptName, data.callback); + // Second call + wsScriptLoaderService.insertScriptTag(data.scriptName, data.callback); + + expect(data.callback).toHaveBeenCalled(); // suppose to be true }); - it('method insertScriptTag should add script node into body', function() { + // For loadScriptTag + + it('method insertScriptTag should the promise when script have already been added !', function() { + + var success = function(success) { + console.info('Success !'); + }; + + var error = function(error) { + console.error('Error !'); + }; + var scriptName = 'myScript'; + wsScriptLoaderService.loadScriptTag(scriptName).then(success, error); }); }); From 0b0736c746a7b6323b3a6fc37bf47a9e7ff2cf69 Mon Sep 17 00:00:00 2001 From: Randy Date: Wed, 6 Apr 2016 12:34:20 +0200 Subject: [PATCH 06/19] Update template example --- src/app/controller.js | 13 +++++-------- src/app/index.html | 1 - 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/app/controller.js b/src/app/controller.js index 163512a..d97bd21 100644 --- a/src/app/controller.js +++ b/src/app/controller.js @@ -1,14 +1,11 @@ angular.module('wsScriptLoader') .controller('wsScriptLoaderController', ['wsScriptLoader', function(wsScriptLoader) { - var wsScriptLoaderCtrl = this; + var wsScriptLoaderCtrl = this; - wsScriptLoaderCtrl.scriptName = ""; + wsScriptLoaderCtrl.scriptName = ""; - wsScriptLoaderCtrl.addScript = function(scriptName) { - console.info('Inserting script...'); - wsScriptLoader.insertScriptTag(scriptName, function() { - console.error("Error : script already added !"); - }); - }; + wsScriptLoaderCtrl.addScript = function(scriptName) { + wsScriptLoader.loadScriptTag(scriptName); + }; }]); diff --git a/src/app/index.html b/src/app/index.html index dc87894..50f8006 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -5,7 +5,6 @@ wsScriptLoader unit test - From 8272b6b619210b18e3e6f242e434850e9cca638f Mon Sep 17 00:00:00 2001 From: Randy Date: Wed, 6 Apr 2016 12:34:52 +0200 Subject: [PATCH 07/19] Update karma.conf file --- karma-src.conf.js | 1 + 1 file changed, 1 insertion(+) diff --git a/karma-src.conf.js b/karma-src.conf.js index a0fa5a5..66e0da1 100644 --- a/karma-src.conf.js +++ b/karma-src.conf.js @@ -29,6 +29,7 @@ module.exports = function(config) { 'bower/angular/angular.js', 'bower/angular-mocks/angular-mocks.js', 'dist/ws-script-loader.js', + 'src/app/controller.js', 'test/*.js', ], From 674d54726292d4cd25308c0e2d316f9d1b1fe24d Mon Sep 17 00:00:00 2001 From: Randy Date: Wed, 6 Apr 2016 12:35:15 +0200 Subject: [PATCH 08/19] Add script test --- src/app/myScript.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/app/myScript.js diff --git a/src/app/myScript.js b/src/app/myScript.js new file mode 100644 index 0000000..375dc12 --- /dev/null +++ b/src/app/myScript.js @@ -0,0 +1 @@ +var test = 3; From 63a3e62a36664b2f1d64a37079e15bc0d4c9cc48 Mon Sep 17 00:00:00 2001 From: Randy Date: Wed, 6 Apr 2016 12:35:23 +0200 Subject: [PATCH 09/19] Update test specs --- dist/ws-script-loader.js | 9 ++++--- test/wsScriptLoaderSpec.js | 55 ++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/dist/ws-script-loader.js b/dist/ws-script-loader.js index 1caffc6..bc683e5 100755 --- a/dist/ws-script-loader.js +++ b/dist/ws-script-loader.js @@ -1,7 +1,7 @@ (function() { -angular.module('wsScriptLoader', []) +angular.module('wsScriptLoader', ['wsScriptLoader']) .service('wsScriptLoader', ["$q", function($q) { var service = this; @@ -21,6 +21,7 @@ angular.module('wsScriptLoader', []) document.body.appendChild(tag); loadedScripts.push(tagUrl); + return tag; } else { @@ -36,11 +37,11 @@ angular.module('wsScriptLoader', []) service.loadScriptTag = function (tagUrl) { var deferred = $q.defer(); - service.insertScriptTag(tagUrl, function () { + return service.insertScriptTag(tagUrl, function () { deferred.resolve(); }); return deferred.promise; - }; + }; }]); -}()); \ No newline at end of file +}()); diff --git a/test/wsScriptLoaderSpec.js b/test/wsScriptLoaderSpec.js index 3dd53cf..4e7368a 100755 --- a/test/wsScriptLoaderSpec.js +++ b/test/wsScriptLoaderSpec.js @@ -35,6 +35,44 @@ describe('wsScriptLoaderService test', function() { // For insertScriptTag + it('method insertScriptTag should add script into the DOM', function() { + + var data = { + scriptName: 'randy', + callback: function() { + console.error('Hello !'); + } + }; + + var element = wsScriptLoaderService.insertScriptTag(data.scriptName, data.callback); + var src = angular.element(element).attr('src'); + var onload = angular.element(element).attr('onload'); + + expect(src).toBeDefined(); + expect(src).toEqual('randy'); + + expect(onload).toBeDefined(); + expect(onload).toEqual(data.callback); + }); + + // For loadScriptTag + it('method loadScriptTag should add script into the DOM', function() { + + var data = { + scriptName: 'randy' + }; + + var element = wsScriptLoaderService.loadScriptTag(data.scriptName); + var src = angular.element(element).attr('src'); + var onload = angular.element(element).attr('onload'); + + expect(src).toBeDefined(); + expect(src).toEqual('randy'); + + expect(onload).toBeDefined(); + expect(onload).toEqual(data.callback); + }); + it('method insertScriptTag should execute the callback when script have already been added !', function() { // object created to use spies functionality @@ -52,21 +90,4 @@ describe('wsScriptLoaderService test', function() { expect(data.callback).toHaveBeenCalled(); // suppose to be true }); - - // For loadScriptTag - - it('method insertScriptTag should the promise when script have already been added !', function() { - - var success = function(success) { - console.info('Success !'); - }; - - var error = function(error) { - console.error('Error !'); - }; - - var scriptName = 'myScript'; - wsScriptLoaderService.loadScriptTag(scriptName).then(success, error); - }); - }); From f153e18003583a6c413a6b95f4deb9c466a1bfdc Mon Sep 17 00:00:00 2001 From: Randy Date: Mon, 11 Apr 2016 09:37:39 +0200 Subject: [PATCH 10/19] Change script name --- test/wsScriptLoaderSpec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/wsScriptLoaderSpec.js b/test/wsScriptLoaderSpec.js index 4e7368a..808d391 100755 --- a/test/wsScriptLoaderSpec.js +++ b/test/wsScriptLoaderSpec.js @@ -38,7 +38,7 @@ describe('wsScriptLoaderService test', function() { it('method insertScriptTag should add script into the DOM', function() { var data = { - scriptName: 'randy', + scriptName: 'myScript', callback: function() { console.error('Hello !'); } @@ -49,7 +49,7 @@ describe('wsScriptLoaderService test', function() { var onload = angular.element(element).attr('onload'); expect(src).toBeDefined(); - expect(src).toEqual('randy'); + expect(src).toEqual('myScript'); expect(onload).toBeDefined(); expect(onload).toEqual(data.callback); @@ -59,7 +59,7 @@ describe('wsScriptLoaderService test', function() { it('method loadScriptTag should add script into the DOM', function() { var data = { - scriptName: 'randy' + scriptName: 'myScript' }; var element = wsScriptLoaderService.loadScriptTag(data.scriptName); @@ -67,7 +67,7 @@ describe('wsScriptLoaderService test', function() { var onload = angular.element(element).attr('onload'); expect(src).toBeDefined(); - expect(src).toEqual('randy'); + expect(src).toEqual('myScript'); expect(onload).toBeDefined(); expect(onload).toEqual(data.callback); From 308ef61d2b8efc2281d51bf8ec80cc882864e55e Mon Sep 17 00:00:00 2001 From: Randy Date: Mon, 11 Apr 2016 09:42:47 +0200 Subject: [PATCH 11/19] Add some returns for test --- src/wsScriptLoader.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wsScriptLoader.js b/src/wsScriptLoader.js index 67fb3bb..eef064b 100755 --- a/src/wsScriptLoader.js +++ b/src/wsScriptLoader.js @@ -1,4 +1,4 @@ -angular.module('wsScriptLoader', []) +angular.module('wsScriptLoader', ['wsScriptLoader']) .service('wsScriptLoader', function($q) { var service = this; @@ -18,6 +18,7 @@ angular.module('wsScriptLoader', []) document.body.appendChild(tag); loadedScripts.push(tagUrl); + return tag; } else { @@ -38,5 +39,5 @@ angular.module('wsScriptLoader', []) }); return deferred.promise; - }; - }); \ No newline at end of file + }; + }); From 96a7a5e69d266efacd74e070c83fc5d3a57f27ad Mon Sep 17 00:00:00 2001 From: Randy Date: Tue, 17 May 2016 17:19:25 +0200 Subject: [PATCH 12/19] Add Travis for test --- .travis.yml | 4 ++++ package.json | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..af652df --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.8 +script: gulp diff --git a/package.json b/package.json index 1db12a5..f87977d 100644 --- a/package.json +++ b/package.json @@ -30,5 +30,8 @@ }, "engines": { "node": ">=0.8.0" + }, + "scripts": { + "test": "gulp test-debug" } } From 0d97876e630e8e31a994a1844d5c002493148525 Mon Sep 17 00:00:00 2001 From: Randy Date: Tue, 17 May 2016 17:35:50 +0200 Subject: [PATCH 13/19] Update Travis file --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index af652df..51fb993 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,8 @@ language: node_js node_js: - - 0.8 + - 5.6.0 + - 3.6.0 +before_script: + - npm install + - bower install script: gulp From 173e73592088b8a4b619041b7967508219262dd5 Mon Sep 17 00:00:00 2001 From: Randy Date: Tue, 17 May 2016 17:45:10 +0200 Subject: [PATCH 14/19] Fixing bower install --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 51fb993..7fc9a80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,6 @@ node_js: - 3.6.0 before_script: - npm install + - npm install bower - bower install script: gulp From f7887dfcad91a5bed66b8f7d75c61f5fe238d2b0 Mon Sep 17 00:00:00 2001 From: Randy Date: Tue, 17 May 2016 17:55:37 +0200 Subject: [PATCH 15/19] Fixing gulp --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7fc9a80..1c871c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: node_js node_js: - 5.6.0 - - 3.6.0 before_script: - npm install - npm install bower - bower install + - npm update + - bower update script: gulp From 2756cc6069ad75cf3821fe6238b203c3ffe9ecbc Mon Sep 17 00:00:00 2001 From: Kangele Date: Mon, 23 May 2016 12:02:38 +0200 Subject: [PATCH 16/19] Add Travis badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6b8e997..2ecafa5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +https://travis-ci.org/Kangele/ws-script-loader.svg?branch=travis_setup + # wsScriptLoader Dynamically load scripts in your Angular code. From d3501d9553410a48159cc180e824721548e421ce Mon Sep 17 00:00:00 2001 From: Kangele Date: Mon, 23 May 2016 12:03:27 +0200 Subject: [PATCH 17/19] Fix Travis badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ecafa5..1437c4e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -https://travis-ci.org/Kangele/ws-script-loader.svg?branch=travis_setup +[![Build Status](https://travis-ci.org/Kangele/ws-script-loader.svg?branch=travis_setup)](https://travis-ci.org/Kangele/ws-script-loader) # wsScriptLoader From 1a0c5d5b8c94197ef4db79d40e7c71fd888afd27 Mon Sep 17 00:00:00 2001 From: Kangele Date: Mon, 23 May 2016 12:02:38 +0200 Subject: [PATCH 18/19] Add Travis badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6b8e997..2ecafa5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +https://travis-ci.org/Kangele/ws-script-loader.svg?branch=travis_setup + # wsScriptLoader Dynamically load scripts in your Angular code. From c92dd85ca993bd85bf29ba67d0a106cb56e4d139 Mon Sep 17 00:00:00 2001 From: Kangele Date: Mon, 23 May 2016 12:03:27 +0200 Subject: [PATCH 19/19] Fix Travis badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ecafa5..1437c4e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -https://travis-ci.org/Kangele/ws-script-loader.svg?branch=travis_setup +[![Build Status](https://travis-ci.org/Kangele/ws-script-loader.svg?branch=travis_setup)](https://travis-ci.org/Kangele/ws-script-loader) # wsScriptLoader