From 54095e9e215ac7ca0c1f1ec0c42f86056b356188 Mon Sep 17 00:00:00 2001 From: Richard Russell Date: Thu, 27 Apr 2017 23:46:38 +0100 Subject: [PATCH 1/3] Add start of unit tests. --- karma.conf.js | 21 ++++++++++++++ package.json | 11 ++++++++ test/angular-environment.js | 56 +++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 karma.conf.js create mode 100644 test/angular-environment.js diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..f086d92 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,21 @@ +module.exports = function (config) { + config.set({ + plugins: [ + 'karma-jasmine', + 'karma-chrome-launcher' + ], + frameworks: ['jasmine'], + singleRun: false, + autoWatch: true, + colors: true, + reporters: ['dots'], + browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'], + files: [ + 'node_modules/angular/angular.js', + 'node_modules/angular-mocks/angular-mocks.js', + 'src/angular-environment.js', + 'test/*.js' + ], + logLevel: config.LOG_ERROR + }); +}; \ No newline at end of file diff --git a/package.json b/package.json index c164378..22c64db 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "1.0.8", "description": "AngujarJS Environment Plugin", "main": "index.js", + "scripts": { + "test": "karma start --single-run" + }, "repository": { "type": "git", "url": "git+https://github.com/juanpablob/angular-environment.git" @@ -24,6 +27,8 @@ }, "homepage": "https://github.com/juanpablob/angular-environment#readme", "devDependencies": { + "angular": "^1.6.4", + "angular-mocks": "^1.6.4", "gulp": "^3.9.0", "gulp-concat": "^2.6.0", "gulp-jshint": "^1.11.2", @@ -33,6 +38,12 @@ "gulp-strip-debug": "^1.1.0", "gulp-util": "^3.0.6", "gulp-watch": "^4.3.3", + "jasmine": "^2.6.0", + "jasmine-core": "^2.6.1", + "karma": "^1.6.0", + "karma-chrome-launcher": "^2.0.0", + "karma-firefox-launcher": "^1.0.1", + "karma-jasmine": "^1.1.0", "yargs": "^3.15.0" } } diff --git a/test/angular-environment.js b/test/angular-environment.js new file mode 100644 index 0000000..666745f --- /dev/null +++ b/test/angular-environment.js @@ -0,0 +1,56 @@ +'use strict'; + +describe('Test environment provider', function () { + + var theEnvServiceProvider; + var envService; + + beforeEach(function () { + // Initialise the provider by injecting it into a fake module's + // config block. + var fakeModule = angular.module('test.app.environment', []); + fakeModule.config(function (envServiceProvider) { + theEnvServiceProvider = envServiceProvider; + }); + // Initialise the test.app injector. + module('environment', 'test.app.environment'); + inject(function () {}); + envService = theEnvServiceProvider.$get(); + + envService.config({ + vars: { + development: { + backend: 'https://backend-dev/' + }, + production: { + backend: 'https://backend/' + } + } + }); + }); + + describe('with envService provider', function () { + it('tests the envService provider can be created', function () { + expect(theEnvServiceProvider).toBeDefined(); + }); + + it('tests the default environment for envService is development', function () { + expect(envService.environment).toBe('development'); + expect(envService.get()).toBe('development'); + }); + + it('tests the environment for envService can be set', function () { + envService.set('production'); + expect(envService.get()).toBe('production'); + }); + + it('tests the config var for development environment is selected', function () { + expect(envService.read('backend')).toBe('https://backend-dev/'); + }); + + it('tests the config var for production environment is selected', function () { + envService.set('production'); + expect(envService.read('backend')).toBe('https://backend/'); + }); + }); +}); From 18413764ffeaf616d5340c2c614fb8bce61f7490 Mon Sep 17 00:00:00 2001 From: Richard Russell Date: Thu, 27 Apr 2017 23:48:25 +0100 Subject: [PATCH 2/3] Add end line to end of karma.conf.js file. --- karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index f086d92..dde99ca 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -18,4 +18,4 @@ module.exports = function (config) { ], logLevel: config.LOG_ERROR }); -}; \ No newline at end of file +}; From 1ebc8b2c63976a3fd78bcfe88bc3dc0266f8096c Mon Sep 17 00:00:00 2001 From: Richard Russell Date: Sun, 30 Apr 2017 10:53:52 +0100 Subject: [PATCH 3/3] Remove extra words in demo/index.html. --- demo/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/index.html b/demo/index.html index 438d74e..f9d113a 100644 --- a/demo/index.html +++ b/demo/index.html @@ -18,7 +18,7 @@

AngularJS Environment Plugin

Let's see if it works


-

The current environment is {{environment}} and this are the their vars

+

The current environment is {{environment}} and this is their vars

  • {{k}} —→ {{v}}