├── .gitignore ├── LICENSE ├── README.md ├── jasmine-lib ├── console │ └── console.js ├── jasmine-core.js ├── jasmine-core.rb └── jasmine-core │ ├── __init__.py │ ├── boot.js │ ├── boot │ ├── boot.js │ └── node_boot.js │ ├── core.py │ ├── example │ ├── node_example │ │ ├── lib │ │ │ └── jasmine_examples │ │ │ │ ├── Player.js │ │ │ │ └── Song.js │ │ └── spec │ │ │ ├── helpers │ │ │ └── jasmine_examples │ │ │ │ └── SpecHelper.js │ │ │ └── jasmine_examples │ │ │ └── PlayerSpec.js │ ├── spec │ │ ├── PlayerSpec.js │ │ └── SpecHelper.js │ └── src │ │ ├── Player.js │ │ └── Song.js │ ├── jasmine-html.js │ ├── jasmine.css │ ├── jasmine.js │ ├── json2.js │ ├── node_boot.js │ ├── spec │ └── version.rb ├── night-mode.js ├── night-mode.js.map ├── night-mode.min.js ├── night-mode.ts ├── test-runner.html └── unit-tests.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # night-mode-js 2 | 3 | A small javascript tool to automatically add or remove night css class from the `` element. It's lightweight, straightforward and easy to set up. 4 | 5 | ## Why? 6 | This project was designed with conviction that all software should have an optimized dark theme to reduce eye strain during night-time use. 7 | 8 | ## Quickstart 9 | Simply include the script in the ``. 10 | ```html 11 | 12 | ``` 13 | 14 | Or download and place night-mode.min.js in your project. 15 | ```html 16 | 17 | ``` 18 | 19 | 20 | The simplest way to use NightMode (See the table below describing default options): 21 | ```html 22 | 25 | ``` 26 | 27 | Or with custom options: 28 | ```html 29 | 37 | ``` 38 | ### Options 39 | 40 | | property | default | description | 41 | |--------------------------|--------------------|-------------------------------------------------------------------------------| 42 | | evening | new DayTime(21, 0) | The time when the night starts. Seconds aren't supported. | 43 | | morning | new DayTime(6, 0) | The time when the night ends. Seconds aren't supported. | 44 | | refreshIntervalInSeconds | 20 | How often the NightMode object checks the time. | 45 | | cssNightClassName | 'night' | Name of the css class that is added to `` element at night | 46 | | autoSwitch | true | Whether the NightMode object should automatically switch the night css class. | 47 | 48 | And you can also disable or enable the nightMode auto-switch if necessary (note that disabling auto-switch doesn't remove the night class from the body if it's currently present): 49 | ```js 50 | nightMode.disableAutoSwitch(); 51 | nightMode.enableAutoSwitch(); 52 | ``` 53 | 54 | You're almost done! You just need to add some css rules: 55 | ```css 56 | body { 57 | background-color: white; 58 | color: #212121; 59 | } 60 | 61 | body.night { 62 | background-color: #181818; 63 | color: white; 64 | } 65 | ... 66 | ``` 67 | 68 | ## Compatibility 69 | This script is written entirely in Typescript and compiled into javascript language level ES5. If you need a different language level, feel free to compile the source yourself. 70 | 71 | ## Dependencies 72 | No dependencies! 73 | 74 | ## License & credits 75 | 76 | Created by [Marek Kadlčík](http://marekkadlcik.com). 77 | 78 | Licensed under [MIT licence](https://github.com/cuddlecheek/night-mode-js/blob/master/LICENSE). 79 | -------------------------------------------------------------------------------- /jasmine-lib/console/console.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2016 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | function getJasmineRequireObj() { 24 | if (typeof module !== 'undefined' && module.exports) { 25 | return exports; 26 | } else { 27 | window.jasmineRequire = window.jasmineRequire || {}; 28 | return window.jasmineRequire; 29 | } 30 | } 31 | 32 | getJasmineRequireObj().console = function(jRequire, j$) { 33 | j$.ConsoleReporter = jRequire.ConsoleReporter(); 34 | }; 35 | 36 | getJasmineRequireObj().ConsoleReporter = function() { 37 | 38 | var noopTimer = { 39 | start: function(){}, 40 | elapsed: function(){ return 0; } 41 | }; 42 | 43 | function ConsoleReporter(options) { 44 | var print = options.print, 45 | showColors = options.showColors || false, 46 | onComplete = options.onComplete || function() {}, 47 | timer = options.timer || noopTimer, 48 | specCount, 49 | failureCount, 50 | failedSpecs = [], 51 | pendingCount, 52 | ansi = { 53 | green: '\x1B[32m', 54 | red: '\x1B[31m', 55 | yellow: '\x1B[33m', 56 | none: '\x1B[0m' 57 | }, 58 | failedSuites = []; 59 | 60 | print('ConsoleReporter is deprecated and will be removed in a future version.'); 61 | 62 | this.jasmineStarted = function() { 63 | specCount = 0; 64 | failureCount = 0; 65 | pendingCount = 0; 66 | print('Started'); 67 | printNewline(); 68 | timer.start(); 69 | }; 70 | 71 | this.jasmineDone = function() { 72 | printNewline(); 73 | for (var i = 0; i < failedSpecs.length; i++) { 74 | specFailureDetails(failedSpecs[i]); 75 | } 76 | 77 | if(specCount > 0) { 78 | printNewline(); 79 | 80 | var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' + 81 | failureCount + ' ' + plural('failure', failureCount); 82 | 83 | if (pendingCount) { 84 | specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount); 85 | } 86 | 87 | print(specCounts); 88 | } else { 89 | print('No specs found'); 90 | } 91 | 92 | printNewline(); 93 | var seconds = timer.elapsed() / 1000; 94 | print('Finished in ' + seconds + ' ' + plural('second', seconds)); 95 | printNewline(); 96 | 97 | for(i = 0; i < failedSuites.length; i++) { 98 | suiteFailureDetails(failedSuites[i]); 99 | } 100 | 101 | onComplete(failureCount === 0); 102 | }; 103 | 104 | this.specDone = function(result) { 105 | specCount++; 106 | 107 | if (result.status == 'pending') { 108 | pendingCount++; 109 | print(colored('yellow', '*')); 110 | return; 111 | } 112 | 113 | if (result.status == 'passed') { 114 | print(colored('green', '.')); 115 | return; 116 | } 117 | 118 | if (result.status == 'failed') { 119 | failureCount++; 120 | failedSpecs.push(result); 121 | print(colored('red', 'F')); 122 | } 123 | }; 124 | 125 | this.suiteDone = function(result) { 126 | if (result.failedExpectations && result.failedExpectations.length > 0) { 127 | failureCount++; 128 | failedSuites.push(result); 129 | } 130 | }; 131 | 132 | return this; 133 | 134 | function printNewline() { 135 | print('\n'); 136 | } 137 | 138 | function colored(color, str) { 139 | return showColors ? (ansi[color] + str + ansi.none) : str; 140 | } 141 | 142 | function plural(str, count) { 143 | return count == 1 ? str : str + 's'; 144 | } 145 | 146 | function repeat(thing, times) { 147 | var arr = []; 148 | for (var i = 0; i < times; i++) { 149 | arr.push(thing); 150 | } 151 | return arr; 152 | } 153 | 154 | function indent(str, spaces) { 155 | var lines = (str || '').split('\n'); 156 | var newArr = []; 157 | for (var i = 0; i < lines.length; i++) { 158 | newArr.push(repeat(' ', spaces).join('') + lines[i]); 159 | } 160 | return newArr.join('\n'); 161 | } 162 | 163 | function specFailureDetails(result) { 164 | printNewline(); 165 | print(result.fullName); 166 | 167 | for (var i = 0; i < result.failedExpectations.length; i++) { 168 | var failedExpectation = result.failedExpectations[i]; 169 | printNewline(); 170 | print(indent(failedExpectation.message, 2)); 171 | print(indent(failedExpectation.stack, 2)); 172 | } 173 | 174 | printNewline(); 175 | } 176 | 177 | function suiteFailureDetails(result) { 178 | for (var i = 0; i < result.failedExpectations.length; i++) { 179 | printNewline(); 180 | print(colored('red', 'An error was thrown in an afterAll')); 181 | printNewline(); 182 | print(colored('red', 'AfterAll ' + result.failedExpectations[i].message)); 183 | 184 | } 185 | printNewline(); 186 | } 187 | } 188 | 189 | return ConsoleReporter; 190 | }; 191 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./jasmine-core/jasmine.js"); 2 | module.exports.boot = require('./jasmine-core/node_boot.js'); 3 | 4 | var path = require('path'), 5 | fs = require('fs'); 6 | 7 | var rootPath = path.join(__dirname, "jasmine-core"), 8 | bootFiles = ['boot.js'], 9 | nodeBootFiles = ['node_boot.js'], 10 | cssFiles = [], 11 | jsFiles = [], 12 | jsFilesToSkip = ['jasmine.js'].concat(bootFiles, nodeBootFiles); 13 | 14 | fs.readdirSync(rootPath).forEach(function(file) { 15 | if(fs.statSync(path.join(rootPath, file)).isFile()) { 16 | switch(path.extname(file)) { 17 | case '.css': 18 | cssFiles.push(file); 19 | break; 20 | case '.js': 21 | if (jsFilesToSkip.indexOf(file) < 0) { 22 | jsFiles.push(file); 23 | } 24 | break; 25 | } 26 | } 27 | }); 28 | 29 | module.exports.files = { 30 | path: rootPath, 31 | bootDir: rootPath, 32 | bootFiles: bootFiles, 33 | nodeBootFiles: nodeBootFiles, 34 | cssFiles: cssFiles, 35 | jsFiles: ['jasmine.js'].concat(jsFiles), 36 | imagesDir: path.join(__dirname, '../images') 37 | }; 38 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core.rb: -------------------------------------------------------------------------------- 1 | module Jasmine 2 | module Core 3 | class << self 4 | def path 5 | File.join(File.dirname(__FILE__), "jasmine-core") 6 | end 7 | 8 | def js_files 9 | (["jasmine.js"] + Dir.glob(File.join(path, "*.js"))).map { |f| File.basename(f) }.uniq - boot_files - node_boot_files 10 | end 11 | 12 | SPEC_TYPES = ["core", "html", "node"] 13 | 14 | def core_spec_files 15 | spec_files("core") 16 | end 17 | 18 | def html_spec_files 19 | spec_files("html") 20 | end 21 | 22 | def node_spec_files 23 | spec_files("node") 24 | end 25 | 26 | def boot_files 27 | ["boot.js"] 28 | end 29 | 30 | def node_boot_files 31 | ["node_boot.js"] 32 | end 33 | 34 | def boot_dir 35 | path 36 | end 37 | 38 | def spec_files(type) 39 | raise ArgumentError.new("Unrecognized spec type") unless SPEC_TYPES.include?(type) 40 | (Dir.glob(File.join(path, "spec", type, "*.js"))).map { |f| File.join("spec", type, File.basename(f)) }.uniq 41 | end 42 | 43 | def css_files 44 | Dir.glob(File.join(path, "*.css")).map { |f| File.basename(f) } 45 | end 46 | 47 | def images_dir 48 | File.join(File.dirname(__FILE__), '../images') 49 | end 50 | 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/__init__.py: -------------------------------------------------------------------------------- 1 | from .core import Core -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/boot.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2016 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | /** 24 | Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project. 25 | 26 | If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms. 27 | 28 | The location of `boot.js` can be specified and/or overridden in `jasmine.yml`. 29 | 30 | [jasmine-gem]: http://github.com/pivotal/jasmine-gem 31 | */ 32 | 33 | (function() { 34 | 35 | /** 36 | * ## Require & Instantiate 37 | * 38 | * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference. 39 | */ 40 | window.jasmine = jasmineRequire.core(jasmineRequire); 41 | 42 | /** 43 | * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference. 44 | */ 45 | jasmineRequire.html(jasmine); 46 | 47 | /** 48 | * Create the Jasmine environment. This is used to run all specs in a project. 49 | */ 50 | var env = jasmine.getEnv(); 51 | 52 | /** 53 | * ## The Global Interface 54 | * 55 | * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged. 56 | */ 57 | var jasmineInterface = jasmineRequire.interface(jasmine, env); 58 | 59 | /** 60 | * Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`. 61 | */ 62 | extend(window, jasmineInterface); 63 | 64 | /** 65 | * ## Runner Parameters 66 | * 67 | * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface. 68 | */ 69 | 70 | var queryString = new jasmine.QueryString({ 71 | getWindowLocation: function() { return window.location; } 72 | }); 73 | 74 | var catchingExceptions = queryString.getParam("catch"); 75 | env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions); 76 | 77 | var throwingExpectationFailures = queryString.getParam("throwFailures"); 78 | env.throwOnExpectationFailure(throwingExpectationFailures); 79 | 80 | var random = queryString.getParam("random"); 81 | env.randomizeTests(random); 82 | 83 | var seed = queryString.getParam("seed"); 84 | if (seed) { 85 | env.seed(seed); 86 | } 87 | 88 | /** 89 | * ## Reporters 90 | * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any). 91 | */ 92 | var htmlReporter = new jasmine.HtmlReporter({ 93 | env: env, 94 | onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); }, 95 | onThrowExpectationsClick: function() { queryString.navigateWithNewParam("throwFailures", !env.throwingExpectationFailures()); }, 96 | onRandomClick: function() { queryString.navigateWithNewParam("random", !env.randomTests()); }, 97 | addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); }, 98 | getContainer: function() { return document.body; }, 99 | createElement: function() { return document.createElement.apply(document, arguments); }, 100 | createTextNode: function() { return document.createTextNode.apply(document, arguments); }, 101 | timer: new jasmine.Timer() 102 | }); 103 | 104 | /** 105 | * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript. 106 | */ 107 | env.addReporter(jasmineInterface.jsApiReporter); 108 | env.addReporter(htmlReporter); 109 | 110 | /** 111 | * Filter which specs will be run by matching the start of the full name against the `spec` query param. 112 | */ 113 | var specFilter = new jasmine.HtmlSpecFilter({ 114 | filterString: function() { return queryString.getParam("spec"); } 115 | }); 116 | 117 | env.specFilter = function(spec) { 118 | return specFilter.matches(spec.getFullName()); 119 | }; 120 | 121 | /** 122 | * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack. 123 | */ 124 | window.setTimeout = window.setTimeout; 125 | window.setInterval = window.setInterval; 126 | window.clearTimeout = window.clearTimeout; 127 | window.clearInterval = window.clearInterval; 128 | 129 | /** 130 | * ## Execution 131 | * 132 | * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded. 133 | */ 134 | var currentWindowOnload = window.onload; 135 | 136 | window.onload = function() { 137 | if (currentWindowOnload) { 138 | currentWindowOnload(); 139 | } 140 | htmlReporter.initialize(); 141 | env.execute(); 142 | }; 143 | 144 | /** 145 | * Helper function for readability above. 146 | */ 147 | function extend(destination, source) { 148 | for (var property in source) destination[property] = source[property]; 149 | return destination; 150 | } 151 | 152 | }()); 153 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/boot/boot.js: -------------------------------------------------------------------------------- 1 | /** 2 | Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project. 3 | 4 | If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms. 5 | 6 | The location of `boot.js` can be specified and/or overridden in `jasmine.yml`. 7 | 8 | [jasmine-gem]: http://github.com/pivotal/jasmine-gem 9 | */ 10 | 11 | (function() { 12 | 13 | /** 14 | * ## Require & Instantiate 15 | * 16 | * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference. 17 | */ 18 | window.jasmine = jasmineRequire.core(jasmineRequire); 19 | 20 | /** 21 | * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference. 22 | */ 23 | jasmineRequire.html(jasmine); 24 | 25 | /** 26 | * Create the Jasmine environment. This is used to run all specs in a project. 27 | */ 28 | var env = jasmine.getEnv(); 29 | 30 | /** 31 | * ## The Global Interface 32 | * 33 | * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged. 34 | */ 35 | var jasmineInterface = jasmineRequire.interface(jasmine, env); 36 | 37 | /** 38 | * Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`. 39 | */ 40 | extend(window, jasmineInterface); 41 | 42 | /** 43 | * ## Runner Parameters 44 | * 45 | * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface. 46 | */ 47 | 48 | var queryString = new jasmine.QueryString({ 49 | getWindowLocation: function() { return window.location; } 50 | }); 51 | 52 | var catchingExceptions = queryString.getParam("catch"); 53 | env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions); 54 | 55 | var throwingExpectationFailures = queryString.getParam("throwFailures"); 56 | env.throwOnExpectationFailure(throwingExpectationFailures); 57 | 58 | var random = queryString.getParam("random"); 59 | env.randomizeTests(random); 60 | 61 | var seed = queryString.getParam("seed"); 62 | if (seed) { 63 | env.seed(seed); 64 | } 65 | 66 | /** 67 | * ## Reporters 68 | * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any). 69 | */ 70 | var htmlReporter = new jasmine.HtmlReporter({ 71 | env: env, 72 | onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); }, 73 | onThrowExpectationsClick: function() { queryString.navigateWithNewParam("throwFailures", !env.throwingExpectationFailures()); }, 74 | onRandomClick: function() { queryString.navigateWithNewParam("random", !env.randomTests()); }, 75 | addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); }, 76 | getContainer: function() { return document.body; }, 77 | createElement: function() { return document.createElement.apply(document, arguments); }, 78 | createTextNode: function() { return document.createTextNode.apply(document, arguments); }, 79 | timer: new jasmine.Timer() 80 | }); 81 | 82 | /** 83 | * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript. 84 | */ 85 | env.addReporter(jasmineInterface.jsApiReporter); 86 | env.addReporter(htmlReporter); 87 | 88 | /** 89 | * Filter which specs will be run by matching the start of the full name against the `spec` query param. 90 | */ 91 | var specFilter = new jasmine.HtmlSpecFilter({ 92 | filterString: function() { return queryString.getParam("spec"); } 93 | }); 94 | 95 | env.specFilter = function(spec) { 96 | return specFilter.matches(spec.getFullName()); 97 | }; 98 | 99 | /** 100 | * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack. 101 | */ 102 | window.setTimeout = window.setTimeout; 103 | window.setInterval = window.setInterval; 104 | window.clearTimeout = window.clearTimeout; 105 | window.clearInterval = window.clearInterval; 106 | 107 | /** 108 | * ## Execution 109 | * 110 | * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded. 111 | */ 112 | var currentWindowOnload = window.onload; 113 | 114 | window.onload = function() { 115 | if (currentWindowOnload) { 116 | currentWindowOnload(); 117 | } 118 | htmlReporter.initialize(); 119 | env.execute(); 120 | }; 121 | 122 | /** 123 | * Helper function for readability above. 124 | */ 125 | function extend(destination, source) { 126 | for (var property in source) destination[property] = source[property]; 127 | return destination; 128 | } 129 | 130 | }()); 131 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/boot/node_boot.js: -------------------------------------------------------------------------------- 1 | module.exports = function(jasmineRequire) { 2 | var jasmine = jasmineRequire.core(jasmineRequire); 3 | 4 | var consoleFns = require('../console/console.js'); 5 | consoleFns.console(consoleFns, jasmine); 6 | 7 | var env = jasmine.getEnv(); 8 | 9 | var jasmineInterface = jasmineRequire.interface(jasmine, env); 10 | 11 | extend(global, jasmineInterface); 12 | 13 | function extend(destination, source) { 14 | for (var property in source) destination[property] = source[property]; 15 | return destination; 16 | } 17 | 18 | return jasmine; 19 | }; 20 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/core.py: -------------------------------------------------------------------------------- 1 | import pkg_resources 2 | 3 | try: 4 | from collections import OrderedDict 5 | except ImportError: 6 | from ordereddict import OrderedDict 7 | 8 | class Core(object): 9 | @classmethod 10 | def js_package(cls): 11 | return __package__ 12 | 13 | @classmethod 14 | def css_package(cls): 15 | return __package__ 16 | 17 | @classmethod 18 | def image_package(cls): 19 | return __package__ + ".images" 20 | 21 | @classmethod 22 | def js_files(cls): 23 | js_files = sorted(list(filter(lambda x: '.js' in x, pkg_resources.resource_listdir(cls.js_package(), '.')))) 24 | 25 | # jasmine.js needs to be first 26 | js_files.insert(0, 'jasmine.js') 27 | 28 | # boot needs to be last 29 | js_files.remove('boot.js') 30 | js_files.append('boot.js') 31 | 32 | return cls._uniq(js_files) 33 | 34 | @classmethod 35 | def css_files(cls): 36 | return cls._uniq(sorted(filter(lambda x: '.css' in x, pkg_resources.resource_listdir(cls.css_package(), '.')))) 37 | 38 | @classmethod 39 | def favicon(cls): 40 | return 'jasmine_favicon.png' 41 | 42 | @classmethod 43 | def _uniq(self, items, idfun=None): 44 | # order preserving 45 | 46 | if idfun is None: 47 | def idfun(x): return x 48 | seen = {} 49 | result = [] 50 | for item in items: 51 | marker = idfun(item) 52 | # in old Python versions: 53 | # if seen.has_key(marker) 54 | # but in new ones: 55 | if marker in seen: 56 | continue 57 | 58 | seen[marker] = 1 59 | result.append(item) 60 | return result -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/example/node_example/lib/jasmine_examples/Player.js: -------------------------------------------------------------------------------- 1 | function Player() { 2 | } 3 | Player.prototype.play = function(song) { 4 | this.currentlyPlayingSong = song; 5 | this.isPlaying = true; 6 | }; 7 | 8 | Player.prototype.pause = function() { 9 | this.isPlaying = false; 10 | }; 11 | 12 | Player.prototype.resume = function() { 13 | if (this.isPlaying) { 14 | throw new Error("song is already playing"); 15 | } 16 | 17 | this.isPlaying = true; 18 | }; 19 | 20 | Player.prototype.makeFavorite = function() { 21 | this.currentlyPlayingSong.persistFavoriteStatus(true); 22 | }; 23 | 24 | module.exports = Player; 25 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/example/node_example/lib/jasmine_examples/Song.js: -------------------------------------------------------------------------------- 1 | function Song() { 2 | } 3 | 4 | Song.prototype.persistFavoriteStatus = function(value) { 5 | // something complicated 6 | throw new Error("not yet implemented"); 7 | }; 8 | 9 | module.exports = Song; 10 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/example/node_example/spec/helpers/jasmine_examples/SpecHelper.js: -------------------------------------------------------------------------------- 1 | beforeEach(function () { 2 | jasmine.addMatchers({ 3 | toBePlaying: function () { 4 | return { 5 | compare: function (actual, expected) { 6 | var player = actual; 7 | 8 | return { 9 | pass: player.currentlyPlayingSong === expected && player.isPlaying 10 | } 11 | } 12 | }; 13 | } 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/example/node_example/spec/jasmine_examples/PlayerSpec.js: -------------------------------------------------------------------------------- 1 | describe("Player", function() { 2 | var Player = require('../../lib/jasmine_examples/Player'); 3 | var Song = require('../../lib/jasmine_examples/Song'); 4 | var player; 5 | var song; 6 | 7 | beforeEach(function() { 8 | player = new Player(); 9 | song = new Song(); 10 | }); 11 | 12 | it("should be able to play a Song", function() { 13 | player.play(song); 14 | expect(player.currentlyPlayingSong).toEqual(song); 15 | 16 | //demonstrates use of custom matcher 17 | expect(player).toBePlaying(song); 18 | }); 19 | 20 | describe("when song has been paused", function() { 21 | beforeEach(function() { 22 | player.play(song); 23 | player.pause(); 24 | }); 25 | 26 | it("should indicate that the song is currently paused", function() { 27 | expect(player.isPlaying).toBeFalsy(); 28 | 29 | // demonstrates use of 'not' with a custom matcher 30 | expect(player).not.toBePlaying(song); 31 | }); 32 | 33 | it("should be possible to resume", function() { 34 | player.resume(); 35 | expect(player.isPlaying).toBeTruthy(); 36 | expect(player.currentlyPlayingSong).toEqual(song); 37 | }); 38 | }); 39 | 40 | // demonstrates use of spies to intercept and test method calls 41 | it("tells the current song if the user has made it a favorite", function() { 42 | spyOn(song, 'persistFavoriteStatus'); 43 | 44 | player.play(song); 45 | player.makeFavorite(); 46 | 47 | expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true); 48 | }); 49 | 50 | //demonstrates use of expected exceptions 51 | describe("#resume", function() { 52 | it("should throw an exception if song is already playing", function() { 53 | player.play(song); 54 | 55 | expect(function() { 56 | player.resume(); 57 | }).toThrowError("song is already playing"); 58 | }); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/example/spec/PlayerSpec.js: -------------------------------------------------------------------------------- 1 | describe("Player", function() { 2 | var player; 3 | var song; 4 | 5 | beforeEach(function() { 6 | player = new Player(); 7 | song = new Song(); 8 | }); 9 | 10 | it("should be able to play a Song", function() { 11 | player.play(song); 12 | expect(player.currentlyPlayingSong).toEqual(song); 13 | 14 | //demonstrates use of custom matcher 15 | expect(player).toBePlaying(song); 16 | }); 17 | 18 | describe("when song has been paused", function() { 19 | beforeEach(function() { 20 | player.play(song); 21 | player.pause(); 22 | }); 23 | 24 | it("should indicate that the song is currently paused", function() { 25 | expect(player.isPlaying).toBeFalsy(); 26 | 27 | // demonstrates use of 'not' with a custom matcher 28 | expect(player).not.toBePlaying(song); 29 | }); 30 | 31 | it("should be possible to resume", function() { 32 | player.resume(); 33 | expect(player.isPlaying).toBeTruthy(); 34 | expect(player.currentlyPlayingSong).toEqual(song); 35 | }); 36 | }); 37 | 38 | // demonstrates use of spies to intercept and test method calls 39 | it("tells the current song if the user has made it a favorite", function() { 40 | spyOn(song, 'persistFavoriteStatus'); 41 | 42 | player.play(song); 43 | player.makeFavorite(); 44 | 45 | expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true); 46 | }); 47 | 48 | //demonstrates use of expected exceptions 49 | describe("#resume", function() { 50 | it("should throw an exception if song is already playing", function() { 51 | player.play(song); 52 | 53 | expect(function() { 54 | player.resume(); 55 | }).toThrowError("song is already playing"); 56 | }); 57 | }); 58 | }); 59 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/example/spec/SpecHelper.js: -------------------------------------------------------------------------------- 1 | beforeEach(function () { 2 | jasmine.addMatchers({ 3 | toBePlaying: function () { 4 | return { 5 | compare: function (actual, expected) { 6 | var player = actual; 7 | 8 | return { 9 | pass: player.currentlyPlayingSong === expected && player.isPlaying 10 | }; 11 | } 12 | }; 13 | } 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/example/src/Player.js: -------------------------------------------------------------------------------- 1 | function Player() { 2 | } 3 | Player.prototype.play = function(song) { 4 | this.currentlyPlayingSong = song; 5 | this.isPlaying = true; 6 | }; 7 | 8 | Player.prototype.pause = function() { 9 | this.isPlaying = false; 10 | }; 11 | 12 | Player.prototype.resume = function() { 13 | if (this.isPlaying) { 14 | throw new Error("song is already playing"); 15 | } 16 | 17 | this.isPlaying = true; 18 | }; 19 | 20 | Player.prototype.makeFavorite = function() { 21 | this.currentlyPlayingSong.persistFavoriteStatus(true); 22 | }; -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/example/src/Song.js: -------------------------------------------------------------------------------- 1 | function Song() { 2 | } 3 | 4 | Song.prototype.persistFavoriteStatus = function(value) { 5 | // something complicated 6 | throw new Error("not yet implemented"); 7 | }; -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/jasmine-html.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2016 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | jasmineRequire.html = function(j$) { 24 | j$.ResultsNode = jasmineRequire.ResultsNode(); 25 | j$.HtmlReporter = jasmineRequire.HtmlReporter(j$); 26 | j$.QueryString = jasmineRequire.QueryString(); 27 | j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter(); 28 | }; 29 | 30 | jasmineRequire.HtmlReporter = function(j$) { 31 | 32 | var noopTimer = { 33 | start: function() {}, 34 | elapsed: function() { return 0; } 35 | }; 36 | 37 | function HtmlReporter(options) { 38 | var env = options.env || {}, 39 | getContainer = options.getContainer, 40 | createElement = options.createElement, 41 | createTextNode = options.createTextNode, 42 | onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {}, 43 | onThrowExpectationsClick = options.onThrowExpectationsClick || function() {}, 44 | onRandomClick = options.onRandomClick || function() {}, 45 | addToExistingQueryString = options.addToExistingQueryString || defaultQueryString, 46 | timer = options.timer || noopTimer, 47 | results = [], 48 | specsExecuted = 0, 49 | failureCount = 0, 50 | pendingSpecCount = 0, 51 | htmlReporterMain, 52 | symbols, 53 | failedSuites = []; 54 | 55 | this.initialize = function() { 56 | clearPrior(); 57 | htmlReporterMain = createDom('div', {className: 'jasmine_html-reporter'}, 58 | createDom('div', {className: 'jasmine-banner'}, 59 | createDom('a', {className: 'jasmine-title', href: 'http://jasmine.github.io/', target: '_blank'}), 60 | createDom('span', {className: 'jasmine-version'}, j$.version) 61 | ), 62 | createDom('ul', {className: 'jasmine-symbol-summary'}), 63 | createDom('div', {className: 'jasmine-alert'}), 64 | createDom('div', {className: 'jasmine-results'}, 65 | createDom('div', {className: 'jasmine-failures'}) 66 | ) 67 | ); 68 | getContainer().appendChild(htmlReporterMain); 69 | }; 70 | 71 | var totalSpecsDefined; 72 | this.jasmineStarted = function(options) { 73 | totalSpecsDefined = options.totalSpecsDefined || 0; 74 | timer.start(); 75 | }; 76 | 77 | var summary = createDom('div', {className: 'jasmine-summary'}); 78 | 79 | var topResults = new j$.ResultsNode({}, '', null), 80 | currentParent = topResults; 81 | 82 | this.suiteStarted = function(result) { 83 | currentParent.addChild(result, 'suite'); 84 | currentParent = currentParent.last(); 85 | }; 86 | 87 | this.suiteDone = function(result) { 88 | if (result.status == 'failed') { 89 | failedSuites.push(result); 90 | } 91 | 92 | if (currentParent == topResults) { 93 | return; 94 | } 95 | 96 | currentParent = currentParent.parent; 97 | }; 98 | 99 | this.specStarted = function(result) { 100 | currentParent.addChild(result, 'spec'); 101 | }; 102 | 103 | var failures = []; 104 | this.specDone = function(result) { 105 | if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') { 106 | console.error('Spec \'' + result.fullName + '\' has no expectations.'); 107 | } 108 | 109 | if (result.status != 'disabled') { 110 | specsExecuted++; 111 | } 112 | 113 | if (!symbols){ 114 | symbols = find('.jasmine-symbol-summary'); 115 | } 116 | 117 | symbols.appendChild(createDom('li', { 118 | className: noExpectations(result) ? 'jasmine-empty' : 'jasmine-' + result.status, 119 | id: 'spec_' + result.id, 120 | title: result.fullName 121 | } 122 | )); 123 | 124 | if (result.status == 'failed') { 125 | failureCount++; 126 | 127 | var failure = 128 | createDom('div', {className: 'jasmine-spec-detail jasmine-failed'}, 129 | createDom('div', {className: 'jasmine-description'}, 130 | createDom('a', {title: result.fullName, href: specHref(result)}, result.fullName) 131 | ), 132 | createDom('div', {className: 'jasmine-messages'}) 133 | ); 134 | var messages = failure.childNodes[1]; 135 | 136 | for (var i = 0; i < result.failedExpectations.length; i++) { 137 | var expectation = result.failedExpectations[i]; 138 | messages.appendChild(createDom('div', {className: 'jasmine-result-message'}, expectation.message)); 139 | messages.appendChild(createDom('div', {className: 'jasmine-stack-trace'}, expectation.stack)); 140 | } 141 | 142 | failures.push(failure); 143 | } 144 | 145 | if (result.status == 'pending') { 146 | pendingSpecCount++; 147 | } 148 | }; 149 | 150 | this.jasmineDone = function(doneResult) { 151 | var banner = find('.jasmine-banner'); 152 | var alert = find('.jasmine-alert'); 153 | var order = doneResult && doneResult.order; 154 | alert.appendChild(createDom('span', {className: 'jasmine-duration'}, 'finished in ' + timer.elapsed() / 1000 + 's')); 155 | 156 | banner.appendChild( 157 | createDom('div', { className: 'jasmine-run-options' }, 158 | createDom('span', { className: 'jasmine-trigger' }, 'Options'), 159 | createDom('div', { className: 'jasmine-payload' }, 160 | createDom('div', { className: 'jasmine-exceptions' }, 161 | createDom('input', { 162 | className: 'jasmine-raise', 163 | id: 'jasmine-raise-exceptions', 164 | type: 'checkbox' 165 | }), 166 | createDom('label', { className: 'jasmine-label', 'for': 'jasmine-raise-exceptions' }, 'raise exceptions')), 167 | createDom('div', { className: 'jasmine-throw-failures' }, 168 | createDom('input', { 169 | className: 'jasmine-throw', 170 | id: 'jasmine-throw-failures', 171 | type: 'checkbox' 172 | }), 173 | createDom('label', { className: 'jasmine-label', 'for': 'jasmine-throw-failures' }, 'stop spec on expectation failure')), 174 | createDom('div', { className: 'jasmine-random-order' }, 175 | createDom('input', { 176 | className: 'jasmine-random', 177 | id: 'jasmine-random-order', 178 | type: 'checkbox' 179 | }), 180 | createDom('label', { className: 'jasmine-label', 'for': 'jasmine-random-order' }, 'run tests in random order')) 181 | ) 182 | )); 183 | 184 | var raiseCheckbox = find('#jasmine-raise-exceptions'); 185 | 186 | raiseCheckbox.checked = !env.catchingExceptions(); 187 | raiseCheckbox.onclick = onRaiseExceptionsClick; 188 | 189 | var throwCheckbox = find('#jasmine-throw-failures'); 190 | throwCheckbox.checked = env.throwingExpectationFailures(); 191 | throwCheckbox.onclick = onThrowExpectationsClick; 192 | 193 | var randomCheckbox = find('#jasmine-random-order'); 194 | randomCheckbox.checked = env.randomTests(); 195 | randomCheckbox.onclick = onRandomClick; 196 | 197 | var optionsMenu = find('.jasmine-run-options'), 198 | optionsTrigger = optionsMenu.querySelector('.jasmine-trigger'), 199 | optionsPayload = optionsMenu.querySelector('.jasmine-payload'), 200 | isOpen = /\bjasmine-open\b/; 201 | 202 | optionsTrigger.onclick = function() { 203 | if (isOpen.test(optionsPayload.className)) { 204 | optionsPayload.className = optionsPayload.className.replace(isOpen, ''); 205 | } else { 206 | optionsPayload.className += ' jasmine-open'; 207 | } 208 | }; 209 | 210 | if (specsExecuted < totalSpecsDefined) { 211 | var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all'; 212 | var skippedLink = order && order.random ? '?random=true' : '?'; 213 | alert.appendChild( 214 | createDom('span', {className: 'jasmine-bar jasmine-skipped'}, 215 | createDom('a', {href: skippedLink, title: 'Run all specs'}, skippedMessage) 216 | ) 217 | ); 218 | } 219 | var statusBarMessage = ''; 220 | var statusBarClassName = 'jasmine-bar '; 221 | 222 | if (totalSpecsDefined > 0) { 223 | statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount); 224 | if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); } 225 | statusBarClassName += (failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed'; 226 | } else { 227 | statusBarClassName += 'jasmine-skipped'; 228 | statusBarMessage += 'No specs found'; 229 | } 230 | 231 | var seedBar; 232 | if (order && order.random) { 233 | seedBar = createDom('span', {className: 'jasmine-seed-bar'}, 234 | ', randomized with seed ', 235 | createDom('a', {title: 'randomized with seed ' + order.seed, href: seedHref(order.seed)}, order.seed) 236 | ); 237 | } 238 | 239 | alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage, seedBar)); 240 | 241 | var errorBarClassName = 'jasmine-bar jasmine-errored'; 242 | var errorBarMessagePrefix = 'AfterAll '; 243 | 244 | for(var i = 0; i < failedSuites.length; i++) { 245 | var failedSuite = failedSuites[i]; 246 | for(var j = 0; j < failedSuite.failedExpectations.length; j++) { 247 | alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failedSuite.failedExpectations[j].message)); 248 | } 249 | } 250 | 251 | var globalFailures = (doneResult && doneResult.failedExpectations) || []; 252 | for(i = 0; i < globalFailures.length; i++) { 253 | var failure = globalFailures[i]; 254 | alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failure.message)); 255 | } 256 | 257 | var results = find('.jasmine-results'); 258 | results.appendChild(summary); 259 | 260 | summaryList(topResults, summary); 261 | 262 | function summaryList(resultsTree, domParent) { 263 | var specListNode; 264 | for (var i = 0; i < resultsTree.children.length; i++) { 265 | var resultNode = resultsTree.children[i]; 266 | if (resultNode.type == 'suite') { 267 | var suiteListNode = createDom('ul', {className: 'jasmine-suite', id: 'suite-' + resultNode.result.id}, 268 | createDom('li', {className: 'jasmine-suite-detail'}, 269 | createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description) 270 | ) 271 | ); 272 | 273 | summaryList(resultNode, suiteListNode); 274 | domParent.appendChild(suiteListNode); 275 | } 276 | if (resultNode.type == 'spec') { 277 | if (domParent.getAttribute('class') != 'jasmine-specs') { 278 | specListNode = createDom('ul', {className: 'jasmine-specs'}); 279 | domParent.appendChild(specListNode); 280 | } 281 | var specDescription = resultNode.result.description; 282 | if(noExpectations(resultNode.result)) { 283 | specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription; 284 | } 285 | if(resultNode.result.status === 'pending' && resultNode.result.pendingReason !== '') { 286 | specDescription = specDescription + ' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason; 287 | } 288 | specListNode.appendChild( 289 | createDom('li', { 290 | className: 'jasmine-' + resultNode.result.status, 291 | id: 'spec-' + resultNode.result.id 292 | }, 293 | createDom('a', {href: specHref(resultNode.result)}, specDescription) 294 | ) 295 | ); 296 | } 297 | } 298 | } 299 | 300 | if (failures.length) { 301 | alert.appendChild( 302 | createDom('span', {className: 'jasmine-menu jasmine-bar jasmine-spec-list'}, 303 | createDom('span', {}, 'Spec List | '), 304 | createDom('a', {className: 'jasmine-failures-menu', href: '#'}, 'Failures'))); 305 | alert.appendChild( 306 | createDom('span', {className: 'jasmine-menu jasmine-bar jasmine-failure-list'}, 307 | createDom('a', {className: 'jasmine-spec-list-menu', href: '#'}, 'Spec List'), 308 | createDom('span', {}, ' | Failures '))); 309 | 310 | find('.jasmine-failures-menu').onclick = function() { 311 | setMenuModeTo('jasmine-failure-list'); 312 | }; 313 | find('.jasmine-spec-list-menu').onclick = function() { 314 | setMenuModeTo('jasmine-spec-list'); 315 | }; 316 | 317 | setMenuModeTo('jasmine-failure-list'); 318 | 319 | var failureNode = find('.jasmine-failures'); 320 | for (i = 0; i < failures.length; i++) { 321 | failureNode.appendChild(failures[i]); 322 | } 323 | } 324 | }; 325 | 326 | return this; 327 | 328 | function find(selector) { 329 | return getContainer().querySelector('.jasmine_html-reporter ' + selector); 330 | } 331 | 332 | function clearPrior() { 333 | // return the reporter 334 | var oldReporter = find(''); 335 | 336 | if(oldReporter) { 337 | getContainer().removeChild(oldReporter); 338 | } 339 | } 340 | 341 | function createDom(type, attrs, childrenVarArgs) { 342 | var el = createElement(type); 343 | 344 | for (var i = 2; i < arguments.length; i++) { 345 | var child = arguments[i]; 346 | 347 | if (typeof child === 'string') { 348 | el.appendChild(createTextNode(child)); 349 | } else { 350 | if (child) { 351 | el.appendChild(child); 352 | } 353 | } 354 | } 355 | 356 | for (var attr in attrs) { 357 | if (attr == 'className') { 358 | el[attr] = attrs[attr]; 359 | } else { 360 | el.setAttribute(attr, attrs[attr]); 361 | } 362 | } 363 | 364 | return el; 365 | } 366 | 367 | function pluralize(singular, count) { 368 | var word = (count == 1 ? singular : singular + 's'); 369 | 370 | return '' + count + ' ' + word; 371 | } 372 | 373 | function specHref(result) { 374 | return addToExistingQueryString('spec', result.fullName); 375 | } 376 | 377 | function seedHref(seed) { 378 | return addToExistingQueryString('seed', seed); 379 | } 380 | 381 | function defaultQueryString(key, value) { 382 | return '?' + key + '=' + value; 383 | } 384 | 385 | function setMenuModeTo(mode) { 386 | htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode); 387 | } 388 | 389 | function noExpectations(result) { 390 | return (result.failedExpectations.length + result.passedExpectations.length) === 0 && 391 | result.status === 'passed'; 392 | } 393 | } 394 | 395 | return HtmlReporter; 396 | }; 397 | 398 | jasmineRequire.HtmlSpecFilter = function() { 399 | function HtmlSpecFilter(options) { 400 | var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); 401 | var filterPattern = new RegExp(filterString); 402 | 403 | this.matches = function(specName) { 404 | return filterPattern.test(specName); 405 | }; 406 | } 407 | 408 | return HtmlSpecFilter; 409 | }; 410 | 411 | jasmineRequire.ResultsNode = function() { 412 | function ResultsNode(result, type, parent) { 413 | this.result = result; 414 | this.type = type; 415 | this.parent = parent; 416 | 417 | this.children = []; 418 | 419 | this.addChild = function(result, type) { 420 | this.children.push(new ResultsNode(result, type, this)); 421 | }; 422 | 423 | this.last = function() { 424 | return this.children[this.children.length - 1]; 425 | }; 426 | } 427 | 428 | return ResultsNode; 429 | }; 430 | 431 | jasmineRequire.QueryString = function() { 432 | function QueryString(options) { 433 | 434 | this.navigateWithNewParam = function(key, value) { 435 | options.getWindowLocation().search = this.fullStringWithNewParam(key, value); 436 | }; 437 | 438 | this.fullStringWithNewParam = function(key, value) { 439 | var paramMap = queryStringToParamMap(); 440 | paramMap[key] = value; 441 | return toQueryString(paramMap); 442 | }; 443 | 444 | this.getParam = function(key) { 445 | return queryStringToParamMap()[key]; 446 | }; 447 | 448 | return this; 449 | 450 | function toQueryString(paramMap) { 451 | var qStrPairs = []; 452 | for (var prop in paramMap) { 453 | qStrPairs.push(encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])); 454 | } 455 | return '?' + qStrPairs.join('&'); 456 | } 457 | 458 | function queryStringToParamMap() { 459 | var paramStr = options.getWindowLocation().search.substring(1), 460 | params = [], 461 | paramMap = {}; 462 | 463 | if (paramStr.length > 0) { 464 | params = paramStr.split('&'); 465 | for (var i = 0; i < params.length; i++) { 466 | var p = params[i].split('='); 467 | var value = decodeURIComponent(p[1]); 468 | if (value === 'true' || value === 'false') { 469 | value = JSON.parse(value); 470 | } 471 | paramMap[decodeURIComponent(p[0])] = value; 472 | } 473 | } 474 | 475 | return paramMap; 476 | } 477 | 478 | } 479 | 480 | return QueryString; 481 | }; 482 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/jasmine.css: -------------------------------------------------------------------------------- 1 | body { overflow-y: scroll; } 2 | 3 | .jasmine_html-reporter { background-color: #eee; padding: 5px; margin: -8px; font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333; } 4 | .jasmine_html-reporter a { text-decoration: none; } 5 | .jasmine_html-reporter a:hover { text-decoration: underline; } 6 | .jasmine_html-reporter p, .jasmine_html-reporter h1, .jasmine_html-reporter h2, .jasmine_html-reporter h3, .jasmine_html-reporter h4, .jasmine_html-reporter h5, .jasmine_html-reporter h6 { margin: 0; line-height: 14px; } 7 | .jasmine_html-reporter .jasmine-banner, .jasmine_html-reporter .jasmine-symbol-summary, .jasmine_html-reporter .jasmine-summary, .jasmine_html-reporter .jasmine-result-message, .jasmine_html-reporter .jasmine-spec .jasmine-description, .jasmine_html-reporter .jasmine-spec-detail .jasmine-description, .jasmine_html-reporter .jasmine-alert .jasmine-bar, .jasmine_html-reporter .jasmine-stack-trace { padding-left: 9px; padding-right: 9px; } 8 | .jasmine_html-reporter .jasmine-banner { position: relative; } 9 | .jasmine_html-reporter .jasmine-banner .jasmine-title { background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFoAAAAZCAMAAACGusnyAAACdlBMVEX/////AP+AgICqVaqAQICZM5mAVYCSSZKAQICOOY6ATYCLRouAQICJO4mSSYCIRIiPQICHPIeOR4CGQ4aMQICGPYaLRoCFQ4WKQICPPYWJRYCOQoSJQICNPoSIRICMQoSHQICHRICKQoOHQICKPoOJO4OJQYOMQICMQ4CIQYKLQICIPoKLQ4CKQICNPoKJQISMQ4KJQoSLQYKJQISLQ4KIQoSKQYKIQICIQISMQoSKQYKLQIOLQoOJQYGLQIOKQIOMQoGKQYOLQYGKQIOLQoGJQYOJQIOKQYGJQIOKQoGKQIGLQIKLQ4KKQoGLQYKJQIGKQYKJQIGKQIKJQoGKQYKLQIGKQYKLQIOJQoKKQoOJQYKKQIOJQoKKQoOKQIOLQoKKQYOLQYKJQIOKQoKKQYKKQoKJQYOKQYKLQIOKQoKLQYOKQYKLQIOJQoGKQYKJQYGJQoGKQYKLQoGLQYGKQoGJQYKKQYGJQIKKQoGJQYKLQIKKQYGLQYKKQYGKQYGKQYKJQYOKQoKJQYOKQYKLQYOLQYOKQYKLQYOKQoKKQYKKQYOKQYOJQYKKQYKLQYKKQIKKQoKKQYKKQYKKQoKJQIKKQYKLQYKKQYKKQI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ICAgICAgICBpZD0icGF0aDU0IgogICAgICAgICAgICAgc3R5bGU9ImZpbGw6IzhhNDE4MjtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6bm9uZSIgLz48cGF0aAogICAgICAgICAgICAgZD0ibSA3MTYuMjg5LDM3Ni41OSAzNy42NDA2LDAgMCwxODQuODE2IC0zNy42NDA2LDAgMCwtMTg0LjgxNiB6IgogICAgICAgICAgICAgaW5rc2NhcGU6Y29ubmVjdG9yLWN1cnZhdHVyZT0iMCIKICAgICAgICAgICAgIGlkPSJwYXRoNTYiCiAgICAgICAgICAgICBzdHlsZT0iZmlsbDojOGE0MTgyO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIiAvPjwvZz48L2c+PC9nPjwvZz48L3N2Zz4=') no-repeat, none; -moz-background-size: 100%; -o-background-size: 100%; -webkit-background-size: 100%; background-size: 100%; display: block; float: left; width: 90px; height: 25px; } 10 | .jasmine_html-reporter .jasmine-banner .jasmine-version { margin-left: 14px; position: relative; top: 6px; } 11 | .jasmine_html-reporter #jasmine_content { position: fixed; right: 100%; } 12 | .jasmine_html-reporter .jasmine-version { color: #aaa; } 13 | .jasmine_html-reporter .jasmine-banner { margin-top: 14px; } 14 | .jasmine_html-reporter .jasmine-duration { color: #fff; float: right; line-height: 28px; padding-right: 9px; } 15 | .jasmine_html-reporter .jasmine-symbol-summary { overflow: hidden; *zoom: 1; margin: 14px 0; } 16 | .jasmine_html-reporter .jasmine-symbol-summary li { display: inline-block; height: 10px; width: 14px; font-size: 16px; } 17 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-passed { font-size: 14px; } 18 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-passed:before { color: #007069; content: "\02022"; } 19 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-failed { line-height: 9px; } 20 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-failed:before { color: #ca3a11; content: "\d7"; font-weight: bold; margin-left: -1px; } 21 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-disabled { font-size: 14px; } 22 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-disabled:before { color: #bababa; content: "\02022"; } 23 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-pending { line-height: 17px; } 24 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-pending:before { color: #ba9d37; content: "*"; } 25 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-empty { font-size: 14px; } 26 | .jasmine_html-reporter .jasmine-symbol-summary li.jasmine-empty:before { color: #ba9d37; content: "\02022"; } 27 | .jasmine_html-reporter .jasmine-run-options { float: right; margin-right: 5px; border: 1px solid #8a4182; color: #8a4182; position: relative; line-height: 20px; } 28 | .jasmine_html-reporter .jasmine-run-options .jasmine-trigger { cursor: pointer; padding: 8px 16px; } 29 | .jasmine_html-reporter .jasmine-run-options .jasmine-payload { position: absolute; display: none; right: -1px; border: 1px solid #8a4182; background-color: #eee; white-space: nowrap; padding: 4px 8px; } 30 | .jasmine_html-reporter .jasmine-run-options .jasmine-payload.jasmine-open { display: block; } 31 | .jasmine_html-reporter .jasmine-bar { line-height: 28px; font-size: 14px; display: block; color: #eee; } 32 | .jasmine_html-reporter .jasmine-bar.jasmine-failed { background-color: #ca3a11; } 33 | .jasmine_html-reporter .jasmine-bar.jasmine-passed { background-color: #007069; } 34 | .jasmine_html-reporter .jasmine-bar.jasmine-skipped { background-color: #bababa; } 35 | .jasmine_html-reporter .jasmine-bar.jasmine-errored { background-color: #ca3a11; } 36 | .jasmine_html-reporter .jasmine-bar.jasmine-menu { background-color: #fff; color: #aaa; } 37 | .jasmine_html-reporter .jasmine-bar.jasmine-menu a { color: #333; } 38 | .jasmine_html-reporter .jasmine-bar a { color: white; } 39 | .jasmine_html-reporter.jasmine-spec-list .jasmine-bar.jasmine-menu.jasmine-failure-list, .jasmine_html-reporter.jasmine-spec-list .jasmine-results .jasmine-failures { display: none; } 40 | .jasmine_html-reporter.jasmine-failure-list .jasmine-bar.jasmine-menu.jasmine-spec-list, .jasmine_html-reporter.jasmine-failure-list .jasmine-summary { display: none; } 41 | .jasmine_html-reporter .jasmine-results { margin-top: 14px; } 42 | .jasmine_html-reporter .jasmine-summary { margin-top: 14px; } 43 | .jasmine_html-reporter .jasmine-summary ul { list-style-type: none; margin-left: 14px; padding-top: 0; padding-left: 0; } 44 | .jasmine_html-reporter .jasmine-summary ul.jasmine-suite { margin-top: 7px; margin-bottom: 7px; } 45 | .jasmine_html-reporter .jasmine-summary li.jasmine-passed a { color: #007069; } 46 | .jasmine_html-reporter .jasmine-summary li.jasmine-failed a { color: #ca3a11; } 47 | .jasmine_html-reporter .jasmine-summary li.jasmine-empty a { color: #ba9d37; } 48 | .jasmine_html-reporter .jasmine-summary li.jasmine-pending a { color: #ba9d37; } 49 | .jasmine_html-reporter .jasmine-summary li.jasmine-disabled a { color: #bababa; } 50 | .jasmine_html-reporter .jasmine-description + .jasmine-suite { margin-top: 0; } 51 | .jasmine_html-reporter .jasmine-suite { margin-top: 14px; } 52 | .jasmine_html-reporter .jasmine-suite a { color: #333; } 53 | .jasmine_html-reporter .jasmine-failures .jasmine-spec-detail { margin-bottom: 28px; } 54 | .jasmine_html-reporter .jasmine-failures .jasmine-spec-detail .jasmine-description { background-color: #ca3a11; } 55 | .jasmine_html-reporter .jasmine-failures .jasmine-spec-detail .jasmine-description a { color: white; } 56 | .jasmine_html-reporter .jasmine-result-message { padding-top: 14px; color: #333; white-space: pre; } 57 | .jasmine_html-reporter .jasmine-result-message span.jasmine-result { display: block; } 58 | .jasmine_html-reporter .jasmine-stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666; border: 1px solid #ddd; background: white; white-space: pre; } 59 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/jasmine.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2016 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | var getJasmineRequireObj = (function (jasmineGlobal) { 24 | var jasmineRequire; 25 | 26 | if (typeof module !== 'undefined' && module.exports && typeof exports !== 'undefined') { 27 | if (typeof global !== 'undefined') { 28 | jasmineGlobal = global; 29 | } else { 30 | jasmineGlobal = {}; 31 | } 32 | jasmineRequire = exports; 33 | } else { 34 | if (typeof window !== 'undefined' && typeof window.toString === 'function' && window.toString() === '[object GjsGlobal]') { 35 | jasmineGlobal = window; 36 | } 37 | jasmineRequire = jasmineGlobal.jasmineRequire = jasmineGlobal.jasmineRequire || {}; 38 | } 39 | 40 | function getJasmineRequire() { 41 | return jasmineRequire; 42 | } 43 | 44 | getJasmineRequire().core = function(jRequire) { 45 | var j$ = {}; 46 | 47 | jRequire.base(j$, jasmineGlobal); 48 | j$.util = jRequire.util(); 49 | j$.errors = jRequire.errors(); 50 | j$.formatErrorMsg = jRequire.formatErrorMsg(); 51 | j$.Any = jRequire.Any(j$); 52 | j$.Anything = jRequire.Anything(j$); 53 | j$.CallTracker = jRequire.CallTracker(j$); 54 | j$.MockDate = jRequire.MockDate(); 55 | j$.Clock = jRequire.Clock(); 56 | j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler(); 57 | j$.Env = jRequire.Env(j$); 58 | j$.ExceptionFormatter = jRequire.ExceptionFormatter(); 59 | j$.Expectation = jRequire.Expectation(); 60 | j$.buildExpectationResult = jRequire.buildExpectationResult(); 61 | j$.JsApiReporter = jRequire.JsApiReporter(); 62 | j$.matchersUtil = jRequire.matchersUtil(j$); 63 | j$.ObjectContaining = jRequire.ObjectContaining(j$); 64 | j$.ArrayContaining = jRequire.ArrayContaining(j$); 65 | j$.pp = jRequire.pp(j$); 66 | j$.QueueRunner = jRequire.QueueRunner(j$); 67 | j$.ReportDispatcher = jRequire.ReportDispatcher(); 68 | j$.Spec = jRequire.Spec(j$); 69 | j$.SpyRegistry = jRequire.SpyRegistry(j$); 70 | j$.SpyStrategy = jRequire.SpyStrategy(); 71 | j$.StringMatching = jRequire.StringMatching(j$); 72 | j$.Suite = jRequire.Suite(j$); 73 | j$.Timer = jRequire.Timer(); 74 | j$.TreeProcessor = jRequire.TreeProcessor(); 75 | j$.version = jRequire.version(); 76 | j$.Order = jRequire.Order(); 77 | 78 | j$.matchers = jRequire.requireMatchers(jRequire, j$); 79 | 80 | return j$; 81 | }; 82 | 83 | return getJasmineRequire; 84 | })(this); 85 | 86 | getJasmineRequireObj().requireMatchers = function(jRequire, j$) { 87 | var availableMatchers = [ 88 | 'toBe', 89 | 'toBeCloseTo', 90 | 'toBeDefined', 91 | 'toBeFalsy', 92 | 'toBeGreaterThan', 93 | 'toBeGreaterThanOrEqual', 94 | 'toBeLessThanOrEqual', 95 | 'toBeLessThan', 96 | 'toBeNaN', 97 | 'toBeNull', 98 | 'toBeTruthy', 99 | 'toBeUndefined', 100 | 'toContain', 101 | 'toEqual', 102 | 'toHaveBeenCalled', 103 | 'toHaveBeenCalledWith', 104 | 'toHaveBeenCalledTimes', 105 | 'toMatch', 106 | 'toThrow', 107 | 'toThrowError' 108 | ], 109 | matchers = {}; 110 | 111 | for (var i = 0; i < availableMatchers.length; i++) { 112 | var name = availableMatchers[i]; 113 | matchers[name] = jRequire[name](j$); 114 | } 115 | 116 | return matchers; 117 | }; 118 | 119 | getJasmineRequireObj().base = function(j$, jasmineGlobal) { 120 | j$.unimplementedMethod_ = function() { 121 | throw new Error('unimplemented method'); 122 | }; 123 | 124 | j$.MAX_PRETTY_PRINT_DEPTH = 40; 125 | j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100; 126 | j$.DEFAULT_TIMEOUT_INTERVAL = 5000; 127 | 128 | j$.getGlobal = function() { 129 | return jasmineGlobal; 130 | }; 131 | 132 | j$.getEnv = function(options) { 133 | var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options); 134 | //jasmine. singletons in here (setTimeout blah blah). 135 | return env; 136 | }; 137 | 138 | j$.isArray_ = function(value) { 139 | return j$.isA_('Array', value); 140 | }; 141 | 142 | j$.isString_ = function(value) { 143 | return j$.isA_('String', value); 144 | }; 145 | 146 | j$.isNumber_ = function(value) { 147 | return j$.isA_('Number', value); 148 | }; 149 | 150 | j$.isA_ = function(typeName, value) { 151 | return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; 152 | }; 153 | 154 | j$.isDomNode = function(obj) { 155 | return obj.nodeType > 0; 156 | }; 157 | 158 | j$.fnNameFor = function(func) { 159 | if (func.name) { 160 | return func.name; 161 | } 162 | 163 | var matches = func.toString().match(/^\s*function\s*(\w*)\s*\(/); 164 | return matches ? matches[1] : ''; 165 | }; 166 | 167 | j$.any = function(clazz) { 168 | return new j$.Any(clazz); 169 | }; 170 | 171 | j$.anything = function() { 172 | return new j$.Anything(); 173 | }; 174 | 175 | j$.objectContaining = function(sample) { 176 | return new j$.ObjectContaining(sample); 177 | }; 178 | 179 | j$.stringMatching = function(expected) { 180 | return new j$.StringMatching(expected); 181 | }; 182 | 183 | j$.arrayContaining = function(sample) { 184 | return new j$.ArrayContaining(sample); 185 | }; 186 | 187 | j$.createSpy = function(name, originalFn) { 188 | 189 | var spyStrategy = new j$.SpyStrategy({ 190 | name: name, 191 | fn: originalFn, 192 | getSpy: function() { return spy; } 193 | }), 194 | callTracker = new j$.CallTracker(), 195 | spy = function() { 196 | var callData = { 197 | object: this, 198 | args: Array.prototype.slice.apply(arguments) 199 | }; 200 | 201 | callTracker.track(callData); 202 | var returnValue = spyStrategy.exec.apply(this, arguments); 203 | callData.returnValue = returnValue; 204 | 205 | return returnValue; 206 | }; 207 | 208 | for (var prop in originalFn) { 209 | if (prop === 'and' || prop === 'calls') { 210 | throw new Error('Jasmine spies would overwrite the \'and\' and \'calls\' properties on the object being spied upon'); 211 | } 212 | 213 | spy[prop] = originalFn[prop]; 214 | } 215 | 216 | spy.and = spyStrategy; 217 | spy.calls = callTracker; 218 | 219 | return spy; 220 | }; 221 | 222 | j$.isSpy = function(putativeSpy) { 223 | if (!putativeSpy) { 224 | return false; 225 | } 226 | return putativeSpy.and instanceof j$.SpyStrategy && 227 | putativeSpy.calls instanceof j$.CallTracker; 228 | }; 229 | 230 | j$.createSpyObj = function(baseName, methodNames) { 231 | if (j$.isArray_(baseName) && j$.util.isUndefined(methodNames)) { 232 | methodNames = baseName; 233 | baseName = 'unknown'; 234 | } 235 | 236 | if (!j$.isArray_(methodNames) || methodNames.length === 0) { 237 | throw 'createSpyObj requires a non-empty array of method names to create spies for'; 238 | } 239 | var obj = {}; 240 | for (var i = 0; i < methodNames.length; i++) { 241 | obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]); 242 | } 243 | return obj; 244 | }; 245 | }; 246 | 247 | getJasmineRequireObj().util = function() { 248 | 249 | var util = {}; 250 | 251 | util.inherit = function(childClass, parentClass) { 252 | var Subclass = function() { 253 | }; 254 | Subclass.prototype = parentClass.prototype; 255 | childClass.prototype = new Subclass(); 256 | }; 257 | 258 | util.htmlEscape = function(str) { 259 | if (!str) { 260 | return str; 261 | } 262 | return str.replace(/&/g, '&') 263 | .replace(//g, '>'); 265 | }; 266 | 267 | util.argsToArray = function(args) { 268 | var arrayOfArgs = []; 269 | for (var i = 0; i < args.length; i++) { 270 | arrayOfArgs.push(args[i]); 271 | } 272 | return arrayOfArgs; 273 | }; 274 | 275 | util.isUndefined = function(obj) { 276 | return obj === void 0; 277 | }; 278 | 279 | util.arrayContains = function(array, search) { 280 | var i = array.length; 281 | while (i--) { 282 | if (array[i] === search) { 283 | return true; 284 | } 285 | } 286 | return false; 287 | }; 288 | 289 | util.clone = function(obj) { 290 | if (Object.prototype.toString.apply(obj) === '[object Array]') { 291 | return obj.slice(); 292 | } 293 | 294 | var cloned = {}; 295 | for (var prop in obj) { 296 | if (obj.hasOwnProperty(prop)) { 297 | cloned[prop] = obj[prop]; 298 | } 299 | } 300 | 301 | return cloned; 302 | }; 303 | 304 | return util; 305 | }; 306 | 307 | getJasmineRequireObj().Spec = function(j$) { 308 | function Spec(attrs) { 309 | this.expectationFactory = attrs.expectationFactory; 310 | this.resultCallback = attrs.resultCallback || function() {}; 311 | this.id = attrs.id; 312 | this.description = attrs.description || ''; 313 | this.queueableFn = attrs.queueableFn; 314 | this.beforeAndAfterFns = attrs.beforeAndAfterFns || function() { return {befores: [], afters: []}; }; 315 | this.userContext = attrs.userContext || function() { return {}; }; 316 | this.onStart = attrs.onStart || function() {}; 317 | this.getSpecName = attrs.getSpecName || function() { return ''; }; 318 | this.expectationResultFactory = attrs.expectationResultFactory || function() { }; 319 | this.queueRunnerFactory = attrs.queueRunnerFactory || function() {}; 320 | this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; 321 | this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure; 322 | 323 | if (!this.queueableFn.fn) { 324 | this.pend(); 325 | } 326 | 327 | this.result = { 328 | id: this.id, 329 | description: this.description, 330 | fullName: this.getFullName(), 331 | failedExpectations: [], 332 | passedExpectations: [], 333 | pendingReason: '' 334 | }; 335 | } 336 | 337 | Spec.prototype.addExpectationResult = function(passed, data, isError) { 338 | var expectationResult = this.expectationResultFactory(data); 339 | if (passed) { 340 | this.result.passedExpectations.push(expectationResult); 341 | } else { 342 | this.result.failedExpectations.push(expectationResult); 343 | 344 | if (this.throwOnExpectationFailure && !isError) { 345 | throw new j$.errors.ExpectationFailed(); 346 | } 347 | } 348 | }; 349 | 350 | Spec.prototype.expect = function(actual) { 351 | return this.expectationFactory(actual, this); 352 | }; 353 | 354 | Spec.prototype.execute = function(onComplete, enabled) { 355 | var self = this; 356 | 357 | this.onStart(this); 358 | 359 | if (!this.isExecutable() || this.markedPending || enabled === false) { 360 | complete(enabled); 361 | return; 362 | } 363 | 364 | var fns = this.beforeAndAfterFns(); 365 | var allFns = fns.befores.concat(this.queueableFn).concat(fns.afters); 366 | 367 | this.queueRunnerFactory({ 368 | queueableFns: allFns, 369 | onException: function() { self.onException.apply(self, arguments); }, 370 | onComplete: complete, 371 | userContext: this.userContext() 372 | }); 373 | 374 | function complete(enabledAgain) { 375 | self.result.status = self.status(enabledAgain); 376 | self.resultCallback(self.result); 377 | 378 | if (onComplete) { 379 | onComplete(); 380 | } 381 | } 382 | }; 383 | 384 | Spec.prototype.onException = function onException(e) { 385 | if (Spec.isPendingSpecException(e)) { 386 | this.pend(extractCustomPendingMessage(e)); 387 | return; 388 | } 389 | 390 | if (e instanceof j$.errors.ExpectationFailed) { 391 | return; 392 | } 393 | 394 | this.addExpectationResult(false, { 395 | matcherName: '', 396 | passed: false, 397 | expected: '', 398 | actual: '', 399 | error: e 400 | }, true); 401 | }; 402 | 403 | Spec.prototype.disable = function() { 404 | this.disabled = true; 405 | }; 406 | 407 | Spec.prototype.pend = function(message) { 408 | this.markedPending = true; 409 | if (message) { 410 | this.result.pendingReason = message; 411 | } 412 | }; 413 | 414 | Spec.prototype.getResult = function() { 415 | this.result.status = this.status(); 416 | return this.result; 417 | }; 418 | 419 | Spec.prototype.status = function(enabled) { 420 | if (this.disabled || enabled === false) { 421 | return 'disabled'; 422 | } 423 | 424 | if (this.markedPending) { 425 | return 'pending'; 426 | } 427 | 428 | if (this.result.failedExpectations.length > 0) { 429 | return 'failed'; 430 | } else { 431 | return 'passed'; 432 | } 433 | }; 434 | 435 | Spec.prototype.isExecutable = function() { 436 | return !this.disabled; 437 | }; 438 | 439 | Spec.prototype.getFullName = function() { 440 | return this.getSpecName(this); 441 | }; 442 | 443 | var extractCustomPendingMessage = function(e) { 444 | var fullMessage = e.toString(), 445 | boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage), 446 | boilerplateEnd = boilerplateStart + Spec.pendingSpecExceptionMessage.length; 447 | 448 | return fullMessage.substr(boilerplateEnd); 449 | }; 450 | 451 | Spec.pendingSpecExceptionMessage = '=> marked Pending'; 452 | 453 | Spec.isPendingSpecException = function(e) { 454 | return !!(e && e.toString && e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1); 455 | }; 456 | 457 | return Spec; 458 | }; 459 | 460 | if (typeof window == void 0 && typeof exports == 'object') { 461 | exports.Spec = jasmineRequire.Spec; 462 | } 463 | 464 | /*jshint bitwise: false*/ 465 | 466 | getJasmineRequireObj().Order = function() { 467 | function Order(options) { 468 | this.random = 'random' in options ? options.random : true; 469 | var seed = this.seed = options.seed || generateSeed(); 470 | this.sort = this.random ? randomOrder : naturalOrder; 471 | 472 | function naturalOrder(items) { 473 | return items; 474 | } 475 | 476 | function randomOrder(items) { 477 | var copy = items.slice(); 478 | copy.sort(function(a, b) { 479 | return jenkinsHash(seed + a.id) - jenkinsHash(seed + b.id); 480 | }); 481 | return copy; 482 | } 483 | 484 | function generateSeed() { 485 | return String(Math.random()).slice(-5); 486 | } 487 | 488 | // Bob Jenkins One-at-a-Time Hash algorithm is a non-cryptographic hash function 489 | // used to get a different output when the key changes slighly. 490 | // We use your return to sort the children randomly in a consistent way when 491 | // used in conjunction with a seed 492 | 493 | function jenkinsHash(key) { 494 | var hash, i; 495 | for(hash = i = 0; i < key.length; ++i) { 496 | hash += key.charCodeAt(i); 497 | hash += (hash << 10); 498 | hash ^= (hash >> 6); 499 | } 500 | hash += (hash << 3); 501 | hash ^= (hash >> 11); 502 | hash += (hash << 15); 503 | return hash; 504 | } 505 | 506 | } 507 | 508 | return Order; 509 | }; 510 | 511 | getJasmineRequireObj().Env = function(j$) { 512 | function Env(options) { 513 | options = options || {}; 514 | 515 | var self = this; 516 | var global = options.global || j$.getGlobal(); 517 | 518 | var totalSpecsDefined = 0; 519 | 520 | var catchExceptions = true; 521 | 522 | var realSetTimeout = j$.getGlobal().setTimeout; 523 | var realClearTimeout = j$.getGlobal().clearTimeout; 524 | this.clock = new j$.Clock(global, function () { return new j$.DelayedFunctionScheduler(); }, new j$.MockDate(global)); 525 | 526 | var runnableResources = {}; 527 | 528 | var currentSpec = null; 529 | var currentlyExecutingSuites = []; 530 | var currentDeclarationSuite = null; 531 | var throwOnExpectationFailure = false; 532 | var random = false; 533 | var seed = null; 534 | 535 | var currentSuite = function() { 536 | return currentlyExecutingSuites[currentlyExecutingSuites.length - 1]; 537 | }; 538 | 539 | var currentRunnable = function() { 540 | return currentSpec || currentSuite(); 541 | }; 542 | 543 | var reporter = new j$.ReportDispatcher([ 544 | 'jasmineStarted', 545 | 'jasmineDone', 546 | 'suiteStarted', 547 | 'suiteDone', 548 | 'specStarted', 549 | 'specDone' 550 | ]); 551 | 552 | this.specFilter = function() { 553 | return true; 554 | }; 555 | 556 | this.addCustomEqualityTester = function(tester) { 557 | if(!currentRunnable()) { 558 | throw new Error('Custom Equalities must be added in a before function or a spec'); 559 | } 560 | runnableResources[currentRunnable().id].customEqualityTesters.push(tester); 561 | }; 562 | 563 | this.addMatchers = function(matchersToAdd) { 564 | if(!currentRunnable()) { 565 | throw new Error('Matchers must be added in a before function or a spec'); 566 | } 567 | var customMatchers = runnableResources[currentRunnable().id].customMatchers; 568 | for (var matcherName in matchersToAdd) { 569 | customMatchers[matcherName] = matchersToAdd[matcherName]; 570 | } 571 | }; 572 | 573 | j$.Expectation.addCoreMatchers(j$.matchers); 574 | 575 | var nextSpecId = 0; 576 | var getNextSpecId = function() { 577 | return 'spec' + nextSpecId++; 578 | }; 579 | 580 | var nextSuiteId = 0; 581 | var getNextSuiteId = function() { 582 | return 'suite' + nextSuiteId++; 583 | }; 584 | 585 | var expectationFactory = function(actual, spec) { 586 | return j$.Expectation.Factory({ 587 | util: j$.matchersUtil, 588 | customEqualityTesters: runnableResources[spec.id].customEqualityTesters, 589 | customMatchers: runnableResources[spec.id].customMatchers, 590 | actual: actual, 591 | addExpectationResult: addExpectationResult 592 | }); 593 | 594 | function addExpectationResult(passed, result) { 595 | return spec.addExpectationResult(passed, result); 596 | } 597 | }; 598 | 599 | var defaultResourcesForRunnable = function(id, parentRunnableId) { 600 | var resources = {spies: [], customEqualityTesters: [], customMatchers: {}}; 601 | 602 | if(runnableResources[parentRunnableId]){ 603 | resources.customEqualityTesters = j$.util.clone(runnableResources[parentRunnableId].customEqualityTesters); 604 | resources.customMatchers = j$.util.clone(runnableResources[parentRunnableId].customMatchers); 605 | } 606 | 607 | runnableResources[id] = resources; 608 | }; 609 | 610 | var clearResourcesForRunnable = function(id) { 611 | spyRegistry.clearSpies(); 612 | delete runnableResources[id]; 613 | }; 614 | 615 | var beforeAndAfterFns = function(suite) { 616 | return function() { 617 | var befores = [], 618 | afters = []; 619 | 620 | while(suite) { 621 | befores = befores.concat(suite.beforeFns); 622 | afters = afters.concat(suite.afterFns); 623 | 624 | suite = suite.parentSuite; 625 | } 626 | 627 | return { 628 | befores: befores.reverse(), 629 | afters: afters 630 | }; 631 | }; 632 | }; 633 | 634 | var getSpecName = function(spec, suite) { 635 | var fullName = [spec.description], 636 | suiteFullName = suite.getFullName(); 637 | 638 | if (suiteFullName !== '') { 639 | fullName.unshift(suiteFullName); 640 | } 641 | return fullName.join(' '); 642 | }; 643 | 644 | // TODO: we may just be able to pass in the fn instead of wrapping here 645 | var buildExpectationResult = j$.buildExpectationResult, 646 | exceptionFormatter = new j$.ExceptionFormatter(), 647 | expectationResultFactory = function(attrs) { 648 | attrs.messageFormatter = exceptionFormatter.message; 649 | attrs.stackFormatter = exceptionFormatter.stack; 650 | 651 | return buildExpectationResult(attrs); 652 | }; 653 | 654 | // TODO: fix this naming, and here's where the value comes in 655 | this.catchExceptions = function(value) { 656 | catchExceptions = !!value; 657 | return catchExceptions; 658 | }; 659 | 660 | this.catchingExceptions = function() { 661 | return catchExceptions; 662 | }; 663 | 664 | var maximumSpecCallbackDepth = 20; 665 | var currentSpecCallbackDepth = 0; 666 | 667 | function clearStack(fn) { 668 | currentSpecCallbackDepth++; 669 | if (currentSpecCallbackDepth >= maximumSpecCallbackDepth) { 670 | currentSpecCallbackDepth = 0; 671 | realSetTimeout(fn, 0); 672 | } else { 673 | fn(); 674 | } 675 | } 676 | 677 | var catchException = function(e) { 678 | return j$.Spec.isPendingSpecException(e) || catchExceptions; 679 | }; 680 | 681 | this.throwOnExpectationFailure = function(value) { 682 | throwOnExpectationFailure = !!value; 683 | }; 684 | 685 | this.throwingExpectationFailures = function() { 686 | return throwOnExpectationFailure; 687 | }; 688 | 689 | this.randomizeTests = function(value) { 690 | random = !!value; 691 | }; 692 | 693 | this.randomTests = function() { 694 | return random; 695 | }; 696 | 697 | this.seed = function(value) { 698 | if (value) { 699 | seed = value; 700 | } 701 | return seed; 702 | }; 703 | 704 | var queueRunnerFactory = function(options) { 705 | options.catchException = catchException; 706 | options.clearStack = options.clearStack || clearStack; 707 | options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}; 708 | options.fail = self.fail; 709 | 710 | new j$.QueueRunner(options).execute(); 711 | }; 712 | 713 | var topSuite = new j$.Suite({ 714 | env: this, 715 | id: getNextSuiteId(), 716 | description: 'Jasmine__TopLevel__Suite', 717 | expectationFactory: expectationFactory, 718 | expectationResultFactory: expectationResultFactory 719 | }); 720 | defaultResourcesForRunnable(topSuite.id); 721 | currentDeclarationSuite = topSuite; 722 | 723 | this.topSuite = function() { 724 | return topSuite; 725 | }; 726 | 727 | this.execute = function(runnablesToRun) { 728 | if(!runnablesToRun) { 729 | if (focusedRunnables.length) { 730 | runnablesToRun = focusedRunnables; 731 | } else { 732 | runnablesToRun = [topSuite.id]; 733 | } 734 | } 735 | 736 | var order = new j$.Order({ 737 | random: random, 738 | seed: seed 739 | }); 740 | 741 | var processor = new j$.TreeProcessor({ 742 | tree: topSuite, 743 | runnableIds: runnablesToRun, 744 | queueRunnerFactory: queueRunnerFactory, 745 | nodeStart: function(suite) { 746 | currentlyExecutingSuites.push(suite); 747 | defaultResourcesForRunnable(suite.id, suite.parentSuite.id); 748 | reporter.suiteStarted(suite.result); 749 | }, 750 | nodeComplete: function(suite, result) { 751 | if (!suite.disabled) { 752 | clearResourcesForRunnable(suite.id); 753 | } 754 | currentlyExecutingSuites.pop(); 755 | reporter.suiteDone(result); 756 | }, 757 | orderChildren: function(node) { 758 | return order.sort(node.children); 759 | } 760 | }); 761 | 762 | if(!processor.processTree().valid) { 763 | throw new Error('Invalid order: would cause a beforeAll or afterAll to be run multiple times'); 764 | } 765 | 766 | reporter.jasmineStarted({ 767 | totalSpecsDefined: totalSpecsDefined 768 | }); 769 | 770 | currentlyExecutingSuites.push(topSuite); 771 | 772 | processor.execute(function() { 773 | clearResourcesForRunnable(topSuite.id); 774 | currentlyExecutingSuites.pop(); 775 | 776 | reporter.jasmineDone({ 777 | order: order, 778 | failedExpectations: topSuite.result.failedExpectations 779 | }); 780 | }); 781 | }; 782 | 783 | this.addReporter = function(reporterToAdd) { 784 | reporter.addReporter(reporterToAdd); 785 | }; 786 | 787 | this.provideFallbackReporter = function(reporterToAdd) { 788 | reporter.provideFallbackReporter(reporterToAdd); 789 | }; 790 | 791 | var spyRegistry = new j$.SpyRegistry({currentSpies: function() { 792 | if(!currentRunnable()) { 793 | throw new Error('Spies must be created in a before function or a spec'); 794 | } 795 | return runnableResources[currentRunnable().id].spies; 796 | }}); 797 | 798 | this.allowRespy = function(allow){ 799 | spyRegistry.allowRespy(allow); 800 | }; 801 | 802 | this.spyOn = function() { 803 | return spyRegistry.spyOn.apply(spyRegistry, arguments); 804 | }; 805 | 806 | var suiteFactory = function(description) { 807 | var suite = new j$.Suite({ 808 | env: self, 809 | id: getNextSuiteId(), 810 | description: description, 811 | parentSuite: currentDeclarationSuite, 812 | expectationFactory: expectationFactory, 813 | expectationResultFactory: expectationResultFactory, 814 | throwOnExpectationFailure: throwOnExpectationFailure 815 | }); 816 | 817 | return suite; 818 | }; 819 | 820 | this.describe = function(description, specDefinitions) { 821 | var suite = suiteFactory(description); 822 | if (specDefinitions.length > 0) { 823 | throw new Error('describe does not expect any arguments'); 824 | } 825 | if (currentDeclarationSuite.markedPending) { 826 | suite.pend(); 827 | } 828 | addSpecsToSuite(suite, specDefinitions); 829 | return suite; 830 | }; 831 | 832 | this.xdescribe = function(description, specDefinitions) { 833 | var suite = suiteFactory(description); 834 | suite.pend(); 835 | addSpecsToSuite(suite, specDefinitions); 836 | return suite; 837 | }; 838 | 839 | var focusedRunnables = []; 840 | 841 | this.fdescribe = function(description, specDefinitions) { 842 | var suite = suiteFactory(description); 843 | suite.isFocused = true; 844 | 845 | focusedRunnables.push(suite.id); 846 | unfocusAncestor(); 847 | addSpecsToSuite(suite, specDefinitions); 848 | 849 | return suite; 850 | }; 851 | 852 | function addSpecsToSuite(suite, specDefinitions) { 853 | var parentSuite = currentDeclarationSuite; 854 | parentSuite.addChild(suite); 855 | currentDeclarationSuite = suite; 856 | 857 | var declarationError = null; 858 | try { 859 | specDefinitions.call(suite); 860 | } catch (e) { 861 | declarationError = e; 862 | } 863 | 864 | if (declarationError) { 865 | self.it('encountered a declaration exception', function() { 866 | throw declarationError; 867 | }); 868 | } 869 | 870 | currentDeclarationSuite = parentSuite; 871 | } 872 | 873 | function findFocusedAncestor(suite) { 874 | while (suite) { 875 | if (suite.isFocused) { 876 | return suite.id; 877 | } 878 | suite = suite.parentSuite; 879 | } 880 | 881 | return null; 882 | } 883 | 884 | function unfocusAncestor() { 885 | var focusedAncestor = findFocusedAncestor(currentDeclarationSuite); 886 | if (focusedAncestor) { 887 | for (var i = 0; i < focusedRunnables.length; i++) { 888 | if (focusedRunnables[i] === focusedAncestor) { 889 | focusedRunnables.splice(i, 1); 890 | break; 891 | } 892 | } 893 | } 894 | } 895 | 896 | var specFactory = function(description, fn, suite, timeout) { 897 | totalSpecsDefined++; 898 | var spec = new j$.Spec({ 899 | id: getNextSpecId(), 900 | beforeAndAfterFns: beforeAndAfterFns(suite), 901 | expectationFactory: expectationFactory, 902 | resultCallback: specResultCallback, 903 | getSpecName: function(spec) { 904 | return getSpecName(spec, suite); 905 | }, 906 | onStart: specStarted, 907 | description: description, 908 | expectationResultFactory: expectationResultFactory, 909 | queueRunnerFactory: queueRunnerFactory, 910 | userContext: function() { return suite.clonedSharedUserContext(); }, 911 | queueableFn: { 912 | fn: fn, 913 | timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } 914 | }, 915 | throwOnExpectationFailure: throwOnExpectationFailure 916 | }); 917 | 918 | if (!self.specFilter(spec)) { 919 | spec.disable(); 920 | } 921 | 922 | return spec; 923 | 924 | function specResultCallback(result) { 925 | clearResourcesForRunnable(spec.id); 926 | currentSpec = null; 927 | reporter.specDone(result); 928 | } 929 | 930 | function specStarted(spec) { 931 | currentSpec = spec; 932 | defaultResourcesForRunnable(spec.id, suite.id); 933 | reporter.specStarted(spec.result); 934 | } 935 | }; 936 | 937 | this.it = function(description, fn, timeout) { 938 | var spec = specFactory(description, fn, currentDeclarationSuite, timeout); 939 | if (currentDeclarationSuite.markedPending) { 940 | spec.pend(); 941 | } 942 | currentDeclarationSuite.addChild(spec); 943 | return spec; 944 | }; 945 | 946 | this.xit = function() { 947 | var spec = this.it.apply(this, arguments); 948 | spec.pend('Temporarily disabled with xit'); 949 | return spec; 950 | }; 951 | 952 | this.fit = function(description, fn, timeout){ 953 | var spec = specFactory(description, fn, currentDeclarationSuite, timeout); 954 | currentDeclarationSuite.addChild(spec); 955 | focusedRunnables.push(spec.id); 956 | unfocusAncestor(); 957 | return spec; 958 | }; 959 | 960 | this.expect = function(actual) { 961 | if (!currentRunnable()) { 962 | throw new Error('\'expect\' was used when there was no current spec, this could be because an asynchronous test timed out'); 963 | } 964 | 965 | return currentRunnable().expect(actual); 966 | }; 967 | 968 | this.beforeEach = function(beforeEachFunction, timeout) { 969 | currentDeclarationSuite.beforeEach({ 970 | fn: beforeEachFunction, 971 | timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } 972 | }); 973 | }; 974 | 975 | this.beforeAll = function(beforeAllFunction, timeout) { 976 | currentDeclarationSuite.beforeAll({ 977 | fn: beforeAllFunction, 978 | timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } 979 | }); 980 | }; 981 | 982 | this.afterEach = function(afterEachFunction, timeout) { 983 | currentDeclarationSuite.afterEach({ 984 | fn: afterEachFunction, 985 | timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } 986 | }); 987 | }; 988 | 989 | this.afterAll = function(afterAllFunction, timeout) { 990 | currentDeclarationSuite.afterAll({ 991 | fn: afterAllFunction, 992 | timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } 993 | }); 994 | }; 995 | 996 | this.pending = function(message) { 997 | var fullMessage = j$.Spec.pendingSpecExceptionMessage; 998 | if(message) { 999 | fullMessage += message; 1000 | } 1001 | throw fullMessage; 1002 | }; 1003 | 1004 | this.fail = function(error) { 1005 | var message = 'Failed'; 1006 | if (error) { 1007 | message += ': '; 1008 | message += error.message || error; 1009 | } 1010 | 1011 | currentRunnable().addExpectationResult(false, { 1012 | matcherName: '', 1013 | passed: false, 1014 | expected: '', 1015 | actual: '', 1016 | message: message, 1017 | error: error && error.message ? error : null 1018 | }); 1019 | }; 1020 | } 1021 | 1022 | return Env; 1023 | }; 1024 | 1025 | getJasmineRequireObj().JsApiReporter = function() { 1026 | 1027 | var noopTimer = { 1028 | start: function(){}, 1029 | elapsed: function(){ return 0; } 1030 | }; 1031 | 1032 | function JsApiReporter(options) { 1033 | var timer = options.timer || noopTimer, 1034 | status = 'loaded'; 1035 | 1036 | this.started = false; 1037 | this.finished = false; 1038 | this.runDetails = {}; 1039 | 1040 | this.jasmineStarted = function() { 1041 | this.started = true; 1042 | status = 'started'; 1043 | timer.start(); 1044 | }; 1045 | 1046 | var executionTime; 1047 | 1048 | this.jasmineDone = function(runDetails) { 1049 | this.finished = true; 1050 | this.runDetails = runDetails; 1051 | executionTime = timer.elapsed(); 1052 | status = 'done'; 1053 | }; 1054 | 1055 | this.status = function() { 1056 | return status; 1057 | }; 1058 | 1059 | var suites = [], 1060 | suites_hash = {}; 1061 | 1062 | this.suiteStarted = function(result) { 1063 | suites_hash[result.id] = result; 1064 | }; 1065 | 1066 | this.suiteDone = function(result) { 1067 | storeSuite(result); 1068 | }; 1069 | 1070 | this.suiteResults = function(index, length) { 1071 | return suites.slice(index, index + length); 1072 | }; 1073 | 1074 | function storeSuite(result) { 1075 | suites.push(result); 1076 | suites_hash[result.id] = result; 1077 | } 1078 | 1079 | this.suites = function() { 1080 | return suites_hash; 1081 | }; 1082 | 1083 | var specs = []; 1084 | 1085 | this.specDone = function(result) { 1086 | specs.push(result); 1087 | }; 1088 | 1089 | this.specResults = function(index, length) { 1090 | return specs.slice(index, index + length); 1091 | }; 1092 | 1093 | this.specs = function() { 1094 | return specs; 1095 | }; 1096 | 1097 | this.executionTime = function() { 1098 | return executionTime; 1099 | }; 1100 | 1101 | } 1102 | 1103 | return JsApiReporter; 1104 | }; 1105 | 1106 | getJasmineRequireObj().CallTracker = function(j$) { 1107 | 1108 | function CallTracker() { 1109 | var calls = []; 1110 | var opts = {}; 1111 | 1112 | function argCloner(context) { 1113 | var clonedArgs = []; 1114 | var argsAsArray = j$.util.argsToArray(context.args); 1115 | for(var i = 0; i < argsAsArray.length; i++) { 1116 | if(Object.prototype.toString.apply(argsAsArray[i]).match(/^\[object/)) { 1117 | clonedArgs.push(j$.util.clone(argsAsArray[i])); 1118 | } else { 1119 | clonedArgs.push(argsAsArray[i]); 1120 | } 1121 | } 1122 | context.args = clonedArgs; 1123 | } 1124 | 1125 | this.track = function(context) { 1126 | if(opts.cloneArgs) { 1127 | argCloner(context); 1128 | } 1129 | calls.push(context); 1130 | }; 1131 | 1132 | this.any = function() { 1133 | return !!calls.length; 1134 | }; 1135 | 1136 | this.count = function() { 1137 | return calls.length; 1138 | }; 1139 | 1140 | this.argsFor = function(index) { 1141 | var call = calls[index]; 1142 | return call ? call.args : []; 1143 | }; 1144 | 1145 | this.all = function() { 1146 | return calls; 1147 | }; 1148 | 1149 | this.allArgs = function() { 1150 | var callArgs = []; 1151 | for(var i = 0; i < calls.length; i++){ 1152 | callArgs.push(calls[i].args); 1153 | } 1154 | 1155 | return callArgs; 1156 | }; 1157 | 1158 | this.first = function() { 1159 | return calls[0]; 1160 | }; 1161 | 1162 | this.mostRecent = function() { 1163 | return calls[calls.length - 1]; 1164 | }; 1165 | 1166 | this.reset = function() { 1167 | calls = []; 1168 | }; 1169 | 1170 | this.saveArgumentsByValue = function() { 1171 | opts.cloneArgs = true; 1172 | }; 1173 | 1174 | } 1175 | 1176 | return CallTracker; 1177 | }; 1178 | 1179 | getJasmineRequireObj().Clock = function() { 1180 | function Clock(global, delayedFunctionSchedulerFactory, mockDate) { 1181 | var self = this, 1182 | realTimingFunctions = { 1183 | setTimeout: global.setTimeout, 1184 | clearTimeout: global.clearTimeout, 1185 | setInterval: global.setInterval, 1186 | clearInterval: global.clearInterval 1187 | }, 1188 | fakeTimingFunctions = { 1189 | setTimeout: setTimeout, 1190 | clearTimeout: clearTimeout, 1191 | setInterval: setInterval, 1192 | clearInterval: clearInterval 1193 | }, 1194 | installed = false, 1195 | delayedFunctionScheduler, 1196 | timer; 1197 | 1198 | 1199 | self.install = function() { 1200 | if(!originalTimingFunctionsIntact()) { 1201 | throw new Error('Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?'); 1202 | } 1203 | replace(global, fakeTimingFunctions); 1204 | timer = fakeTimingFunctions; 1205 | delayedFunctionScheduler = delayedFunctionSchedulerFactory(); 1206 | installed = true; 1207 | 1208 | return self; 1209 | }; 1210 | 1211 | self.uninstall = function() { 1212 | delayedFunctionScheduler = null; 1213 | mockDate.uninstall(); 1214 | replace(global, realTimingFunctions); 1215 | 1216 | timer = realTimingFunctions; 1217 | installed = false; 1218 | }; 1219 | 1220 | self.withMock = function(closure) { 1221 | this.install(); 1222 | try { 1223 | closure(); 1224 | } finally { 1225 | this.uninstall(); 1226 | } 1227 | }; 1228 | 1229 | self.mockDate = function(initialDate) { 1230 | mockDate.install(initialDate); 1231 | }; 1232 | 1233 | self.setTimeout = function(fn, delay, params) { 1234 | if (legacyIE()) { 1235 | if (arguments.length > 2) { 1236 | throw new Error('IE < 9 cannot support extra params to setTimeout without a polyfill'); 1237 | } 1238 | return timer.setTimeout(fn, delay); 1239 | } 1240 | return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]); 1241 | }; 1242 | 1243 | self.setInterval = function(fn, delay, params) { 1244 | if (legacyIE()) { 1245 | if (arguments.length > 2) { 1246 | throw new Error('IE < 9 cannot support extra params to setInterval without a polyfill'); 1247 | } 1248 | return timer.setInterval(fn, delay); 1249 | } 1250 | return Function.prototype.apply.apply(timer.setInterval, [global, arguments]); 1251 | }; 1252 | 1253 | self.clearTimeout = function(id) { 1254 | return Function.prototype.call.apply(timer.clearTimeout, [global, id]); 1255 | }; 1256 | 1257 | self.clearInterval = function(id) { 1258 | return Function.prototype.call.apply(timer.clearInterval, [global, id]); 1259 | }; 1260 | 1261 | self.tick = function(millis) { 1262 | if (installed) { 1263 | delayedFunctionScheduler.tick(millis, function(millis) { mockDate.tick(millis); }); 1264 | } else { 1265 | throw new Error('Mock clock is not installed, use jasmine.clock().install()'); 1266 | } 1267 | }; 1268 | 1269 | return self; 1270 | 1271 | function originalTimingFunctionsIntact() { 1272 | return global.setTimeout === realTimingFunctions.setTimeout && 1273 | global.clearTimeout === realTimingFunctions.clearTimeout && 1274 | global.setInterval === realTimingFunctions.setInterval && 1275 | global.clearInterval === realTimingFunctions.clearInterval; 1276 | } 1277 | 1278 | function legacyIE() { 1279 | //if these methods are polyfilled, apply will be present 1280 | return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply; 1281 | } 1282 | 1283 | function replace(dest, source) { 1284 | for (var prop in source) { 1285 | dest[prop] = source[prop]; 1286 | } 1287 | } 1288 | 1289 | function setTimeout(fn, delay) { 1290 | return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2)); 1291 | } 1292 | 1293 | function clearTimeout(id) { 1294 | return delayedFunctionScheduler.removeFunctionWithId(id); 1295 | } 1296 | 1297 | function setInterval(fn, interval) { 1298 | return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true); 1299 | } 1300 | 1301 | function clearInterval(id) { 1302 | return delayedFunctionScheduler.removeFunctionWithId(id); 1303 | } 1304 | 1305 | function argSlice(argsObj, n) { 1306 | return Array.prototype.slice.call(argsObj, n); 1307 | } 1308 | } 1309 | 1310 | return Clock; 1311 | }; 1312 | 1313 | getJasmineRequireObj().DelayedFunctionScheduler = function() { 1314 | function DelayedFunctionScheduler() { 1315 | var self = this; 1316 | var scheduledLookup = []; 1317 | var scheduledFunctions = {}; 1318 | var currentTime = 0; 1319 | var delayedFnCount = 0; 1320 | 1321 | self.tick = function(millis, tickDate) { 1322 | millis = millis || 0; 1323 | var endTime = currentTime + millis; 1324 | 1325 | runScheduledFunctions(endTime, tickDate); 1326 | currentTime = endTime; 1327 | }; 1328 | 1329 | self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) { 1330 | var f; 1331 | if (typeof(funcToCall) === 'string') { 1332 | /* jshint evil: true */ 1333 | f = function() { return eval(funcToCall); }; 1334 | /* jshint evil: false */ 1335 | } else { 1336 | f = funcToCall; 1337 | } 1338 | 1339 | millis = millis || 0; 1340 | timeoutKey = timeoutKey || ++delayedFnCount; 1341 | runAtMillis = runAtMillis || (currentTime + millis); 1342 | 1343 | var funcToSchedule = { 1344 | runAtMillis: runAtMillis, 1345 | funcToCall: f, 1346 | recurring: recurring, 1347 | params: params, 1348 | timeoutKey: timeoutKey, 1349 | millis: millis 1350 | }; 1351 | 1352 | if (runAtMillis in scheduledFunctions) { 1353 | scheduledFunctions[runAtMillis].push(funcToSchedule); 1354 | } else { 1355 | scheduledFunctions[runAtMillis] = [funcToSchedule]; 1356 | scheduledLookup.push(runAtMillis); 1357 | scheduledLookup.sort(function (a, b) { 1358 | return a - b; 1359 | }); 1360 | } 1361 | 1362 | return timeoutKey; 1363 | }; 1364 | 1365 | self.removeFunctionWithId = function(timeoutKey) { 1366 | for (var runAtMillis in scheduledFunctions) { 1367 | var funcs = scheduledFunctions[runAtMillis]; 1368 | var i = indexOfFirstToPass(funcs, function (func) { 1369 | return func.timeoutKey === timeoutKey; 1370 | }); 1371 | 1372 | if (i > -1) { 1373 | if (funcs.length === 1) { 1374 | delete scheduledFunctions[runAtMillis]; 1375 | deleteFromLookup(runAtMillis); 1376 | } else { 1377 | funcs.splice(i, 1); 1378 | } 1379 | 1380 | // intervals get rescheduled when executed, so there's never more 1381 | // than a single scheduled function with a given timeoutKey 1382 | break; 1383 | } 1384 | } 1385 | }; 1386 | 1387 | return self; 1388 | 1389 | function indexOfFirstToPass(array, testFn) { 1390 | var index = -1; 1391 | 1392 | for (var i = 0; i < array.length; ++i) { 1393 | if (testFn(array[i])) { 1394 | index = i; 1395 | break; 1396 | } 1397 | } 1398 | 1399 | return index; 1400 | } 1401 | 1402 | function deleteFromLookup(key) { 1403 | var value = Number(key); 1404 | var i = indexOfFirstToPass(scheduledLookup, function (millis) { 1405 | return millis === value; 1406 | }); 1407 | 1408 | if (i > -1) { 1409 | scheduledLookup.splice(i, 1); 1410 | } 1411 | } 1412 | 1413 | function reschedule(scheduledFn) { 1414 | self.scheduleFunction(scheduledFn.funcToCall, 1415 | scheduledFn.millis, 1416 | scheduledFn.params, 1417 | true, 1418 | scheduledFn.timeoutKey, 1419 | scheduledFn.runAtMillis + scheduledFn.millis); 1420 | } 1421 | 1422 | function forEachFunction(funcsToRun, callback) { 1423 | for (var i = 0; i < funcsToRun.length; ++i) { 1424 | callback(funcsToRun[i]); 1425 | } 1426 | } 1427 | 1428 | function runScheduledFunctions(endTime, tickDate) { 1429 | tickDate = tickDate || function() {}; 1430 | if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) { 1431 | tickDate(endTime); 1432 | return; 1433 | } 1434 | 1435 | do { 1436 | var newCurrentTime = scheduledLookup.shift(); 1437 | tickDate(newCurrentTime - currentTime); 1438 | 1439 | currentTime = newCurrentTime; 1440 | 1441 | var funcsToRun = scheduledFunctions[currentTime]; 1442 | delete scheduledFunctions[currentTime]; 1443 | 1444 | forEachFunction(funcsToRun, function(funcToRun) { 1445 | if (funcToRun.recurring) { 1446 | reschedule(funcToRun); 1447 | } 1448 | }); 1449 | 1450 | forEachFunction(funcsToRun, function(funcToRun) { 1451 | funcToRun.funcToCall.apply(null, funcToRun.params || []); 1452 | }); 1453 | } while (scheduledLookup.length > 0 && 1454 | // checking first if we're out of time prevents setTimeout(0) 1455 | // scheduled in a funcToRun from forcing an extra iteration 1456 | currentTime !== endTime && 1457 | scheduledLookup[0] <= endTime); 1458 | } 1459 | } 1460 | 1461 | return DelayedFunctionScheduler; 1462 | }; 1463 | 1464 | getJasmineRequireObj().ExceptionFormatter = function() { 1465 | function ExceptionFormatter() { 1466 | this.message = function(error) { 1467 | var message = ''; 1468 | 1469 | if (error.name && error.message) { 1470 | message += error.name + ': ' + error.message; 1471 | } else { 1472 | message += error.toString() + ' thrown'; 1473 | } 1474 | 1475 | if (error.fileName || error.sourceURL) { 1476 | message += ' in ' + (error.fileName || error.sourceURL); 1477 | } 1478 | 1479 | if (error.line || error.lineNumber) { 1480 | message += ' (line ' + (error.line || error.lineNumber) + ')'; 1481 | } 1482 | 1483 | return message; 1484 | }; 1485 | 1486 | this.stack = function(error) { 1487 | return error ? error.stack : null; 1488 | }; 1489 | } 1490 | 1491 | return ExceptionFormatter; 1492 | }; 1493 | 1494 | getJasmineRequireObj().Expectation = function() { 1495 | 1496 | function Expectation(options) { 1497 | this.util = options.util || { buildFailureMessage: function() {} }; 1498 | this.customEqualityTesters = options.customEqualityTesters || []; 1499 | this.actual = options.actual; 1500 | this.addExpectationResult = options.addExpectationResult || function(){}; 1501 | this.isNot = options.isNot; 1502 | 1503 | var customMatchers = options.customMatchers || {}; 1504 | for (var matcherName in customMatchers) { 1505 | this[matcherName] = Expectation.prototype.wrapCompare(matcherName, customMatchers[matcherName]); 1506 | } 1507 | } 1508 | 1509 | Expectation.prototype.wrapCompare = function(name, matcherFactory) { 1510 | return function() { 1511 | var args = Array.prototype.slice.call(arguments, 0), 1512 | expected = args.slice(0), 1513 | message = ''; 1514 | 1515 | args.unshift(this.actual); 1516 | 1517 | var matcher = matcherFactory(this.util, this.customEqualityTesters), 1518 | matcherCompare = matcher.compare; 1519 | 1520 | function defaultNegativeCompare() { 1521 | var result = matcher.compare.apply(null, args); 1522 | result.pass = !result.pass; 1523 | return result; 1524 | } 1525 | 1526 | if (this.isNot) { 1527 | matcherCompare = matcher.negativeCompare || defaultNegativeCompare; 1528 | } 1529 | 1530 | var result = matcherCompare.apply(null, args); 1531 | 1532 | if (!result.pass) { 1533 | if (!result.message) { 1534 | args.unshift(this.isNot); 1535 | args.unshift(name); 1536 | message = this.util.buildFailureMessage.apply(null, args); 1537 | } else { 1538 | if (Object.prototype.toString.apply(result.message) === '[object Function]') { 1539 | message = result.message(); 1540 | } else { 1541 | message = result.message; 1542 | } 1543 | } 1544 | } 1545 | 1546 | if (expected.length == 1) { 1547 | expected = expected[0]; 1548 | } 1549 | 1550 | // TODO: how many of these params are needed? 1551 | this.addExpectationResult( 1552 | result.pass, 1553 | { 1554 | matcherName: name, 1555 | passed: result.pass, 1556 | message: message, 1557 | actual: this.actual, 1558 | expected: expected // TODO: this may need to be arrayified/sliced 1559 | } 1560 | ); 1561 | }; 1562 | }; 1563 | 1564 | Expectation.addCoreMatchers = function(matchers) { 1565 | var prototype = Expectation.prototype; 1566 | for (var matcherName in matchers) { 1567 | var matcher = matchers[matcherName]; 1568 | prototype[matcherName] = prototype.wrapCompare(matcherName, matcher); 1569 | } 1570 | }; 1571 | 1572 | Expectation.Factory = function(options) { 1573 | options = options || {}; 1574 | 1575 | var expect = new Expectation(options); 1576 | 1577 | // TODO: this would be nice as its own Object - NegativeExpectation 1578 | // TODO: copy instead of mutate options 1579 | options.isNot = true; 1580 | expect.not = new Expectation(options); 1581 | 1582 | return expect; 1583 | }; 1584 | 1585 | return Expectation; 1586 | }; 1587 | 1588 | //TODO: expectation result may make more sense as a presentation of an expectation. 1589 | getJasmineRequireObj().buildExpectationResult = function() { 1590 | function buildExpectationResult(options) { 1591 | var messageFormatter = options.messageFormatter || function() {}, 1592 | stackFormatter = options.stackFormatter || function() {}; 1593 | 1594 | var result = { 1595 | matcherName: options.matcherName, 1596 | message: message(), 1597 | stack: stack(), 1598 | passed: options.passed 1599 | }; 1600 | 1601 | if(!result.passed) { 1602 | result.expected = options.expected; 1603 | result.actual = options.actual; 1604 | } 1605 | 1606 | return result; 1607 | 1608 | function message() { 1609 | if (options.passed) { 1610 | return 'Passed.'; 1611 | } else if (options.message) { 1612 | return options.message; 1613 | } else if (options.error) { 1614 | return messageFormatter(options.error); 1615 | } 1616 | return ''; 1617 | } 1618 | 1619 | function stack() { 1620 | if (options.passed) { 1621 | return ''; 1622 | } 1623 | 1624 | var error = options.error; 1625 | if (!error) { 1626 | try { 1627 | throw new Error(message()); 1628 | } catch (e) { 1629 | error = e; 1630 | } 1631 | } 1632 | return stackFormatter(error); 1633 | } 1634 | } 1635 | 1636 | return buildExpectationResult; 1637 | }; 1638 | 1639 | getJasmineRequireObj().MockDate = function() { 1640 | function MockDate(global) { 1641 | var self = this; 1642 | var currentTime = 0; 1643 | 1644 | if (!global || !global.Date) { 1645 | self.install = function() {}; 1646 | self.tick = function() {}; 1647 | self.uninstall = function() {}; 1648 | return self; 1649 | } 1650 | 1651 | var GlobalDate = global.Date; 1652 | 1653 | self.install = function(mockDate) { 1654 | if (mockDate instanceof GlobalDate) { 1655 | currentTime = mockDate.getTime(); 1656 | } else { 1657 | currentTime = new GlobalDate().getTime(); 1658 | } 1659 | 1660 | global.Date = FakeDate; 1661 | }; 1662 | 1663 | self.tick = function(millis) { 1664 | millis = millis || 0; 1665 | currentTime = currentTime + millis; 1666 | }; 1667 | 1668 | self.uninstall = function() { 1669 | currentTime = 0; 1670 | global.Date = GlobalDate; 1671 | }; 1672 | 1673 | createDateProperties(); 1674 | 1675 | return self; 1676 | 1677 | function FakeDate() { 1678 | switch(arguments.length) { 1679 | case 0: 1680 | return new GlobalDate(currentTime); 1681 | case 1: 1682 | return new GlobalDate(arguments[0]); 1683 | case 2: 1684 | return new GlobalDate(arguments[0], arguments[1]); 1685 | case 3: 1686 | return new GlobalDate(arguments[0], arguments[1], arguments[2]); 1687 | case 4: 1688 | return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3]); 1689 | case 5: 1690 | return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], 1691 | arguments[4]); 1692 | case 6: 1693 | return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], 1694 | arguments[4], arguments[5]); 1695 | default: 1696 | return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], 1697 | arguments[4], arguments[5], arguments[6]); 1698 | } 1699 | } 1700 | 1701 | function createDateProperties() { 1702 | FakeDate.prototype = GlobalDate.prototype; 1703 | 1704 | FakeDate.now = function() { 1705 | if (GlobalDate.now) { 1706 | return currentTime; 1707 | } else { 1708 | throw new Error('Browser does not support Date.now()'); 1709 | } 1710 | }; 1711 | 1712 | FakeDate.toSource = GlobalDate.toSource; 1713 | FakeDate.toString = GlobalDate.toString; 1714 | FakeDate.parse = GlobalDate.parse; 1715 | FakeDate.UTC = GlobalDate.UTC; 1716 | } 1717 | } 1718 | 1719 | return MockDate; 1720 | }; 1721 | 1722 | getJasmineRequireObj().pp = function(j$) { 1723 | 1724 | function PrettyPrinter() { 1725 | this.ppNestLevel_ = 0; 1726 | this.seen = []; 1727 | } 1728 | 1729 | PrettyPrinter.prototype.format = function(value) { 1730 | this.ppNestLevel_++; 1731 | try { 1732 | if (j$.util.isUndefined(value)) { 1733 | this.emitScalar('undefined'); 1734 | } else if (value === null) { 1735 | this.emitScalar('null'); 1736 | } else if (value === 0 && 1/value === -Infinity) { 1737 | this.emitScalar('-0'); 1738 | } else if (value === j$.getGlobal()) { 1739 | this.emitScalar(''); 1740 | } else if (value.jasmineToString) { 1741 | this.emitScalar(value.jasmineToString()); 1742 | } else if (typeof value === 'string') { 1743 | this.emitString(value); 1744 | } else if (j$.isSpy(value)) { 1745 | this.emitScalar('spy on ' + value.and.identity()); 1746 | } else if (value instanceof RegExp) { 1747 | this.emitScalar(value.toString()); 1748 | } else if (typeof value === 'function') { 1749 | this.emitScalar('Function'); 1750 | } else if (typeof value.nodeType === 'number') { 1751 | this.emitScalar('HTMLNode'); 1752 | } else if (value instanceof Date) { 1753 | this.emitScalar('Date(' + value + ')'); 1754 | } else if (value.toString && typeof value === 'object' && !(value instanceof Array) && value.toString !== Object.prototype.toString) { 1755 | this.emitScalar(value.toString()); 1756 | } else if (j$.util.arrayContains(this.seen, value)) { 1757 | this.emitScalar(''); 1758 | } else if (j$.isArray_(value) || j$.isA_('Object', value)) { 1759 | this.seen.push(value); 1760 | if (j$.isArray_(value)) { 1761 | this.emitArray(value); 1762 | } else { 1763 | this.emitObject(value); 1764 | } 1765 | this.seen.pop(); 1766 | } else { 1767 | this.emitScalar(value.toString()); 1768 | } 1769 | } finally { 1770 | this.ppNestLevel_--; 1771 | } 1772 | }; 1773 | 1774 | PrettyPrinter.prototype.iterateObject = function(obj, fn) { 1775 | for (var property in obj) { 1776 | if (!Object.prototype.hasOwnProperty.call(obj, property)) { continue; } 1777 | fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) && 1778 | obj.__lookupGetter__(property) !== null) : false); 1779 | } 1780 | }; 1781 | 1782 | PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_; 1783 | PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_; 1784 | PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_; 1785 | PrettyPrinter.prototype.emitString = j$.unimplementedMethod_; 1786 | 1787 | function StringPrettyPrinter() { 1788 | PrettyPrinter.call(this); 1789 | 1790 | this.string = ''; 1791 | } 1792 | 1793 | j$.util.inherit(StringPrettyPrinter, PrettyPrinter); 1794 | 1795 | StringPrettyPrinter.prototype.emitScalar = function(value) { 1796 | this.append(value); 1797 | }; 1798 | 1799 | StringPrettyPrinter.prototype.emitString = function(value) { 1800 | this.append('\'' + value + '\''); 1801 | }; 1802 | 1803 | StringPrettyPrinter.prototype.emitArray = function(array) { 1804 | if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { 1805 | this.append('Array'); 1806 | return; 1807 | } 1808 | var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); 1809 | this.append('[ '); 1810 | for (var i = 0; i < length; i++) { 1811 | if (i > 0) { 1812 | this.append(', '); 1813 | } 1814 | this.format(array[i]); 1815 | } 1816 | if(array.length > length){ 1817 | this.append(', ...'); 1818 | } 1819 | 1820 | var self = this; 1821 | var first = array.length === 0; 1822 | this.iterateObject(array, function(property, isGetter) { 1823 | if (property.match(/^\d+$/)) { 1824 | return; 1825 | } 1826 | 1827 | if (first) { 1828 | first = false; 1829 | } else { 1830 | self.append(', '); 1831 | } 1832 | 1833 | self.formatProperty(array, property, isGetter); 1834 | }); 1835 | 1836 | this.append(' ]'); 1837 | }; 1838 | 1839 | StringPrettyPrinter.prototype.emitObject = function(obj) { 1840 | var constructorName = obj.constructor ? j$.fnNameFor(obj.constructor) : 'null'; 1841 | this.append(constructorName); 1842 | 1843 | if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { 1844 | return; 1845 | } 1846 | 1847 | var self = this; 1848 | this.append('({ '); 1849 | var first = true; 1850 | 1851 | this.iterateObject(obj, function(property, isGetter) { 1852 | if (first) { 1853 | first = false; 1854 | } else { 1855 | self.append(', '); 1856 | } 1857 | 1858 | self.formatProperty(obj, property, isGetter); 1859 | }); 1860 | 1861 | this.append(' })'); 1862 | }; 1863 | 1864 | StringPrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) { 1865 | this.append(property); 1866 | this.append(': '); 1867 | if (isGetter) { 1868 | this.append(''); 1869 | } else { 1870 | this.format(obj[property]); 1871 | } 1872 | }; 1873 | 1874 | StringPrettyPrinter.prototype.append = function(value) { 1875 | this.string += value; 1876 | }; 1877 | 1878 | return function(value) { 1879 | var stringPrettyPrinter = new StringPrettyPrinter(); 1880 | stringPrettyPrinter.format(value); 1881 | return stringPrettyPrinter.string; 1882 | }; 1883 | }; 1884 | 1885 | getJasmineRequireObj().QueueRunner = function(j$) { 1886 | 1887 | function once(fn) { 1888 | var called = false; 1889 | return function() { 1890 | if (!called) { 1891 | called = true; 1892 | fn(); 1893 | } 1894 | return null; 1895 | }; 1896 | } 1897 | 1898 | function QueueRunner(attrs) { 1899 | this.queueableFns = attrs.queueableFns || []; 1900 | this.onComplete = attrs.onComplete || function() {}; 1901 | this.clearStack = attrs.clearStack || function(fn) {fn();}; 1902 | this.onException = attrs.onException || function() {}; 1903 | this.catchException = attrs.catchException || function() { return true; }; 1904 | this.userContext = attrs.userContext || {}; 1905 | this.timeout = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout}; 1906 | this.fail = attrs.fail || function() {}; 1907 | } 1908 | 1909 | QueueRunner.prototype.execute = function() { 1910 | this.run(this.queueableFns, 0); 1911 | }; 1912 | 1913 | QueueRunner.prototype.run = function(queueableFns, recursiveIndex) { 1914 | var length = queueableFns.length, 1915 | self = this, 1916 | iterativeIndex; 1917 | 1918 | 1919 | for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) { 1920 | var queueableFn = queueableFns[iterativeIndex]; 1921 | if (queueableFn.fn.length > 0) { 1922 | attemptAsync(queueableFn); 1923 | return; 1924 | } else { 1925 | attemptSync(queueableFn); 1926 | } 1927 | } 1928 | 1929 | var runnerDone = iterativeIndex >= length; 1930 | 1931 | if (runnerDone) { 1932 | this.clearStack(this.onComplete); 1933 | } 1934 | 1935 | function attemptSync(queueableFn) { 1936 | try { 1937 | queueableFn.fn.call(self.userContext); 1938 | } catch (e) { 1939 | handleException(e, queueableFn); 1940 | } 1941 | } 1942 | 1943 | function attemptAsync(queueableFn) { 1944 | var clearTimeout = function () { 1945 | Function.prototype.apply.apply(self.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]); 1946 | }, 1947 | next = once(function () { 1948 | clearTimeout(timeoutId); 1949 | self.run(queueableFns, iterativeIndex + 1); 1950 | }), 1951 | timeoutId; 1952 | 1953 | next.fail = function() { 1954 | self.fail.apply(null, arguments); 1955 | next(); 1956 | }; 1957 | 1958 | if (queueableFn.timeout) { 1959 | timeoutId = Function.prototype.apply.apply(self.timeout.setTimeout, [j$.getGlobal(), [function() { 1960 | var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'); 1961 | onException(error); 1962 | next(); 1963 | }, queueableFn.timeout()]]); 1964 | } 1965 | 1966 | try { 1967 | queueableFn.fn.call(self.userContext, next); 1968 | } catch (e) { 1969 | handleException(e, queueableFn); 1970 | next(); 1971 | } 1972 | } 1973 | 1974 | function onException(e) { 1975 | self.onException(e); 1976 | } 1977 | 1978 | function handleException(e, queueableFn) { 1979 | onException(e); 1980 | if (!self.catchException(e)) { 1981 | //TODO: set a var when we catch an exception and 1982 | //use a finally block to close the loop in a nice way.. 1983 | throw e; 1984 | } 1985 | } 1986 | }; 1987 | 1988 | return QueueRunner; 1989 | }; 1990 | 1991 | getJasmineRequireObj().ReportDispatcher = function() { 1992 | function ReportDispatcher(methods) { 1993 | 1994 | var dispatchedMethods = methods || []; 1995 | 1996 | for (var i = 0; i < dispatchedMethods.length; i++) { 1997 | var method = dispatchedMethods[i]; 1998 | this[method] = (function(m) { 1999 | return function() { 2000 | dispatch(m, arguments); 2001 | }; 2002 | }(method)); 2003 | } 2004 | 2005 | var reporters = []; 2006 | var fallbackReporter = null; 2007 | 2008 | this.addReporter = function(reporter) { 2009 | reporters.push(reporter); 2010 | }; 2011 | 2012 | this.provideFallbackReporter = function(reporter) { 2013 | fallbackReporter = reporter; 2014 | }; 2015 | 2016 | 2017 | return this; 2018 | 2019 | function dispatch(method, args) { 2020 | if (reporters.length === 0 && fallbackReporter !== null) { 2021 | reporters.push(fallbackReporter); 2022 | } 2023 | for (var i = 0; i < reporters.length; i++) { 2024 | var reporter = reporters[i]; 2025 | if (reporter[method]) { 2026 | reporter[method].apply(reporter, args); 2027 | } 2028 | } 2029 | } 2030 | } 2031 | 2032 | return ReportDispatcher; 2033 | }; 2034 | 2035 | 2036 | getJasmineRequireObj().SpyRegistry = function(j$) { 2037 | 2038 | var getErrorMsg = j$.formatErrorMsg('', 'spyOn(, )'); 2039 | 2040 | function SpyRegistry(options) { 2041 | options = options || {}; 2042 | var currentSpies = options.currentSpies || function() { return []; }; 2043 | 2044 | this.allowRespy = function(allow){ 2045 | this.respy = allow; 2046 | }; 2047 | 2048 | this.spyOn = function(obj, methodName) { 2049 | 2050 | if (j$.util.isUndefined(obj)) { 2051 | throw new Error(getErrorMsg('could not find an object to spy upon for ' + methodName + '()')); 2052 | } 2053 | 2054 | if (j$.util.isUndefined(methodName)) { 2055 | throw new Error(getErrorMsg('No method name supplied')); 2056 | } 2057 | 2058 | if (j$.util.isUndefined(obj[methodName])) { 2059 | throw new Error(getErrorMsg(methodName + '() method does not exist')); 2060 | } 2061 | 2062 | if (obj[methodName] && j$.isSpy(obj[methodName]) ) { 2063 | if ( !!this.respy ){ 2064 | return obj[methodName]; 2065 | }else { 2066 | throw new Error(getErrorMsg(methodName + ' has already been spied upon')); 2067 | } 2068 | } 2069 | 2070 | var descriptor; 2071 | try { 2072 | descriptor = Object.getOwnPropertyDescriptor(obj, methodName); 2073 | } catch(e) { 2074 | // IE 8 doesn't support `definePropery` on non-DOM nodes 2075 | } 2076 | 2077 | if (descriptor && !(descriptor.writable || descriptor.set)) { 2078 | throw new Error(getErrorMsg(methodName + ' is not declared writable or has no setter')); 2079 | } 2080 | 2081 | var originalMethod = obj[methodName], 2082 | spiedMethod = j$.createSpy(methodName, originalMethod), 2083 | restoreStrategy; 2084 | 2085 | if (Object.prototype.hasOwnProperty.call(obj, methodName)) { 2086 | restoreStrategy = function() { 2087 | obj[methodName] = originalMethod; 2088 | }; 2089 | } else { 2090 | restoreStrategy = function() { 2091 | delete obj[methodName]; 2092 | }; 2093 | } 2094 | 2095 | currentSpies().push({ 2096 | restoreObjectToOriginalState: restoreStrategy 2097 | }); 2098 | 2099 | obj[methodName] = spiedMethod; 2100 | 2101 | return spiedMethod; 2102 | }; 2103 | 2104 | this.clearSpies = function() { 2105 | var spies = currentSpies(); 2106 | for (var i = spies.length - 1; i >= 0; i--) { 2107 | var spyEntry = spies[i]; 2108 | spyEntry.restoreObjectToOriginalState(); 2109 | } 2110 | }; 2111 | } 2112 | 2113 | return SpyRegistry; 2114 | }; 2115 | 2116 | getJasmineRequireObj().SpyStrategy = function() { 2117 | 2118 | function SpyStrategy(options) { 2119 | options = options || {}; 2120 | 2121 | var identity = options.name || 'unknown', 2122 | originalFn = options.fn || function() {}, 2123 | getSpy = options.getSpy || function() {}, 2124 | plan = function() {}; 2125 | 2126 | this.identity = function() { 2127 | return identity; 2128 | }; 2129 | 2130 | this.exec = function() { 2131 | return plan.apply(this, arguments); 2132 | }; 2133 | 2134 | this.callThrough = function() { 2135 | plan = originalFn; 2136 | return getSpy(); 2137 | }; 2138 | 2139 | this.returnValue = function(value) { 2140 | plan = function() { 2141 | return value; 2142 | }; 2143 | return getSpy(); 2144 | }; 2145 | 2146 | this.returnValues = function() { 2147 | var values = Array.prototype.slice.call(arguments); 2148 | plan = function () { 2149 | return values.shift(); 2150 | }; 2151 | return getSpy(); 2152 | }; 2153 | 2154 | this.throwError = function(something) { 2155 | var error = (something instanceof Error) ? something : new Error(something); 2156 | plan = function() { 2157 | throw error; 2158 | }; 2159 | return getSpy(); 2160 | }; 2161 | 2162 | this.callFake = function(fn) { 2163 | if(!(fn instanceof Function)) { 2164 | throw new Error('Argument passed to callFake should be a function, got ' + fn); 2165 | } 2166 | plan = fn; 2167 | return getSpy(); 2168 | }; 2169 | 2170 | this.stub = function(fn) { 2171 | plan = function() {}; 2172 | return getSpy(); 2173 | }; 2174 | } 2175 | 2176 | return SpyStrategy; 2177 | }; 2178 | 2179 | getJasmineRequireObj().Suite = function(j$) { 2180 | function Suite(attrs) { 2181 | this.env = attrs.env; 2182 | this.id = attrs.id; 2183 | this.parentSuite = attrs.parentSuite; 2184 | this.description = attrs.description; 2185 | this.expectationFactory = attrs.expectationFactory; 2186 | this.expectationResultFactory = attrs.expectationResultFactory; 2187 | this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure; 2188 | 2189 | this.beforeFns = []; 2190 | this.afterFns = []; 2191 | this.beforeAllFns = []; 2192 | this.afterAllFns = []; 2193 | this.disabled = false; 2194 | 2195 | this.children = []; 2196 | 2197 | this.result = { 2198 | id: this.id, 2199 | description: this.description, 2200 | fullName: this.getFullName(), 2201 | failedExpectations: [] 2202 | }; 2203 | } 2204 | 2205 | Suite.prototype.expect = function(actual) { 2206 | return this.expectationFactory(actual, this); 2207 | }; 2208 | 2209 | Suite.prototype.getFullName = function() { 2210 | var fullName = []; 2211 | for (var parentSuite = this; parentSuite; parentSuite = parentSuite.parentSuite) { 2212 | if (parentSuite.parentSuite) { 2213 | fullName.unshift(parentSuite.description); 2214 | } 2215 | } 2216 | return fullName.join(' '); 2217 | }; 2218 | 2219 | Suite.prototype.disable = function() { 2220 | this.disabled = true; 2221 | }; 2222 | 2223 | Suite.prototype.pend = function(message) { 2224 | this.markedPending = true; 2225 | }; 2226 | 2227 | Suite.prototype.beforeEach = function(fn) { 2228 | this.beforeFns.unshift(fn); 2229 | }; 2230 | 2231 | Suite.prototype.beforeAll = function(fn) { 2232 | this.beforeAllFns.push(fn); 2233 | }; 2234 | 2235 | Suite.prototype.afterEach = function(fn) { 2236 | this.afterFns.unshift(fn); 2237 | }; 2238 | 2239 | Suite.prototype.afterAll = function(fn) { 2240 | this.afterAllFns.push(fn); 2241 | }; 2242 | 2243 | Suite.prototype.addChild = function(child) { 2244 | this.children.push(child); 2245 | }; 2246 | 2247 | Suite.prototype.status = function() { 2248 | if (this.disabled) { 2249 | return 'disabled'; 2250 | } 2251 | 2252 | if (this.markedPending) { 2253 | return 'pending'; 2254 | } 2255 | 2256 | if (this.result.failedExpectations.length > 0) { 2257 | return 'failed'; 2258 | } else { 2259 | return 'finished'; 2260 | } 2261 | }; 2262 | 2263 | Suite.prototype.isExecutable = function() { 2264 | return !this.disabled; 2265 | }; 2266 | 2267 | Suite.prototype.canBeReentered = function() { 2268 | return this.beforeAllFns.length === 0 && this.afterAllFns.length === 0; 2269 | }; 2270 | 2271 | Suite.prototype.getResult = function() { 2272 | this.result.status = this.status(); 2273 | return this.result; 2274 | }; 2275 | 2276 | Suite.prototype.sharedUserContext = function() { 2277 | if (!this.sharedContext) { 2278 | this.sharedContext = this.parentSuite ? clone(this.parentSuite.sharedUserContext()) : {}; 2279 | } 2280 | 2281 | return this.sharedContext; 2282 | }; 2283 | 2284 | Suite.prototype.clonedSharedUserContext = function() { 2285 | return clone(this.sharedUserContext()); 2286 | }; 2287 | 2288 | Suite.prototype.onException = function() { 2289 | if (arguments[0] instanceof j$.errors.ExpectationFailed) { 2290 | return; 2291 | } 2292 | 2293 | if(isAfterAll(this.children)) { 2294 | var data = { 2295 | matcherName: '', 2296 | passed: false, 2297 | expected: '', 2298 | actual: '', 2299 | error: arguments[0] 2300 | }; 2301 | this.result.failedExpectations.push(this.expectationResultFactory(data)); 2302 | } else { 2303 | for (var i = 0; i < this.children.length; i++) { 2304 | var child = this.children[i]; 2305 | child.onException.apply(child, arguments); 2306 | } 2307 | } 2308 | }; 2309 | 2310 | Suite.prototype.addExpectationResult = function () { 2311 | if(isAfterAll(this.children) && isFailure(arguments)){ 2312 | var data = arguments[1]; 2313 | this.result.failedExpectations.push(this.expectationResultFactory(data)); 2314 | if(this.throwOnExpectationFailure) { 2315 | throw new j$.errors.ExpectationFailed(); 2316 | } 2317 | } else { 2318 | for (var i = 0; i < this.children.length; i++) { 2319 | var child = this.children[i]; 2320 | try { 2321 | child.addExpectationResult.apply(child, arguments); 2322 | } catch(e) { 2323 | // keep going 2324 | } 2325 | } 2326 | } 2327 | }; 2328 | 2329 | function isAfterAll(children) { 2330 | return children && children[0].result.status; 2331 | } 2332 | 2333 | function isFailure(args) { 2334 | return !args[0]; 2335 | } 2336 | 2337 | function clone(obj) { 2338 | var clonedObj = {}; 2339 | for (var prop in obj) { 2340 | if (obj.hasOwnProperty(prop)) { 2341 | clonedObj[prop] = obj[prop]; 2342 | } 2343 | } 2344 | 2345 | return clonedObj; 2346 | } 2347 | 2348 | return Suite; 2349 | }; 2350 | 2351 | if (typeof window == void 0 && typeof exports == 'object') { 2352 | exports.Suite = jasmineRequire.Suite; 2353 | } 2354 | 2355 | getJasmineRequireObj().Timer = function() { 2356 | var defaultNow = (function(Date) { 2357 | return function() { return new Date().getTime(); }; 2358 | })(Date); 2359 | 2360 | function Timer(options) { 2361 | options = options || {}; 2362 | 2363 | var now = options.now || defaultNow, 2364 | startTime; 2365 | 2366 | this.start = function() { 2367 | startTime = now(); 2368 | }; 2369 | 2370 | this.elapsed = function() { 2371 | return now() - startTime; 2372 | }; 2373 | } 2374 | 2375 | return Timer; 2376 | }; 2377 | 2378 | getJasmineRequireObj().TreeProcessor = function() { 2379 | function TreeProcessor(attrs) { 2380 | var tree = attrs.tree, 2381 | runnableIds = attrs.runnableIds, 2382 | queueRunnerFactory = attrs.queueRunnerFactory, 2383 | nodeStart = attrs.nodeStart || function() {}, 2384 | nodeComplete = attrs.nodeComplete || function() {}, 2385 | orderChildren = attrs.orderChildren || function(node) { return node.children; }, 2386 | stats = { valid: true }, 2387 | processed = false, 2388 | defaultMin = Infinity, 2389 | defaultMax = 1 - Infinity; 2390 | 2391 | this.processTree = function() { 2392 | processNode(tree, false); 2393 | processed = true; 2394 | return stats; 2395 | }; 2396 | 2397 | this.execute = function(done) { 2398 | if (!processed) { 2399 | this.processTree(); 2400 | } 2401 | 2402 | if (!stats.valid) { 2403 | throw 'invalid order'; 2404 | } 2405 | 2406 | var childFns = wrapChildren(tree, 0); 2407 | 2408 | queueRunnerFactory({ 2409 | queueableFns: childFns, 2410 | userContext: tree.sharedUserContext(), 2411 | onException: function() { 2412 | tree.onException.apply(tree, arguments); 2413 | }, 2414 | onComplete: done 2415 | }); 2416 | }; 2417 | 2418 | function runnableIndex(id) { 2419 | for (var i = 0; i < runnableIds.length; i++) { 2420 | if (runnableIds[i] === id) { 2421 | return i; 2422 | } 2423 | } 2424 | } 2425 | 2426 | function processNode(node, parentEnabled) { 2427 | var executableIndex = runnableIndex(node.id); 2428 | 2429 | if (executableIndex !== undefined) { 2430 | parentEnabled = true; 2431 | } 2432 | 2433 | parentEnabled = parentEnabled && node.isExecutable(); 2434 | 2435 | if (!node.children) { 2436 | stats[node.id] = { 2437 | executable: parentEnabled && node.isExecutable(), 2438 | segments: [{ 2439 | index: 0, 2440 | owner: node, 2441 | nodes: [node], 2442 | min: startingMin(executableIndex), 2443 | max: startingMax(executableIndex) 2444 | }] 2445 | }; 2446 | } else { 2447 | var hasExecutableChild = false; 2448 | 2449 | var orderedChildren = orderChildren(node); 2450 | 2451 | for (var i = 0; i < orderedChildren.length; i++) { 2452 | var child = orderedChildren[i]; 2453 | 2454 | processNode(child, parentEnabled); 2455 | 2456 | if (!stats.valid) { 2457 | return; 2458 | } 2459 | 2460 | var childStats = stats[child.id]; 2461 | 2462 | hasExecutableChild = hasExecutableChild || childStats.executable; 2463 | } 2464 | 2465 | stats[node.id] = { 2466 | executable: hasExecutableChild 2467 | }; 2468 | 2469 | segmentChildren(node, orderedChildren, stats[node.id], executableIndex); 2470 | 2471 | if (!node.canBeReentered() && stats[node.id].segments.length > 1) { 2472 | stats = { valid: false }; 2473 | } 2474 | } 2475 | } 2476 | 2477 | function startingMin(executableIndex) { 2478 | return executableIndex === undefined ? defaultMin : executableIndex; 2479 | } 2480 | 2481 | function startingMax(executableIndex) { 2482 | return executableIndex === undefined ? defaultMax : executableIndex; 2483 | } 2484 | 2485 | function segmentChildren(node, orderedChildren, nodeStats, executableIndex) { 2486 | var currentSegment = { index: 0, owner: node, nodes: [], min: startingMin(executableIndex), max: startingMax(executableIndex) }, 2487 | result = [currentSegment], 2488 | lastMax = defaultMax, 2489 | orderedChildSegments = orderChildSegments(orderedChildren); 2490 | 2491 | function isSegmentBoundary(minIndex) { 2492 | return lastMax !== defaultMax && minIndex !== defaultMin && lastMax < minIndex - 1; 2493 | } 2494 | 2495 | for (var i = 0; i < orderedChildSegments.length; i++) { 2496 | var childSegment = orderedChildSegments[i], 2497 | maxIndex = childSegment.max, 2498 | minIndex = childSegment.min; 2499 | 2500 | if (isSegmentBoundary(minIndex)) { 2501 | currentSegment = {index: result.length, owner: node, nodes: [], min: defaultMin, max: defaultMax}; 2502 | result.push(currentSegment); 2503 | } 2504 | 2505 | currentSegment.nodes.push(childSegment); 2506 | currentSegment.min = Math.min(currentSegment.min, minIndex); 2507 | currentSegment.max = Math.max(currentSegment.max, maxIndex); 2508 | lastMax = maxIndex; 2509 | } 2510 | 2511 | nodeStats.segments = result; 2512 | } 2513 | 2514 | function orderChildSegments(children) { 2515 | var specifiedOrder = [], 2516 | unspecifiedOrder = []; 2517 | 2518 | for (var i = 0; i < children.length; i++) { 2519 | var child = children[i], 2520 | segments = stats[child.id].segments; 2521 | 2522 | for (var j = 0; j < segments.length; j++) { 2523 | var seg = segments[j]; 2524 | 2525 | if (seg.min === defaultMin) { 2526 | unspecifiedOrder.push(seg); 2527 | } else { 2528 | specifiedOrder.push(seg); 2529 | } 2530 | } 2531 | } 2532 | 2533 | specifiedOrder.sort(function(a, b) { 2534 | return a.min - b.min; 2535 | }); 2536 | 2537 | return specifiedOrder.concat(unspecifiedOrder); 2538 | } 2539 | 2540 | function executeNode(node, segmentNumber) { 2541 | if (node.children) { 2542 | return { 2543 | fn: function(done) { 2544 | nodeStart(node); 2545 | 2546 | queueRunnerFactory({ 2547 | onComplete: function() { 2548 | nodeComplete(node, node.getResult()); 2549 | done(); 2550 | }, 2551 | queueableFns: wrapChildren(node, segmentNumber), 2552 | userContext: node.sharedUserContext(), 2553 | onException: function() { 2554 | node.onException.apply(node, arguments); 2555 | } 2556 | }); 2557 | } 2558 | }; 2559 | } else { 2560 | return { 2561 | fn: function(done) { node.execute(done, stats[node.id].executable); } 2562 | }; 2563 | } 2564 | } 2565 | 2566 | function wrapChildren(node, segmentNumber) { 2567 | var result = [], 2568 | segmentChildren = stats[node.id].segments[segmentNumber].nodes; 2569 | 2570 | for (var i = 0; i < segmentChildren.length; i++) { 2571 | result.push(executeNode(segmentChildren[i].owner, segmentChildren[i].index)); 2572 | } 2573 | 2574 | if (!stats[node.id].executable) { 2575 | return result; 2576 | } 2577 | 2578 | return node.beforeAllFns.concat(result).concat(node.afterAllFns); 2579 | } 2580 | } 2581 | 2582 | return TreeProcessor; 2583 | }; 2584 | 2585 | getJasmineRequireObj().Any = function(j$) { 2586 | 2587 | function Any(expectedObject) { 2588 | if (typeof expectedObject === 'undefined') { 2589 | throw new TypeError( 2590 | 'jasmine.any() expects to be passed a constructor function. ' + 2591 | 'Please pass one or use jasmine.anything() to match any object.' 2592 | ); 2593 | } 2594 | this.expectedObject = expectedObject; 2595 | } 2596 | 2597 | Any.prototype.asymmetricMatch = function(other) { 2598 | if (this.expectedObject == String) { 2599 | return typeof other == 'string' || other instanceof String; 2600 | } 2601 | 2602 | if (this.expectedObject == Number) { 2603 | return typeof other == 'number' || other instanceof Number; 2604 | } 2605 | 2606 | if (this.expectedObject == Function) { 2607 | return typeof other == 'function' || other instanceof Function; 2608 | } 2609 | 2610 | if (this.expectedObject == Object) { 2611 | return typeof other == 'object'; 2612 | } 2613 | 2614 | if (this.expectedObject == Boolean) { 2615 | return typeof other == 'boolean'; 2616 | } 2617 | 2618 | return other instanceof this.expectedObject; 2619 | }; 2620 | 2621 | Any.prototype.jasmineToString = function() { 2622 | return ''; 2623 | }; 2624 | 2625 | return Any; 2626 | }; 2627 | 2628 | getJasmineRequireObj().Anything = function(j$) { 2629 | 2630 | function Anything() {} 2631 | 2632 | Anything.prototype.asymmetricMatch = function(other) { 2633 | return !j$.util.isUndefined(other) && other !== null; 2634 | }; 2635 | 2636 | Anything.prototype.jasmineToString = function() { 2637 | return ''; 2638 | }; 2639 | 2640 | return Anything; 2641 | }; 2642 | 2643 | getJasmineRequireObj().ArrayContaining = function(j$) { 2644 | function ArrayContaining(sample) { 2645 | this.sample = sample; 2646 | } 2647 | 2648 | ArrayContaining.prototype.asymmetricMatch = function(other) { 2649 | var className = Object.prototype.toString.call(this.sample); 2650 | if (className !== '[object Array]') { throw new Error('You must provide an array to arrayContaining, not \'' + this.sample + '\'.'); } 2651 | 2652 | for (var i = 0; i < this.sample.length; i++) { 2653 | var item = this.sample[i]; 2654 | if (!j$.matchersUtil.contains(other, item)) { 2655 | return false; 2656 | } 2657 | } 2658 | 2659 | return true; 2660 | }; 2661 | 2662 | ArrayContaining.prototype.jasmineToString = function () { 2663 | return ''; 2664 | }; 2665 | 2666 | return ArrayContaining; 2667 | }; 2668 | 2669 | getJasmineRequireObj().ObjectContaining = function(j$) { 2670 | 2671 | function ObjectContaining(sample) { 2672 | this.sample = sample; 2673 | } 2674 | 2675 | function getPrototype(obj) { 2676 | if (Object.getPrototypeOf) { 2677 | return Object.getPrototypeOf(obj); 2678 | } 2679 | 2680 | if (obj.constructor.prototype == obj) { 2681 | return null; 2682 | } 2683 | 2684 | return obj.constructor.prototype; 2685 | } 2686 | 2687 | function hasProperty(obj, property) { 2688 | if (!obj) { 2689 | return false; 2690 | } 2691 | 2692 | if (Object.prototype.hasOwnProperty.call(obj, property)) { 2693 | return true; 2694 | } 2695 | 2696 | return hasProperty(getPrototype(obj), property); 2697 | } 2698 | 2699 | ObjectContaining.prototype.asymmetricMatch = function(other) { 2700 | if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); } 2701 | 2702 | for (var property in this.sample) { 2703 | if (!hasProperty(other, property) || 2704 | !j$.matchersUtil.equals(this.sample[property], other[property])) { 2705 | return false; 2706 | } 2707 | } 2708 | 2709 | return true; 2710 | }; 2711 | 2712 | ObjectContaining.prototype.jasmineToString = function() { 2713 | return ''; 2714 | }; 2715 | 2716 | return ObjectContaining; 2717 | }; 2718 | 2719 | getJasmineRequireObj().StringMatching = function(j$) { 2720 | 2721 | function StringMatching(expected) { 2722 | if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) { 2723 | throw new Error('Expected is not a String or a RegExp'); 2724 | } 2725 | 2726 | this.regexp = new RegExp(expected); 2727 | } 2728 | 2729 | StringMatching.prototype.asymmetricMatch = function(other) { 2730 | return this.regexp.test(other); 2731 | }; 2732 | 2733 | StringMatching.prototype.jasmineToString = function() { 2734 | return ''; 2735 | }; 2736 | 2737 | return StringMatching; 2738 | }; 2739 | 2740 | getJasmineRequireObj().errors = function() { 2741 | function ExpectationFailed() {} 2742 | 2743 | ExpectationFailed.prototype = new Error(); 2744 | ExpectationFailed.prototype.constructor = ExpectationFailed; 2745 | 2746 | return { 2747 | ExpectationFailed: ExpectationFailed 2748 | }; 2749 | }; 2750 | getJasmineRequireObj().formatErrorMsg = function() { 2751 | function generateErrorMsg(domain, usage) { 2752 | var usageDefinition = usage ? '\nUsage: ' + usage : ''; 2753 | 2754 | return function errorMsg(msg) { 2755 | return domain + ' : ' + msg + usageDefinition; 2756 | }; 2757 | } 2758 | 2759 | return generateErrorMsg; 2760 | }; 2761 | 2762 | getJasmineRequireObj().matchersUtil = function(j$) { 2763 | // TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter? 2764 | 2765 | return { 2766 | equals: function(a, b, customTesters) { 2767 | customTesters = customTesters || []; 2768 | 2769 | return eq(a, b, [], [], customTesters); 2770 | }, 2771 | 2772 | contains: function(haystack, needle, customTesters) { 2773 | customTesters = customTesters || []; 2774 | 2775 | if ((Object.prototype.toString.apply(haystack) === '[object Array]') || 2776 | (!!haystack && !haystack.indexOf)) 2777 | { 2778 | for (var i = 0; i < haystack.length; i++) { 2779 | if (eq(haystack[i], needle, [], [], customTesters)) { 2780 | return true; 2781 | } 2782 | } 2783 | return false; 2784 | } 2785 | 2786 | return !!haystack && haystack.indexOf(needle) >= 0; 2787 | }, 2788 | 2789 | buildFailureMessage: function() { 2790 | var args = Array.prototype.slice.call(arguments, 0), 2791 | matcherName = args[0], 2792 | isNot = args[1], 2793 | actual = args[2], 2794 | expected = args.slice(3), 2795 | englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); 2796 | 2797 | var message = 'Expected ' + 2798 | j$.pp(actual) + 2799 | (isNot ? ' not ' : ' ') + 2800 | englishyPredicate; 2801 | 2802 | if (expected.length > 0) { 2803 | for (var i = 0; i < expected.length; i++) { 2804 | if (i > 0) { 2805 | message += ','; 2806 | } 2807 | message += ' ' + j$.pp(expected[i]); 2808 | } 2809 | } 2810 | 2811 | return message + '.'; 2812 | } 2813 | }; 2814 | 2815 | function isAsymmetric(obj) { 2816 | return obj && j$.isA_('Function', obj.asymmetricMatch); 2817 | } 2818 | 2819 | function asymmetricMatch(a, b) { 2820 | var asymmetricA = isAsymmetric(a), 2821 | asymmetricB = isAsymmetric(b); 2822 | 2823 | if (asymmetricA && asymmetricB) { 2824 | return undefined; 2825 | } 2826 | 2827 | if (asymmetricA) { 2828 | return a.asymmetricMatch(b); 2829 | } 2830 | 2831 | if (asymmetricB) { 2832 | return b.asymmetricMatch(a); 2833 | } 2834 | } 2835 | 2836 | // Equality function lovingly adapted from isEqual in 2837 | // [Underscore](http://underscorejs.org) 2838 | function eq(a, b, aStack, bStack, customTesters) { 2839 | var result = true; 2840 | 2841 | var asymmetricResult = asymmetricMatch(a, b); 2842 | if (!j$.util.isUndefined(asymmetricResult)) { 2843 | return asymmetricResult; 2844 | } 2845 | 2846 | for (var i = 0; i < customTesters.length; i++) { 2847 | var customTesterResult = customTesters[i](a, b); 2848 | if (!j$.util.isUndefined(customTesterResult)) { 2849 | return customTesterResult; 2850 | } 2851 | } 2852 | 2853 | if (a instanceof Error && b instanceof Error) { 2854 | return a.message == b.message; 2855 | } 2856 | 2857 | // Identical objects are equal. `0 === -0`, but they aren't identical. 2858 | // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). 2859 | if (a === b) { return a !== 0 || 1 / a == 1 / b; } 2860 | // A strict comparison is necessary because `null == undefined`. 2861 | if (a === null || b === null) { return a === b; } 2862 | var className = Object.prototype.toString.call(a); 2863 | if (className != Object.prototype.toString.call(b)) { return false; } 2864 | switch (className) { 2865 | // Strings, numbers, dates, and booleans are compared by value. 2866 | case '[object String]': 2867 | // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is 2868 | // equivalent to `new String("5")`. 2869 | return a == String(b); 2870 | case '[object Number]': 2871 | // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for 2872 | // other numeric values. 2873 | return a != +a ? b != +b : (a === 0 ? 1 / a == 1 / b : a == +b); 2874 | case '[object Date]': 2875 | case '[object Boolean]': 2876 | // Coerce dates and booleans to numeric primitive values. Dates are compared by their 2877 | // millisecond representations. Note that invalid dates with millisecond representations 2878 | // of `NaN` are not equivalent. 2879 | return +a == +b; 2880 | // RegExps are compared by their source patterns and flags. 2881 | case '[object RegExp]': 2882 | return a.source == b.source && 2883 | a.global == b.global && 2884 | a.multiline == b.multiline && 2885 | a.ignoreCase == b.ignoreCase; 2886 | } 2887 | if (typeof a != 'object' || typeof b != 'object') { return false; } 2888 | 2889 | var aIsDomNode = j$.isDomNode(a); 2890 | var bIsDomNode = j$.isDomNode(b); 2891 | if (aIsDomNode && bIsDomNode) { 2892 | // At first try to use DOM3 method isEqualNode 2893 | if (a.isEqualNode) { 2894 | return a.isEqualNode(b); 2895 | } 2896 | // IE8 doesn't support isEqualNode, try to use outerHTML && innerText 2897 | var aIsElement = a instanceof Element; 2898 | var bIsElement = b instanceof Element; 2899 | if (aIsElement && bIsElement) { 2900 | return a.outerHTML == b.outerHTML; 2901 | } 2902 | if (aIsElement || bIsElement) { 2903 | return false; 2904 | } 2905 | return a.innerText == b.innerText && a.textContent == b.textContent; 2906 | } 2907 | if (aIsDomNode || bIsDomNode) { 2908 | return false; 2909 | } 2910 | 2911 | // Assume equality for cyclic structures. The algorithm for detecting cyclic 2912 | // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. 2913 | var length = aStack.length; 2914 | while (length--) { 2915 | // Linear search. Performance is inversely proportional to the number of 2916 | // unique nested structures. 2917 | if (aStack[length] == a) { return bStack[length] == b; } 2918 | } 2919 | // Add the first object to the stack of traversed objects. 2920 | aStack.push(a); 2921 | bStack.push(b); 2922 | var size = 0; 2923 | // Recursively compare objects and arrays. 2924 | // Compare array lengths to determine if a deep comparison is necessary. 2925 | if (className == '[object Array]') { 2926 | size = a.length; 2927 | if (size !== b.length) { 2928 | return false; 2929 | } 2930 | 2931 | while (size--) { 2932 | result = eq(a[size], b[size], aStack, bStack, customTesters); 2933 | if (!result) { 2934 | return false; 2935 | } 2936 | } 2937 | } else { 2938 | 2939 | // Objects with different constructors are not equivalent, but `Object`s 2940 | // or `Array`s from different frames are. 2941 | var aCtor = a.constructor, bCtor = b.constructor; 2942 | if (aCtor !== bCtor && !(isObjectConstructor(aCtor) && 2943 | isObjectConstructor(bCtor))) { 2944 | return false; 2945 | } 2946 | } 2947 | 2948 | // Deep compare objects. 2949 | var aKeys = keys(a, className == '[object Array]'), key; 2950 | size = aKeys.length; 2951 | 2952 | // Ensure that both objects contain the same number of properties before comparing deep equality. 2953 | if (keys(b, className == '[object Array]').length !== size) { return false; } 2954 | 2955 | while (size--) { 2956 | key = aKeys[size]; 2957 | // Deep compare each member 2958 | result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters); 2959 | 2960 | if (!result) { 2961 | return false; 2962 | } 2963 | } 2964 | // Remove the first object from the stack of traversed objects. 2965 | aStack.pop(); 2966 | bStack.pop(); 2967 | 2968 | return result; 2969 | 2970 | function keys(obj, isArray) { 2971 | var allKeys = Object.keys ? Object.keys(obj) : 2972 | (function(o) { 2973 | var keys = []; 2974 | for (var key in o) { 2975 | if (has(o, key)) { 2976 | keys.push(key); 2977 | } 2978 | } 2979 | return keys; 2980 | })(obj); 2981 | 2982 | if (!isArray) { 2983 | return allKeys; 2984 | } 2985 | 2986 | var extraKeys = []; 2987 | for (var i in allKeys) { 2988 | if (!allKeys[i].match(/^[0-9]+$/)) { 2989 | extraKeys.push(allKeys[i]); 2990 | } 2991 | } 2992 | 2993 | return extraKeys; 2994 | } 2995 | } 2996 | 2997 | function has(obj, key) { 2998 | return Object.prototype.hasOwnProperty.call(obj, key); 2999 | } 3000 | 3001 | function isFunction(obj) { 3002 | return typeof obj === 'function'; 3003 | } 3004 | 3005 | function isObjectConstructor(ctor) { 3006 | // aCtor instanceof aCtor is true for the Object and Function 3007 | // constructors (since a constructor is-a Function and a function is-a 3008 | // Object). We don't just compare ctor === Object because the constructor 3009 | // might come from a different frame with different globals. 3010 | return isFunction(ctor) && ctor instanceof ctor; 3011 | } 3012 | }; 3013 | 3014 | getJasmineRequireObj().toBe = function() { 3015 | function toBe() { 3016 | return { 3017 | compare: function(actual, expected) { 3018 | return { 3019 | pass: actual === expected 3020 | }; 3021 | } 3022 | }; 3023 | } 3024 | 3025 | return toBe; 3026 | }; 3027 | 3028 | getJasmineRequireObj().toBeCloseTo = function() { 3029 | 3030 | function toBeCloseTo() { 3031 | return { 3032 | compare: function(actual, expected, precision) { 3033 | if (precision !== 0) { 3034 | precision = precision || 2; 3035 | } 3036 | 3037 | return { 3038 | pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2) 3039 | }; 3040 | } 3041 | }; 3042 | } 3043 | 3044 | return toBeCloseTo; 3045 | }; 3046 | 3047 | getJasmineRequireObj().toBeDefined = function() { 3048 | function toBeDefined() { 3049 | return { 3050 | compare: function(actual) { 3051 | return { 3052 | pass: (void 0 !== actual) 3053 | }; 3054 | } 3055 | }; 3056 | } 3057 | 3058 | return toBeDefined; 3059 | }; 3060 | 3061 | getJasmineRequireObj().toBeFalsy = function() { 3062 | function toBeFalsy() { 3063 | return { 3064 | compare: function(actual) { 3065 | return { 3066 | pass: !!!actual 3067 | }; 3068 | } 3069 | }; 3070 | } 3071 | 3072 | return toBeFalsy; 3073 | }; 3074 | 3075 | getJasmineRequireObj().toBeGreaterThan = function() { 3076 | 3077 | function toBeGreaterThan() { 3078 | return { 3079 | compare: function(actual, expected) { 3080 | return { 3081 | pass: actual > expected 3082 | }; 3083 | } 3084 | }; 3085 | } 3086 | 3087 | return toBeGreaterThan; 3088 | }; 3089 | 3090 | 3091 | getJasmineRequireObj().toBeGreaterThanOrEqual = function() { 3092 | 3093 | function toBeGreaterThanOrEqual() { 3094 | return { 3095 | compare: function(actual, expected) { 3096 | return { 3097 | pass: actual >= expected 3098 | }; 3099 | } 3100 | }; 3101 | } 3102 | 3103 | return toBeGreaterThanOrEqual; 3104 | }; 3105 | 3106 | getJasmineRequireObj().toBeLessThan = function() { 3107 | function toBeLessThan() { 3108 | return { 3109 | 3110 | compare: function(actual, expected) { 3111 | return { 3112 | pass: actual < expected 3113 | }; 3114 | } 3115 | }; 3116 | } 3117 | 3118 | return toBeLessThan; 3119 | }; 3120 | getJasmineRequireObj().toBeLessThanOrEqual = function() { 3121 | function toBeLessThanOrEqual() { 3122 | return { 3123 | 3124 | compare: function(actual, expected) { 3125 | return { 3126 | pass: actual <= expected 3127 | }; 3128 | } 3129 | }; 3130 | } 3131 | 3132 | return toBeLessThanOrEqual; 3133 | }; 3134 | 3135 | getJasmineRequireObj().toBeNaN = function(j$) { 3136 | 3137 | function toBeNaN() { 3138 | return { 3139 | compare: function(actual) { 3140 | var result = { 3141 | pass: (actual !== actual) 3142 | }; 3143 | 3144 | if (result.pass) { 3145 | result.message = 'Expected actual not to be NaN.'; 3146 | } else { 3147 | result.message = function() { return 'Expected ' + j$.pp(actual) + ' to be NaN.'; }; 3148 | } 3149 | 3150 | return result; 3151 | } 3152 | }; 3153 | } 3154 | 3155 | return toBeNaN; 3156 | }; 3157 | 3158 | getJasmineRequireObj().toBeNull = function() { 3159 | 3160 | function toBeNull() { 3161 | return { 3162 | compare: function(actual) { 3163 | return { 3164 | pass: actual === null 3165 | }; 3166 | } 3167 | }; 3168 | } 3169 | 3170 | return toBeNull; 3171 | }; 3172 | 3173 | getJasmineRequireObj().toBeTruthy = function() { 3174 | 3175 | function toBeTruthy() { 3176 | return { 3177 | compare: function(actual) { 3178 | return { 3179 | pass: !!actual 3180 | }; 3181 | } 3182 | }; 3183 | } 3184 | 3185 | return toBeTruthy; 3186 | }; 3187 | 3188 | getJasmineRequireObj().toBeUndefined = function() { 3189 | 3190 | function toBeUndefined() { 3191 | return { 3192 | compare: function(actual) { 3193 | return { 3194 | pass: void 0 === actual 3195 | }; 3196 | } 3197 | }; 3198 | } 3199 | 3200 | return toBeUndefined; 3201 | }; 3202 | 3203 | getJasmineRequireObj().toContain = function() { 3204 | function toContain(util, customEqualityTesters) { 3205 | customEqualityTesters = customEqualityTesters || []; 3206 | 3207 | return { 3208 | compare: function(actual, expected) { 3209 | 3210 | return { 3211 | pass: util.contains(actual, expected, customEqualityTesters) 3212 | }; 3213 | } 3214 | }; 3215 | } 3216 | 3217 | return toContain; 3218 | }; 3219 | 3220 | getJasmineRequireObj().toEqual = function() { 3221 | 3222 | function toEqual(util, customEqualityTesters) { 3223 | customEqualityTesters = customEqualityTesters || []; 3224 | 3225 | return { 3226 | compare: function(actual, expected) { 3227 | var result = { 3228 | pass: false 3229 | }; 3230 | 3231 | result.pass = util.equals(actual, expected, customEqualityTesters); 3232 | 3233 | return result; 3234 | } 3235 | }; 3236 | } 3237 | 3238 | return toEqual; 3239 | }; 3240 | 3241 | getJasmineRequireObj().toHaveBeenCalled = function(j$) { 3242 | 3243 | var getErrorMsg = j$.formatErrorMsg('', 'expect().toHaveBeenCalled()'); 3244 | 3245 | function toHaveBeenCalled() { 3246 | return { 3247 | compare: function(actual) { 3248 | var result = {}; 3249 | 3250 | if (!j$.isSpy(actual)) { 3251 | throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(actual) + '.')); 3252 | } 3253 | 3254 | if (arguments.length > 1) { 3255 | throw new Error(getErrorMsg('Does not take arguments, use toHaveBeenCalledWith')); 3256 | } 3257 | 3258 | result.pass = actual.calls.any(); 3259 | 3260 | result.message = result.pass ? 3261 | 'Expected spy ' + actual.and.identity() + ' not to have been called.' : 3262 | 'Expected spy ' + actual.and.identity() + ' to have been called.'; 3263 | 3264 | return result; 3265 | } 3266 | }; 3267 | } 3268 | 3269 | return toHaveBeenCalled; 3270 | }; 3271 | 3272 | getJasmineRequireObj().toHaveBeenCalledTimes = function(j$) { 3273 | 3274 | var getErrorMsg = j$.formatErrorMsg('', 'expect().toHaveBeenCalledTimes()'); 3275 | 3276 | function toHaveBeenCalledTimes() { 3277 | return { 3278 | compare: function(actual, expected) { 3279 | if (!j$.isSpy(actual)) { 3280 | throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(actual) + '.')); 3281 | } 3282 | 3283 | var args = Array.prototype.slice.call(arguments, 0), 3284 | result = { pass: false }; 3285 | 3286 | if (!j$.isNumber_(expected)){ 3287 | throw new Error(getErrorMsg('The expected times failed is a required argument and must be a number.')); 3288 | } 3289 | 3290 | actual = args[0]; 3291 | var calls = actual.calls.count(); 3292 | var timesMessage = expected === 1 ? 'once' : expected + ' times'; 3293 | result.pass = calls === expected; 3294 | result.message = result.pass ? 3295 | 'Expected spy ' + actual.and.identity() + ' not to have been called ' + timesMessage + '. It was called ' + calls + ' times.' : 3296 | 'Expected spy ' + actual.and.identity() + ' to have been called ' + timesMessage + '. It was called ' + calls + ' times.'; 3297 | return result; 3298 | } 3299 | }; 3300 | } 3301 | 3302 | return toHaveBeenCalledTimes; 3303 | }; 3304 | 3305 | getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { 3306 | 3307 | var getErrorMsg = j$.formatErrorMsg('', 'expect().toHaveBeenCalledWith(...arguments)'); 3308 | 3309 | function toHaveBeenCalledWith(util, customEqualityTesters) { 3310 | return { 3311 | compare: function() { 3312 | var args = Array.prototype.slice.call(arguments, 0), 3313 | actual = args[0], 3314 | expectedArgs = args.slice(1), 3315 | result = { pass: false }; 3316 | 3317 | if (!j$.isSpy(actual)) { 3318 | throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(actual) + '.')); 3319 | } 3320 | 3321 | if (!actual.calls.any()) { 3322 | result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; }; 3323 | return result; 3324 | } 3325 | 3326 | if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) { 3327 | result.pass = true; 3328 | result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; }; 3329 | } else { 3330 | result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; }; 3331 | } 3332 | 3333 | return result; 3334 | } 3335 | }; 3336 | } 3337 | 3338 | return toHaveBeenCalledWith; 3339 | }; 3340 | 3341 | getJasmineRequireObj().toMatch = function(j$) { 3342 | 3343 | var getErrorMsg = j$.formatErrorMsg('', 'expect().toMatch( || )'); 3344 | 3345 | function toMatch() { 3346 | return { 3347 | compare: function(actual, expected) { 3348 | if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) { 3349 | throw new Error(getErrorMsg('Expected is not a String or a RegExp')); 3350 | } 3351 | 3352 | var regexp = new RegExp(expected); 3353 | 3354 | return { 3355 | pass: regexp.test(actual) 3356 | }; 3357 | } 3358 | }; 3359 | } 3360 | 3361 | return toMatch; 3362 | }; 3363 | 3364 | getJasmineRequireObj().toThrow = function(j$) { 3365 | 3366 | var getErrorMsg = j$.formatErrorMsg('', 'expect(function() {}).toThrow()'); 3367 | 3368 | function toThrow(util) { 3369 | return { 3370 | compare: function(actual, expected) { 3371 | var result = { pass: false }, 3372 | threw = false, 3373 | thrown; 3374 | 3375 | if (typeof actual != 'function') { 3376 | throw new Error(getErrorMsg('Actual is not a Function')); 3377 | } 3378 | 3379 | try { 3380 | actual(); 3381 | } catch (e) { 3382 | threw = true; 3383 | thrown = e; 3384 | } 3385 | 3386 | if (!threw) { 3387 | result.message = 'Expected function to throw an exception.'; 3388 | return result; 3389 | } 3390 | 3391 | if (arguments.length == 1) { 3392 | result.pass = true; 3393 | result.message = function() { return 'Expected function not to throw, but it threw ' + j$.pp(thrown) + '.'; }; 3394 | 3395 | return result; 3396 | } 3397 | 3398 | if (util.equals(thrown, expected)) { 3399 | result.pass = true; 3400 | result.message = function() { return 'Expected function not to throw ' + j$.pp(expected) + '.'; }; 3401 | } else { 3402 | result.message = function() { return 'Expected function to throw ' + j$.pp(expected) + ', but it threw ' + j$.pp(thrown) + '.'; }; 3403 | } 3404 | 3405 | return result; 3406 | } 3407 | }; 3408 | } 3409 | 3410 | return toThrow; 3411 | }; 3412 | 3413 | getJasmineRequireObj().toThrowError = function(j$) { 3414 | 3415 | var getErrorMsg = j$.formatErrorMsg('', 'expect(function() {}).toThrowError(, )'); 3416 | 3417 | function toThrowError () { 3418 | return { 3419 | compare: function(actual) { 3420 | var threw = false, 3421 | pass = {pass: true}, 3422 | fail = {pass: false}, 3423 | thrown; 3424 | 3425 | if (typeof actual != 'function') { 3426 | throw new Error(getErrorMsg('Actual is not a Function')); 3427 | } 3428 | 3429 | var errorMatcher = getMatcher.apply(null, arguments); 3430 | 3431 | try { 3432 | actual(); 3433 | } catch (e) { 3434 | threw = true; 3435 | thrown = e; 3436 | } 3437 | 3438 | if (!threw) { 3439 | fail.message = 'Expected function to throw an Error.'; 3440 | return fail; 3441 | } 3442 | 3443 | if (!(thrown instanceof Error)) { 3444 | fail.message = function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; }; 3445 | return fail; 3446 | } 3447 | 3448 | if (errorMatcher.hasNoSpecifics()) { 3449 | pass.message = 'Expected function not to throw an Error, but it threw ' + j$.fnNameFor(thrown) + '.'; 3450 | return pass; 3451 | } 3452 | 3453 | if (errorMatcher.matches(thrown)) { 3454 | pass.message = function() { 3455 | return 'Expected function not to throw ' + errorMatcher.errorTypeDescription + errorMatcher.messageDescription() + '.'; 3456 | }; 3457 | return pass; 3458 | } else { 3459 | fail.message = function() { 3460 | return 'Expected function to throw ' + errorMatcher.errorTypeDescription + errorMatcher.messageDescription() + 3461 | ', but it threw ' + errorMatcher.thrownDescription(thrown) + '.'; 3462 | }; 3463 | return fail; 3464 | } 3465 | } 3466 | }; 3467 | 3468 | function getMatcher() { 3469 | var expected = null, 3470 | errorType = null; 3471 | 3472 | if (arguments.length == 2) { 3473 | expected = arguments[1]; 3474 | if (isAnErrorType(expected)) { 3475 | errorType = expected; 3476 | expected = null; 3477 | } 3478 | } else if (arguments.length > 2) { 3479 | errorType = arguments[1]; 3480 | expected = arguments[2]; 3481 | if (!isAnErrorType(errorType)) { 3482 | throw new Error(getErrorMsg('Expected error type is not an Error.')); 3483 | } 3484 | } 3485 | 3486 | if (expected && !isStringOrRegExp(expected)) { 3487 | if (errorType) { 3488 | throw new Error(getErrorMsg('Expected error message is not a string or RegExp.')); 3489 | } else { 3490 | throw new Error(getErrorMsg('Expected is not an Error, string, or RegExp.')); 3491 | } 3492 | } 3493 | 3494 | function messageMatch(message) { 3495 | if (typeof expected == 'string') { 3496 | return expected == message; 3497 | } else { 3498 | return expected.test(message); 3499 | } 3500 | } 3501 | 3502 | return { 3503 | errorTypeDescription: errorType ? j$.fnNameFor(errorType) : 'an exception', 3504 | thrownDescription: function(thrown) { 3505 | var thrownName = errorType ? j$.fnNameFor(thrown.constructor) : 'an exception', 3506 | thrownMessage = ''; 3507 | 3508 | if (expected) { 3509 | thrownMessage = ' with message ' + j$.pp(thrown.message); 3510 | } 3511 | 3512 | return thrownName + thrownMessage; 3513 | }, 3514 | messageDescription: function() { 3515 | if (expected === null) { 3516 | return ''; 3517 | } else if (expected instanceof RegExp) { 3518 | return ' with a message matching ' + j$.pp(expected); 3519 | } else { 3520 | return ' with message ' + j$.pp(expected); 3521 | } 3522 | }, 3523 | hasNoSpecifics: function() { 3524 | return expected === null && errorType === null; 3525 | }, 3526 | matches: function(error) { 3527 | return (errorType === null || error instanceof errorType) && 3528 | (expected === null || messageMatch(error.message)); 3529 | } 3530 | }; 3531 | } 3532 | 3533 | function isStringOrRegExp(potential) { 3534 | return potential instanceof RegExp || (typeof potential == 'string'); 3535 | } 3536 | 3537 | function isAnErrorType(type) { 3538 | if (typeof type !== 'function') { 3539 | return false; 3540 | } 3541 | 3542 | var Surrogate = function() {}; 3543 | Surrogate.prototype = type.prototype; 3544 | return (new Surrogate()) instanceof Error; 3545 | } 3546 | } 3547 | 3548 | return toThrowError; 3549 | }; 3550 | 3551 | getJasmineRequireObj().interface = function(jasmine, env) { 3552 | var jasmineInterface = { 3553 | describe: function(description, specDefinitions) { 3554 | return env.describe(description, specDefinitions); 3555 | }, 3556 | 3557 | xdescribe: function(description, specDefinitions) { 3558 | return env.xdescribe(description, specDefinitions); 3559 | }, 3560 | 3561 | fdescribe: function(description, specDefinitions) { 3562 | return env.fdescribe(description, specDefinitions); 3563 | }, 3564 | 3565 | it: function() { 3566 | return env.it.apply(env, arguments); 3567 | }, 3568 | 3569 | xit: function() { 3570 | return env.xit.apply(env, arguments); 3571 | }, 3572 | 3573 | fit: function() { 3574 | return env.fit.apply(env, arguments); 3575 | }, 3576 | 3577 | beforeEach: function() { 3578 | return env.beforeEach.apply(env, arguments); 3579 | }, 3580 | 3581 | afterEach: function() { 3582 | return env.afterEach.apply(env, arguments); 3583 | }, 3584 | 3585 | beforeAll: function() { 3586 | return env.beforeAll.apply(env, arguments); 3587 | }, 3588 | 3589 | afterAll: function() { 3590 | return env.afterAll.apply(env, arguments); 3591 | }, 3592 | 3593 | expect: function(actual) { 3594 | return env.expect(actual); 3595 | }, 3596 | 3597 | pending: function() { 3598 | return env.pending.apply(env, arguments); 3599 | }, 3600 | 3601 | fail: function() { 3602 | return env.fail.apply(env, arguments); 3603 | }, 3604 | 3605 | spyOn: function(obj, methodName) { 3606 | return env.spyOn(obj, methodName); 3607 | }, 3608 | 3609 | jsApiReporter: new jasmine.JsApiReporter({ 3610 | timer: new jasmine.Timer() 3611 | }), 3612 | 3613 | jasmine: jasmine 3614 | }; 3615 | 3616 | jasmine.addCustomEqualityTester = function(tester) { 3617 | env.addCustomEqualityTester(tester); 3618 | }; 3619 | 3620 | jasmine.addMatchers = function(matchers) { 3621 | return env.addMatchers(matchers); 3622 | }; 3623 | 3624 | jasmine.clock = function() { 3625 | return env.clock; 3626 | }; 3627 | 3628 | return jasmineInterface; 3629 | }; 3630 | 3631 | getJasmineRequireObj().version = function() { 3632 | return '2.5.0'; 3633 | }; 3634 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/json2.js: -------------------------------------------------------------------------------- 1 | /* 2 | json2.js 3 | 2014-02-04 4 | 5 | Public Domain. 6 | 7 | NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. 8 | 9 | See http://www.JSON.org/js.html 10 | 11 | 12 | This code should be minified before deployment. 13 | See http://javascript.crockford.com/jsmin.html 14 | 15 | USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO 16 | NOT CONTROL. 17 | 18 | 19 | This file creates a global JSON object containing two methods: stringify 20 | and parse. 21 | 22 | JSON.stringify(value, replacer, space) 23 | value any JavaScript value, usually an object or array. 24 | 25 | replacer an optional parameter that determines how object 26 | values are stringified for objects. It can be a 27 | function or an array of strings. 28 | 29 | space an optional parameter that specifies the indentation 30 | of nested structures. If it is omitted, the text will 31 | be packed without extra whitespace. If it is a number, 32 | it will specify the number of spaces to indent at each 33 | level. If it is a string (such as '\t' or ' '), 34 | it contains the characters used to indent at each level. 35 | 36 | This method produces a JSON text from a JavaScript value. 37 | 38 | When an object value is found, if the object contains a toJSON 39 | method, its toJSON method will be called and the result will be 40 | stringified. A toJSON method does not serialize: it returns the 41 | value represented by the name/value pair that should be serialized, 42 | or undefined if nothing should be serialized. The toJSON method 43 | will be passed the key associated with the value, and this will be 44 | bound to the value 45 | 46 | For example, this would serialize Dates as ISO strings. 47 | 48 | Date.prototype.toJSON = function (key) { 49 | function f(n) { 50 | // Format integers to have at least two digits. 51 | return n < 10 ? '0' + n : n; 52 | } 53 | 54 | return this.getUTCFullYear() + '-' + 55 | f(this.getUTCMonth() + 1) + '-' + 56 | f(this.getUTCDate()) + 'T' + 57 | f(this.getUTCHours()) + ':' + 58 | f(this.getUTCMinutes()) + ':' + 59 | f(this.getUTCSeconds()) + 'Z'; 60 | }; 61 | 62 | You can provide an optional replacer method. It will be passed the 63 | key and value of each member, with this bound to the containing 64 | object. The value that is returned from your method will be 65 | serialized. If your method returns undefined, then the member will 66 | be excluded from the serialization. 67 | 68 | If the replacer parameter is an array of strings, then it will be 69 | used to select the members to be serialized. It filters the results 70 | such that only members with keys listed in the replacer array are 71 | stringified. 72 | 73 | Values that do not have JSON representations, such as undefined or 74 | functions, will not be serialized. Such values in objects will be 75 | dropped; in arrays they will be replaced with null. You can use 76 | a replacer function to replace those with JSON values. 77 | JSON.stringify(undefined) returns undefined. 78 | 79 | The optional space parameter produces a stringification of the 80 | value that is filled with line breaks and indentation to make it 81 | easier to read. 82 | 83 | If the space parameter is a non-empty string, then that string will 84 | be used for indentation. If the space parameter is a number, then 85 | the indentation will be that many spaces. 86 | 87 | Example: 88 | 89 | text = JSON.stringify(['e', {pluribus: 'unum'}]); 90 | // text is '["e",{"pluribus":"unum"}]' 91 | 92 | 93 | text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); 94 | // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' 95 | 96 | text = JSON.stringify([new Date()], function (key, value) { 97 | return this[key] instanceof Date ? 98 | 'Date(' + this[key] + ')' : value; 99 | }); 100 | // text is '["Date(---current time---)"]' 101 | 102 | 103 | JSON.parse(text, reviver) 104 | This method parses a JSON text to produce an object or array. 105 | It can throw a SyntaxError exception. 106 | 107 | The optional reviver parameter is a function that can filter and 108 | transform the results. It receives each of the keys and values, 109 | and its return value is used instead of the original value. 110 | If it returns what it received, then the structure is not modified. 111 | If it returns undefined then the member is deleted. 112 | 113 | Example: 114 | 115 | // Parse the text. Values that look like ISO date strings will 116 | // be converted to Date objects. 117 | 118 | myData = JSON.parse(text, function (key, value) { 119 | var a; 120 | if (typeof value === 'string') { 121 | a = 122 | /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); 123 | if (a) { 124 | return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], 125 | +a[5], +a[6])); 126 | } 127 | } 128 | return value; 129 | }); 130 | 131 | myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { 132 | var d; 133 | if (typeof value === 'string' && 134 | value.slice(0, 5) === 'Date(' && 135 | value.slice(-1) === ')') { 136 | d = new Date(value.slice(5, -1)); 137 | if (d) { 138 | return d; 139 | } 140 | } 141 | return value; 142 | }); 143 | 144 | 145 | This is a reference implementation. You are free to copy, modify, or 146 | redistribute. 147 | */ 148 | 149 | /*jslint evil: true, regexp: true */ 150 | 151 | /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, 152 | call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, 153 | getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, 154 | lastIndex, length, parse, prototype, push, replace, slice, stringify, 155 | test, toJSON, toString, valueOf 156 | */ 157 | 158 | 159 | // Create a JSON object only if one does not already exist. We create the 160 | // methods in a closure to avoid creating global variables. 161 | 162 | if (typeof JSON !== 'object') { 163 | JSON = {}; 164 | } 165 | 166 | (function () { 167 | 'use strict'; 168 | 169 | function f(n) { 170 | // Format integers to have at least two digits. 171 | return n < 10 ? '0' + n : n; 172 | } 173 | 174 | if (typeof Date.prototype.toJSON !== 'function') { 175 | 176 | Date.prototype.toJSON = function () { 177 | 178 | return isFinite(this.valueOf()) 179 | ? this.getUTCFullYear() + '-' + 180 | f(this.getUTCMonth() + 1) + '-' + 181 | f(this.getUTCDate()) + 'T' + 182 | f(this.getUTCHours()) + ':' + 183 | f(this.getUTCMinutes()) + ':' + 184 | f(this.getUTCSeconds()) + 'Z' 185 | : null; 186 | }; 187 | 188 | String.prototype.toJSON = 189 | Number.prototype.toJSON = 190 | Boolean.prototype.toJSON = function () { 191 | return this.valueOf(); 192 | }; 193 | } 194 | 195 | var cx, 196 | escapable, 197 | gap, 198 | indent, 199 | meta, 200 | rep; 201 | 202 | 203 | function quote(string) { 204 | 205 | // If the string contains no control characters, no quote characters, and no 206 | // backslash characters, then we can safely slap some quotes around it. 207 | // Otherwise we must also replace the offending characters with safe escape 208 | // sequences. 209 | 210 | escapable.lastIndex = 0; 211 | return escapable.test(string) ? '"' + string.replace(escapable, function (a) { 212 | var c = meta[a]; 213 | return typeof c === 'string' 214 | ? c 215 | : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); 216 | }) + '"' : '"' + string + '"'; 217 | } 218 | 219 | 220 | function str(key, holder) { 221 | 222 | // Produce a string from holder[key]. 223 | 224 | var i, // The loop counter. 225 | k, // The member key. 226 | v, // The member value. 227 | length, 228 | mind = gap, 229 | partial, 230 | value = holder[key]; 231 | 232 | // If the value has a toJSON method, call it to obtain a replacement value. 233 | 234 | if (value && typeof value === 'object' && 235 | typeof value.toJSON === 'function') { 236 | value = value.toJSON(key); 237 | } 238 | 239 | // If we were called with a replacer function, then call the replacer to 240 | // obtain a replacement value. 241 | 242 | if (typeof rep === 'function') { 243 | value = rep.call(holder, key, value); 244 | } 245 | 246 | // What happens next depends on the value's type. 247 | 248 | switch (typeof value) { 249 | case 'string': 250 | return quote(value); 251 | 252 | case 'number': 253 | 254 | // JSON numbers must be finite. Encode non-finite numbers as null. 255 | 256 | return isFinite(value) ? String(value) : 'null'; 257 | 258 | case 'boolean': 259 | case 'null': 260 | 261 | // If the value is a boolean or null, convert it to a string. Note: 262 | // typeof null does not produce 'null'. The case is included here in 263 | // the remote chance that this gets fixed someday. 264 | 265 | return String(value); 266 | 267 | // If the type is 'object', we might be dealing with an object or an array or 268 | // null. 269 | 270 | case 'object': 271 | 272 | // Due to a specification blunder in ECMAScript, typeof null is 'object', 273 | // so watch out for that case. 274 | 275 | if (!value) { 276 | return 'null'; 277 | } 278 | 279 | // Make an array to hold the partial results of stringifying this object value. 280 | 281 | gap += indent; 282 | partial = []; 283 | 284 | // Is the value an array? 285 | 286 | if (Object.prototype.toString.apply(value) === '[object Array]') { 287 | 288 | // The value is an array. Stringify every element. Use null as a placeholder 289 | // for non-JSON values. 290 | 291 | length = value.length; 292 | for (i = 0; i < length; i += 1) { 293 | partial[i] = str(i, value) || 'null'; 294 | } 295 | 296 | // Join all of the elements together, separated with commas, and wrap them in 297 | // brackets. 298 | 299 | v = partial.length === 0 300 | ? '[]' 301 | : gap 302 | ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' 303 | : '[' + partial.join(',') + ']'; 304 | gap = mind; 305 | return v; 306 | } 307 | 308 | // If the replacer is an array, use it to select the members to be stringified. 309 | 310 | if (rep && typeof rep === 'object') { 311 | length = rep.length; 312 | for (i = 0; i < length; i += 1) { 313 | if (typeof rep[i] === 'string') { 314 | k = rep[i]; 315 | v = str(k, value); 316 | if (v) { 317 | partial.push(quote(k) + (gap ? ': ' : ':') + v); 318 | } 319 | } 320 | } 321 | } else { 322 | 323 | // Otherwise, iterate through all of the keys in the object. 324 | 325 | for (k in value) { 326 | if (Object.prototype.hasOwnProperty.call(value, k)) { 327 | v = str(k, value); 328 | if (v) { 329 | partial.push(quote(k) + (gap ? ': ' : ':') + v); 330 | } 331 | } 332 | } 333 | } 334 | 335 | // Join all of the member texts together, separated with commas, 336 | // and wrap them in braces. 337 | 338 | v = partial.length === 0 339 | ? '{}' 340 | : gap 341 | ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' 342 | : '{' + partial.join(',') + '}'; 343 | gap = mind; 344 | return v; 345 | } 346 | } 347 | 348 | // If the JSON object does not yet have a stringify method, give it one. 349 | 350 | if (typeof JSON.stringify !== 'function') { 351 | escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; 352 | meta = { // table of character substitutions 353 | '\b': '\\b', 354 | '\t': '\\t', 355 | '\n': '\\n', 356 | '\f': '\\f', 357 | '\r': '\\r', 358 | '"' : '\\"', 359 | '\\': '\\\\' 360 | }; 361 | JSON.stringify = function (value, replacer, space) { 362 | 363 | // The stringify method takes a value and an optional replacer, and an optional 364 | // space parameter, and returns a JSON text. The replacer can be a function 365 | // that can replace values, or an array of strings that will select the keys. 366 | // A default replacer method can be provided. Use of the space parameter can 367 | // produce text that is more easily readable. 368 | 369 | var i; 370 | gap = ''; 371 | indent = ''; 372 | 373 | // If the space parameter is a number, make an indent string containing that 374 | // many spaces. 375 | 376 | if (typeof space === 'number') { 377 | for (i = 0; i < space; i += 1) { 378 | indent += ' '; 379 | } 380 | 381 | // If the space parameter is a string, it will be used as the indent string. 382 | 383 | } else if (typeof space === 'string') { 384 | indent = space; 385 | } 386 | 387 | // If there is a replacer, it must be a function or an array. 388 | // Otherwise, throw an error. 389 | 390 | rep = replacer; 391 | if (replacer && typeof replacer !== 'function' && 392 | (typeof replacer !== 'object' || 393 | typeof replacer.length !== 'number')) { 394 | throw new Error('JSON.stringify'); 395 | } 396 | 397 | // Make a fake root object containing our value under the key of ''. 398 | // Return the result of stringifying the value. 399 | 400 | return str('', {'': value}); 401 | }; 402 | } 403 | 404 | 405 | // If the JSON object does not yet have a parse method, give it one. 406 | 407 | if (typeof JSON.parse !== 'function') { 408 | cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; 409 | JSON.parse = function (text, reviver) { 410 | 411 | // The parse method takes a text and an optional reviver function, and returns 412 | // a JavaScript value if the text is a valid JSON text. 413 | 414 | var j; 415 | 416 | function walk(holder, key) { 417 | 418 | // The walk method is used to recursively walk the resulting structure so 419 | // that modifications can be made. 420 | 421 | var k, v, value = holder[key]; 422 | if (value && typeof value === 'object') { 423 | for (k in value) { 424 | if (Object.prototype.hasOwnProperty.call(value, k)) { 425 | v = walk(value, k); 426 | if (v !== undefined) { 427 | value[k] = v; 428 | } else { 429 | delete value[k]; 430 | } 431 | } 432 | } 433 | } 434 | return reviver.call(holder, key, value); 435 | } 436 | 437 | 438 | // Parsing happens in four stages. In the first stage, we replace certain 439 | // Unicode characters with escape sequences. JavaScript handles many characters 440 | // incorrectly, either silently deleting them, or treating them as line endings. 441 | 442 | text = String(text); 443 | cx.lastIndex = 0; 444 | if (cx.test(text)) { 445 | text = text.replace(cx, function (a) { 446 | return '\\u' + 447 | ('0000' + a.charCodeAt(0).toString(16)).slice(-4); 448 | }); 449 | } 450 | 451 | // In the second stage, we run the text against regular expressions that look 452 | // for non-JSON patterns. We are especially concerned with '()' and 'new' 453 | // because they can cause invocation, and '=' because it can cause mutation. 454 | // But just to be safe, we want to reject all unexpected forms. 455 | 456 | // We split the second stage into 4 regexp operations in order to work around 457 | // crippling inefficiencies in IE's and Safari's regexp engines. First we 458 | // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we 459 | // replace all simple value tokens with ']' characters. Third, we delete all 460 | // open brackets that follow a colon or comma or that begin the text. Finally, 461 | // we look to see that the remaining characters are only whitespace or ']' or 462 | // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. 463 | 464 | if (/^[\],:{}\s]*$/ 465 | .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@') 466 | .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') 467 | .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { 468 | 469 | // In the third stage we use the eval function to compile the text into a 470 | // JavaScript structure. The '{' operator is subject to a syntactic ambiguity 471 | // in JavaScript: it can begin a block or an object literal. We wrap the text 472 | // in parens to eliminate the ambiguity. 473 | 474 | j = eval('(' + text + ')'); 475 | 476 | // In the optional fourth stage, we recursively walk the new structure, passing 477 | // each name/value pair to a reviver function for possible transformation. 478 | 479 | return typeof reviver === 'function' 480 | ? walk({'': j}, '') 481 | : j; 482 | } 483 | 484 | // If the text is not JSON parseable, then a SyntaxError is thrown. 485 | 486 | throw new SyntaxError('JSON.parse'); 487 | }; 488 | } 489 | }()); 490 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/node_boot.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2016 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | module.exports = function(jasmineRequire) { 24 | var jasmine = jasmineRequire.core(jasmineRequire); 25 | 26 | var consoleFns = require('../console/console.js'); 27 | consoleFns.console(consoleFns, jasmine); 28 | 29 | var env = jasmine.getEnv(); 30 | 31 | var jasmineInterface = jasmineRequire.interface(jasmine, env); 32 | 33 | extend(global, jasmineInterface); 34 | 35 | function extend(destination, source) { 36 | for (var property in source) destination[property] = source[property]; 37 | return destination; 38 | } 39 | 40 | return jasmine; 41 | }; 42 | -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/spec: -------------------------------------------------------------------------------- 1 | ../../spec -------------------------------------------------------------------------------- /jasmine-lib/jasmine-core/version.rb: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT Edit this file. Canonical version of Jasmine lives in the repo's package.json. This file is generated 3 | # by a grunt task when the standalone release is built. 4 | # 5 | module Jasmine 6 | module Core 7 | VERSION = "2.5.0" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /night-mode.js: -------------------------------------------------------------------------------- 1 | function isNumberInOpenInterval(number, min, max) { 2 | return number >= min 3 | && number <= max; 4 | } 5 | var DayTime = (function () { 6 | function DayTime(hour, minute) { 7 | if (isNumberInOpenInterval(hour, 0, 23) 8 | && isNumberInOpenInterval(minute, 0, 59)) { 9 | this.hour = hour; 10 | this.minute = minute; 11 | } 12 | else { 13 | throw new RangeError("Incorrect time set: " + hour + ":" + minute); 14 | } 15 | } 16 | DayTime.hasValidStructure = function (text) { 17 | return /^\d{1,2}:\d{2}$/.test(text); 18 | }; 19 | DayTime.fromString = function (time) { 20 | if (DayTime.hasValidStructure(time)) { 21 | var splitTime = time.split(":"); 22 | return new DayTime(Number(splitTime[0]), Number(splitTime[1])); 23 | } 24 | else { 25 | throw new Error("Given value " + time + " didn't match expected format HH:mm"); 26 | } 27 | }; 28 | DayTime.fromCurrentTime = function () { 29 | var now = new Date(); 30 | return new DayTime(now.getHours(), now.getMinutes()); 31 | }; 32 | DayTime.prototype.isAfter = function (dayTime) { 33 | return (this.hour > dayTime.hour 34 | || (this.hour === dayTime.hour && this.minute > dayTime.minute)); 35 | }; 36 | return DayTime; 37 | }()); 38 | var NightMode = (function () { 39 | function NightMode(options) { 40 | if (options === void 0) { options = {}; } 41 | this.evening = options.evening instanceof DayTime ? options.evening : new DayTime(21, 0); 42 | this.morning = options.morning instanceof DayTime ? options.morning : new DayTime(6, 0); 43 | this.refreshIntervalInSeconds = (typeof options.refreshIntervalInSeconds === 'number') ? options.refreshIntervalInSeconds : 20; 44 | this.cssNightClassName = (typeof options.cssNightClassName === 'string') ? options.cssNightClassName : 'night'; 45 | if (options.autoSwitch !== false) { 46 | this.enableAutoSwitch(); 47 | } 48 | } 49 | NightMode.prototype.isNight = function () { 50 | var now = DayTime.fromCurrentTime(); 51 | return this.morning.isAfter(now) || !this.evening.isAfter(now); 52 | }; 53 | NightMode.prototype.syncBodyClassWithCurrentTime = function () { 54 | if (this.isNight()) { 55 | document.body.classList.add(this.cssNightClassName); 56 | } 57 | else { 58 | document.body.classList.remove(this.cssNightClassName); 59 | } 60 | }; 61 | NightMode.prototype.enableAutoSwitch = function () { 62 | var _this = this; 63 | this.syncBodyClassWithCurrentTime(); 64 | this.autoSwitchTimeoutIntervalID = setInterval(function () { return _this.syncBodyClassWithCurrentTime(); }, this.refreshIntervalInSeconds * 1000); 65 | }; 66 | NightMode.prototype.disableAutoSwitch = function () { 67 | clearInterval(this.autoSwitchTimeoutIntervalID); 68 | }; 69 | return NightMode; 70 | }()); 71 | //# sourceMappingURL=night-mode.js.map -------------------------------------------------------------------------------- /night-mode.js.map: -------------------------------------------------------------------------------- 1 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AC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnE,CAAC;IAED,gDAA4B,GAA5B;QACI,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACjB,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACxD,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC3D,CAAC;IACL,CAAC;IAED,oCAAgB,GAAhB;QAAA,iBAMC;QALG,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,IAAI,CAAC,2BAA2B,GAAG,WAAW,CAC1C,cAAM,OAAA,KAAI,CAAC,4BAA4B,EAAE,EAAnC,CAAmC,EACzC,IAAI,CAAC,wBAAwB,GAAG,IAAI,CACvC,CAAC;IACN,CAAC;IAED,qCAAiB,GAAjB;QACI,aAAa,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IACpD,CAAC;IAEL,gBAAC;AAAD,CAAC,AA1CD,IA0CC"} -------------------------------------------------------------------------------- /night-mode.min.js: -------------------------------------------------------------------------------- 1 | function isNumberInOpenInterval(c,b,a){return c>=b&&c<=a}var DayTime=(function(){function a(b,c){if(isNumberInOpenInterval(b,0,23)&&isNumberInOpenInterval(c,0,59)){this.hour=b;this.minute=c}else{throw new RangeError("Incorrect time set: "+b+":"+c)}}a.hasValidStructure=function(b){return/^\d{1,2}:\d{2}$/.test(b)};a.fromString=function(c){if(a.hasValidStructure(c)){var b=c.split(":");return new a(Number(b[0]),Number(b[1]))}else{throw new Error("Given value "+c+" didn't match expected format HH:mm")}};a.fromCurrentTime=function(){var b=new Date();return new a(b.getHours(),b.getMinutes())};a.prototype.isAfter=function(b){return(this.hour>b.hour||(this.hour===b.hour&&this.minute>b.minute))};return a}());var NightMode=(function(){function a(b){if(b===void 0){b={}}this.evening=b.evening instanceof DayTime?b.evening:new DayTime(21,0);this.morning=b.morning instanceof DayTime?b.morning:new DayTime(6,0);this.refreshIntervalInSeconds=(typeof b.refreshIntervalInSeconds==="number")?b.refreshIntervalInSeconds:20;this.nightClass=(typeof b.nightClass==="string")?b.nightClass:"night";if(b.shouldAutoswitch!==false){this.enableAutoSwitch()}}a.prototype.isNight=function(){var b=DayTime.fromCurrentTime();return this.morning.isAfter(b)||!this.evening.isAfter(b)};a.prototype.checkBodyClass=function(){if(this.isNight()){document.body.classList.add(this.nightClass)}else{document.body.classList.remove(this.nightClass)}};a.prototype.enableAutoSwitch=function(){var b=this;this.checkBodyClass();this.autoSwitchTimeoutIntervalID=setInterval(function(){return b.checkBodyClass()},this.refreshIntervalInSeconds*1000)};a.prototype.disableAutoSwitch=function(){clearInterval(this.autoSwitchTimeoutIntervalID)};return a}()); -------------------------------------------------------------------------------- /night-mode.ts: -------------------------------------------------------------------------------- 1 | function isNumberInOpenInterval(number: number, min: number, max: number) { 2 | return number >= min 3 | && number <= max; 4 | } 5 | 6 | class DayTime { 7 | 8 | hour: number; 9 | minute: number; 10 | 11 | private static hasValidStructure(text: string): boolean { 12 | return /^\d{1,2}:\d{2}$/.test(text); 13 | } 14 | 15 | constructor(hour: number, minute: number) { 16 | if (isNumberInOpenInterval(hour, 0, 23) 17 | && isNumberInOpenInterval(minute, 0, 59)) { 18 | this.hour = hour; 19 | this.minute = minute; 20 | } else { 21 | throw new RangeError("Incorrect time set: " + hour + ":" + minute); 22 | } 23 | } 24 | 25 | static fromString(time: string): DayTime { 26 | if (DayTime.hasValidStructure(time)) { 27 | let splitTime = time.split(":"); 28 | return new DayTime(Number(splitTime[0]), Number(splitTime[1])); 29 | } else { 30 | throw new Error("Given value " + time + " didn't match expected format HH:mm"); 31 | } 32 | } 33 | 34 | static fromCurrentTime(): DayTime { 35 | let now = new Date(); 36 | return new DayTime(now.getHours(), now.getMinutes()); 37 | } 38 | 39 | isAfter(dayTime: DayTime): boolean { 40 | return (this.hour > dayTime.hour 41 | || (this.hour === dayTime.hour && this.minute > dayTime.minute)); 42 | } 43 | 44 | } 45 | 46 | class NightMode { 47 | evening: DayTime; 48 | morning: DayTime; 49 | refreshIntervalInSeconds: number; 50 | cssNightClassName: string; 51 | autoSwitchTimeoutIntervalID: number; 52 | 53 | constructor(options: any = {}) { 54 | this.evening = options.evening instanceof DayTime ? options.evening : new DayTime(21, 0); 55 | this.morning = options.morning instanceof DayTime ? options.morning : new DayTime(6, 0); 56 | this.refreshIntervalInSeconds = (typeof options.refreshIntervalInSeconds === 'number') ? options.refreshIntervalInSeconds : 20; 57 | this.cssNightClassName = (typeof options.cssNightClassName === 'string') ? options.cssNightClassName : 'night'; 58 | if (options.autoSwitch !== false) { 59 | this.enableAutoSwitch(); 60 | } 61 | } 62 | 63 | isNight(): boolean { 64 | let now = DayTime.fromCurrentTime(); 65 | return this.morning.isAfter(now) || !this.evening.isAfter(now); 66 | } 67 | 68 | syncBodyClassWithCurrentTime(): void { 69 | if (this.isNight()) { 70 | document.body.classList.add(this.cssNightClassName); 71 | } else { 72 | document.body.classList.remove(this.cssNightClassName); 73 | } 74 | } 75 | 76 | enableAutoSwitch(): void { 77 | this.syncBodyClassWithCurrentTime(); 78 | this.autoSwitchTimeoutIntervalID = setInterval( 79 | () => this.syncBodyClassWithCurrentTime(), 80 | this.refreshIntervalInSeconds * 1000 81 | ); 82 | } 83 | 84 | disableAutoSwitch(): void { 85 | clearInterval(this.autoSwitchTimeoutIntervalID); 86 | } 87 | 88 | } -------------------------------------------------------------------------------- /test-runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Unit tests for NightModeJs 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /unit-tests.js: -------------------------------------------------------------------------------- 1 | describe("DayTime factory static function fromString", function() { 2 | 3 | it("should create new object for valid time", function() { 4 | expect(function(){DayTime.fromString("21:30")}).not.toThrow(); 5 | expect(function(){DayTime.fromString("00:00")}).not.toThrow(); 6 | expect(function(){DayTime.fromString("23:59")}).not.toThrow(); 7 | }); 8 | 9 | it("should throw Error if the time has invalid structure", function() { 10 | expect(function(){DayTime.fromString("Aa:30")}).toThrow(jasmine.any(Error)); 11 | expect(function(){DayTime.fromString("1546")}).toThrow(jasmine.any(Error)); 12 | expect(function(){DayTime.fromString("112:54")}).toThrow(jasmine.any(Error)); 13 | }); 14 | 15 | it("should throw RangeError if the hour is over 23", function() { 16 | expect(function(){DayTime.fromString("24:30")}).toThrow(jasmine.any(RangeError)); 17 | expect(function(){DayTime.fromString("46:00")}).toThrow(jasmine.any(RangeError)); 18 | }); 19 | 20 | it("should throw RangeError if the minute is over 59", function() { 21 | expect(function(){DayTime.fromString("20:60")}).toThrow(jasmine.any(RangeError)); 22 | expect(function(){DayTime.fromString("05:84")}).toThrow(jasmine.any(RangeError)); 23 | }); 24 | 25 | }); 26 | 27 | describe("DayTime isAfter function", function() { 28 | 29 | it("should return true if the given argument is after", function() { 30 | expect(DayTime.fromString("20:30").isAfter(DayTime.fromString("20:00"))).toBe(true); 31 | }); 32 | 33 | it("should return false if the given argument is before", function() { 34 | expect(DayTime.fromString("15:00").isAfter(DayTime.fromString("20:00"))).toBe(false); 35 | }); 36 | 37 | it("should return false if the given argument is the same time", function() { 38 | expect(DayTime.fromString("20:30").isAfter(DayTime.fromString("20:30"))).toBe(false); 39 | }); 40 | 41 | }); 42 | 43 | describe("isNumberInOpenInterval", function() { 44 | 45 | it("should return true if the given argument is inside the interval", function() { 46 | expect(isNumberInOpenInterval(10, 0, 20)).toBe(true); 47 | }); 48 | 49 | it("should return true if the given argument is the same as one of the interval endpoints", function() { 50 | expect(isNumberInOpenInterval(0, 0, 20)).toBe(true); 51 | expect(isNumberInOpenInterval(20, 0, 20)).toBe(true); 52 | }); 53 | 54 | it("should return false if the given argument is outside the interval", function() { 55 | expect(isNumberInOpenInterval(-10, 0, 20)).toBe(false); 56 | }); 57 | 58 | }); 59 | 60 | describe("NightMode isNight function", function() { 61 | 62 | var nightMode; 63 | 64 | beforeEach(function() { 65 | nightMode = new NightMode({ 66 | evening: new DayTime(22, 0), 67 | morning: new DayTime(6, 30), 68 | autoSwitch: false 69 | }); 70 | }); 71 | 72 | it("should return true if current time is after the evening", function() { 73 | DayTime.fromCurrentTime = function() { 74 | return new DayTime(23,30); 75 | }; 76 | expect(nightMode.isNight()).toBe(true); 77 | }); 78 | 79 | it("should return false if current time is before the morning", function() { 80 | DayTime.fromCurrentTime = function() { 81 | return new DayTime(6,20); 82 | }; 83 | expect(nightMode.isNight()).toBe(true); 84 | }); 85 | 86 | it("should return false if current time is between the morning and the evening", function() { 87 | DayTime.fromCurrentTime = function() { 88 | return new DayTime(15,20); 89 | }; 90 | expect(nightMode.isNight()).toBe(false); 91 | }); 92 | 93 | }); --------------------------------------------------------------------------------