Skip to content
Browse files

Commits Jasmine, fixtures and spec files

  • Loading branch information...
1 parent 1f16962 commit 5c67db199d8e7ad2c5eff596a23857dc17825f8e @xcambar committed
View
3 test/fixtures/invalidToken.js
@@ -0,0 +1,3 @@
+"falsyToken";
+
+
View
20 test/fixtures/named.js
@@ -0,0 +1,20 @@
+"module m1 {";
+" export fn1";
+" export var1";
+"}";
+
+/**
+ * ES-Harmony Syntax:
+ *
+ * module math {
+ * export fn1;*\/
+ * export var1;
+ * }
+ */
+
+
+var fn1 = function () {
+ return true;
+};
+
+var var1 = 'EXPORTED NAMED MODULE!!';
View
20 test/fixtures/unnamed.js
@@ -0,0 +1,20 @@
+"module {";
+" export fn2";
+" export var2"
+"}";
+
+/**
+ * ES-Harmony Syntax:
+ * This syntax is not valid according to http://wiki.ecmascript.org/doku.php?id=harmony:modules. A module MUST have a name.
+ * module {
+ * export fn1;*\/
+ * export var1;
+ * }
+ */
+
+
+var fn2 = function () {
+ return true;
+};
+
+var var2 = 'EXPORTED!!';
View
11 test/fixtures/withImport.js
@@ -0,0 +1,11 @@
+"module hasImport";
+"import m1";
+"export imp1";
+"export ref1";
+
+var imp1 = function () {
+ return m1.fn1();
+};
+
+console.log('m1: ', m1);
+var ref1 = m1.fn1;
View
54 test/index.html
@@ -0,0 +1,54 @@
+<!doctype html>
+<html>
+<head>
+ <title>Jasmine Spec Runner</title>
+
+ <link rel="shortcut icon" type="image/png" href="/test/jasmine-1.1.0/jasmine_favicon.png">
+
+ <link rel="stylesheet" type="text/css" href="/test/jasmine-1.1.0/jasmine.css">
+ <script type="text/javascript" src="/test/jasmine-1.1.0/jasmine.js"></script>
+ <script type="text/javascript" src="/test/jasmine-1.1.0/jasmine-html.js"></script>
+
+ <!-- spec files -->
+ <script type="text/javascript" src="/test/spec/specHelper.js"></script>
+ <script type="text/javascript" src="/test/spec/loaderSpec.js"></script>
+
+ <!-- static dependencies -->
+ <script type="text/javascript" src="/reqwest.js"></script>
+ <!-- source files -->
+ <script type="text/javascript" src="/loader.js"></script>
+
+ <script type="text/javascript">
+ (function() {
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.updateInterval = 1000;
+
+ var trivialReporter = new jasmine.TrivialReporter();
+
+ jasmineEnv.addReporter(trivialReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return trivialReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ jasmineEnv.execute();
+ }
+
+ })();
+ </script>
+
+</head>
+
+<body>
+</body>
+</html>
View
20 test/jasmine-1.1.0/MIT.LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008-2011 Pivotal Labs
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
190 test/jasmine-1.1.0/jasmine-html.js
@@ -0,0 +1,190 @@
+jasmine.TrivialReporter = function(doc) {
+ this.document = doc || document;
+ this.suiteDivs = {};
+ this.logRunningSpecs = false;
+};
+
+jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
+ var el = document.createElement(type);
+
+ for (var i = 2; i < arguments.length; i++) {
+ var child = arguments[i];
+
+ if (typeof child === 'string') {
+ el.appendChild(document.createTextNode(child));
+ } else {
+ if (child) { el.appendChild(child); }
+ }
+ }
+
+ for (var attr in attrs) {
+ if (attr == "className") {
+ el[attr] = attrs[attr];
+ } else {
+ el.setAttribute(attr, attrs[attr]);
+ }
+ }
+
+ return el;
+};
+
+jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
+ var showPassed, showSkipped;
+
+ this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
+ this.createDom('div', { className: 'banner' },
+ this.createDom('div', { className: 'logo' },
+ this.createDom('span', { className: 'title' }, "Jasmine"),
+ this.createDom('span', { className: 'version' }, runner.env.versionString())),
+ this.createDom('div', { className: 'options' },
+ "Show ",
+ showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
+ showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
+ this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
+ )
+ ),
+
+ this.runnerDiv = this.createDom('div', { className: 'runner running' },
+ this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
+ this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
+ this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
+ );
+
+ this.document.body.appendChild(this.outerDiv);
+
+ var suites = runner.suites();
+ for (var i = 0; i < suites.length; i++) {
+ var suite = suites[i];
+ var suiteDiv = this.createDom('div', { className: 'suite' },
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
+ this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
+ this.suiteDivs[suite.id] = suiteDiv;
+ var parentDiv = this.outerDiv;
+ if (suite.parentSuite) {
+ parentDiv = this.suiteDivs[suite.parentSuite.id];
+ }
+ parentDiv.appendChild(suiteDiv);
+ }
+
+ this.startedAt = new Date();
+
+ var self = this;
+ showPassed.onclick = function(evt) {
+ if (showPassed.checked) {
+ self.outerDiv.className += ' show-passed';
+ } else {
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
+ }
+ };
+
+ showSkipped.onclick = function(evt) {
+ if (showSkipped.checked) {
+ self.outerDiv.className += ' show-skipped';
+ } else {
+ self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
+ }
+ };
+};
+
+jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
+ var results = runner.results();
+ var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
+ this.runnerDiv.setAttribute("class", className);
+ //do it twice for IE
+ this.runnerDiv.setAttribute("className", className);
+ var specs = runner.specs();
+ var specCount = 0;
+ for (var i = 0; i < specs.length; i++) {
+ if (this.specFilter(specs[i])) {
+ specCount++;
+ }
+ }
+ var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
+ message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
+ this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
+
+ this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
+};
+
+jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
+ var results = suite.results();
+ var status = results.passed() ? 'passed' : 'failed';
+ if (results.totalCount === 0) { // todo: change this to check results.skipped
+ status = 'skipped';
+ }
+ this.suiteDivs[suite.id].className += " " + status;
+};
+
+jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
+ if (this.logRunningSpecs) {
+ this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
+ }
+};
+
+jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
+ var results = spec.results();
+ var status = results.passed() ? 'passed' : 'failed';
+ if (results.skipped) {
+ status = 'skipped';
+ }
+ var specDiv = this.createDom('div', { className: 'spec ' + status },
+ this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
+ this.createDom('a', {
+ className: 'description',
+ href: '?spec=' + encodeURIComponent(spec.getFullName()),
+ title: spec.getFullName()
+ }, spec.description));
+
+
+ var resultItems = results.getItems();
+ var messagesDiv = this.createDom('div', { className: 'messages' });
+ for (var i = 0; i < resultItems.length; i++) {
+ var result = resultItems[i];
+
+ if (result.type == 'log') {
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
+
+ if (result.trace.stack) {
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
+ }
+ }
+ }
+
+ if (messagesDiv.childNodes.length > 0) {
+ specDiv.appendChild(messagesDiv);
+ }
+
+ this.suiteDivs[spec.suite.id].appendChild(specDiv);
+};
+
+jasmine.TrivialReporter.prototype.log = function() {
+ var console = jasmine.getGlobal().console;
+ if (console && console.log) {
+ if (console.log.apply) {
+ console.log.apply(console, arguments);
+ } else {
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
+ }
+ }
+};
+
+jasmine.TrivialReporter.prototype.getLocation = function() {
+ return this.document.location;
+};
+
+jasmine.TrivialReporter.prototype.specFilter = function(spec) {
+ var paramMap = {};
+ var params = this.getLocation().search.substring(1).split('&');
+ for (var i = 0; i < params.length; i++) {
+ var p = params[i].split('=');
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
+ }
+
+ if (!paramMap.spec) {
+ return true;
+ }
+ return spec.getFullName().indexOf(paramMap.spec) === 0;
+};
View
166 test/jasmine-1.1.0/jasmine.css
@@ -0,0 +1,166 @@
+body {
+ font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
+}
+
+
+.jasmine_reporter a:visited, .jasmine_reporter a {
+ color: #303;
+}
+
+.jasmine_reporter a:hover, .jasmine_reporter a:active {
+ color: blue;
+}
+
+.run_spec {
+ float:right;
+ padding-right: 5px;
+ font-size: .8em;
+ text-decoration: none;
+}
+
+.jasmine_reporter {
+ margin: 0 5px;
+}
+
+.banner {
+ color: #303;
+ background-color: #fef;
+ padding: 5px;
+}
+
+.logo {
+ float: left;
+ font-size: 1.1em;
+ padding-left: 5px;
+}
+
+.logo .version {
+ font-size: .6em;
+ padding-left: 1em;
+}
+
+.runner.running {
+ background-color: yellow;
+}
+
+
+.options {
+ text-align: right;
+ font-size: .8em;
+}
+
+
+
+
+.suite {
+ border: 1px outset gray;
+ margin: 5px 0;
+ padding-left: 1em;
+}
+
+.suite .suite {
+ margin: 5px;
+}
+
+.suite.passed {
+ background-color: #dfd;
+}
+
+.suite.failed {
+ background-color: #fdd;
+}
+
+.spec {
+ margin: 5px;
+ padding-left: 1em;
+ clear: both;
+}
+
+.spec.failed, .spec.passed, .spec.skipped {
+ padding-bottom: 5px;
+ border: 1px solid gray;
+}
+
+.spec.failed {
+ background-color: #fbb;
+ border-color: red;
+}
+
+.spec.passed {
+ background-color: #bfb;
+ border-color: green;
+}
+
+.spec.skipped {
+ background-color: #bbb;
+}
+
+.messages {
+ border-left: 1px dashed gray;
+ padding-left: 1em;
+ padding-right: 1em;
+}
+
+.passed {
+ background-color: #cfc;
+ display: none;
+}
+
+.failed {
+ background-color: #fbb;
+}
+
+.skipped {
+ color: #777;
+ background-color: #eee;
+ display: none;
+}
+
+
+/*.resultMessage {*/
+ /*white-space: pre;*/
+/*}*/
+
+.resultMessage span.result {
+ display: block;
+ line-height: 2em;
+ color: black;
+}
+
+.resultMessage .mismatch {
+ color: black;
+}
+
+.stackTrace {
+ white-space: pre;
+ font-size: .8em;
+ margin-left: 10px;
+ max-height: 5em;
+ overflow: auto;
+ border: 1px inset red;
+ padding: 1em;
+ background: #eef;
+}
+
+.finished-at {
+ padding-left: 1em;
+ font-size: .6em;
+}
+
+.show-passed .passed,
+.show-skipped .skipped {
+ display: block;
+}
+
+
+#jasmine_content {
+ position:fixed;
+ right: 100%;
+}
+
+.runner {
+ border: 1px solid gray;
+ display: block;
+ margin: 5px 0;
+ padding: 2px 0 2px 10px;
+}
View
2,476 test/jasmine-1.1.0/jasmine.js
2,476 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
BIN test/jasmine-1.1.0/jasmine_favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
155 test/spec/loaderSpec.js
@@ -0,0 +1,155 @@
+describe('Generic features of the Loader', function () {
+ it('should reset its state at will', function () {
+ var modPath = '/test/fixtures/unnamed.js';
+ nh.reset();
+ expect(nh.error()).toBeNull();
+ expect(nh.get(modPath)).toBeUndefined();
+ })
+
+ it('should contain no erroneous module at init', function () {
+ expect(nh.error()).toBeNull();
+ });
+
+ it('should allow a custom global error callback', function () {
+ var modPath = '/invalid/file/path.js';
+ var spy = jasmine.createSpy();
+ nh.error(spy);
+
+ runs(function () {
+ nh(modPath);
+ });
+ waitsFor(function () {
+ return nh.error();
+ }, 'No error happened', 10000);
+ });
+
+ it('should log the modules which could not have been loaded', function () {
+ nh.reset();
+ var modPath = '/invalid/file/path.js';
+ var spy = jasmine.createSpy();
+ nh.error(spy);
+
+ runs(function () {
+ nh(modPath);
+ });
+
+ waitsFor(function () {
+ return nh.error();
+ }, 'No error happened', 10000);
+
+ runs(function () {
+ expect(nh.error()).toEqual([modPath]);
+ expect(spy).toHaveBeenCalled();
+ expect(spy.callCount).toEqual(1);
+ });
+ });
+});
+
+describe('Declaring an unnamed module', function () {
+ it('should load an unnamed module and call the optionnally provided callback', function () {
+ var modPath = '/test/fixtures/unnamed.js';
+ var spy = jasmine.createSpy();
+ runs(function () {
+ nh(modPath, spy);
+ });
+ waitsFor(function () {
+ return !!nh.get(modPath);
+ }, 'The module has never been loaded', 10000);
+
+ runs(function () {
+ expect(spy).toHaveBeenCalled();
+ expect(spy.callCount).toEqual(1);
+ });
+ });
+
+ it('should return an available module by its path', function () {
+ var module = nh.get('/test/fixtures/unnamed.js');
+ expect(module).toHaveMembers(['fn2', 'var2']);
+ expect(module.var2).toBe('EXPORTED!!')
+ expect(typeof module.fn2).toBe('function');
+ });
+
+ it('should raise an exception if an invalid token is encountered', function () {
+ nh.reset();
+ var modPath = '/test/fixtures/invalidToken.js';
+ var caught = false;
+ var spy = jasmine.createSpy();
+ nh.error(spy);
+ runs(function () {
+ nh(modPath);
+ });
+ waitsFor(function () {
+ return nh.error();
+ });
+ runs(function () {
+ expect(spy).toHaveBeenCalled();
+ });
+ });
+});
+
+describe('Declaring an named module', function () {
+ var modPath = '/test/fixtures/named.js',
+ modName = 'm1';
+
+ it('should load a named module by its path and call the optionnally provided callback', function () {
+ var spy = jasmine.createSpy();
+ runs(function () {
+ nh(modPath, spy);
+ });
+ waitsFor(function () {
+ return !!nh.get(modPath);
+ }, 'The module has never been loaded', 10000);
+
+ runs(function () {
+ expect(spy).toHaveBeenCalled();
+ expect(spy.callCount).toEqual(1);
+ });
+ });
+
+ it('should return an available named module by its name', function () {
+ var module = nh.get(modName);
+ expect(module).not.toBeFalsy();
+ });
+
+ it('should return an available named module by its path', function () {
+ var module = nh.get(modPath);
+ expect(module).not.toBeFalsy();
+ });
+
+ it('should return the same module reference either by name or path', function () {
+ var moduleP = nh.get(modPath);
+ var moduleN = nh.get(modName);
+ expect(moduleP).toBe(moduleN);
+ expect(moduleP).toHaveMembers(['fn1', 'var1']);
+ expect(moduleP.var1).toBe('EXPORTED NAMED MODULE!!')
+ expect(typeof moduleP.fn1).toBe('function');
+ });
+});
+
+describe('Importing named modules', function () {
+ var modWithImport = '/test/fixtures/withImport.js';
+ var importedMod = '/test/fixtures/named.js';
+ beforeEach(function () {
+ runs(function () {
+ nh.reset();
+ nh(importedMod);
+ });
+ waitsFor(function () {
+ return nh.get(importedMod);
+ });
+ })
+
+ it('should be able to load an available module from its import name', function () {
+ var spy = jasmine.createSpy();
+ runs(function () {
+ nh(modWithImport, spy);
+ });
+ waitsFor(function () {
+ return nh.get(modWithImport);
+ });
+ runs(function () {
+ expect(nh.get(modWithImport).imp1()).toBeTruthy();
+ expect(nh.get(modWithImport).ref1).toBe(nh.get(importedMod).fn1);
+ });
+ });
+});
View
12 test/spec/specHelper.js
@@ -0,0 +1,12 @@
+beforeEach(function () {
+ this.addMatchers({
+ toHaveMembers: function (expected) {
+ for (var i = 0; i < expected.length; i++) {
+ if(!this.actual.hasOwnProperty(expected[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+ })
+})

0 comments on commit 5c67db1

Please sign in to comment.
Something went wrong with that request. Please try again.