[OpenLayers-Commits] r11551 - in trunk/openlayers/tests: . node.js
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Sat Feb 26 19:39:40 EST 2011
Author: crschmidt
Date: 2011-02-26 16:39:39 -0800 (Sat, 26 Feb 2011)
New Revision: 11551
Added:
trunk/openlayers/tests/node.js/
trunk/openlayers/tests/node.js/mockdom.js
trunk/openlayers/tests/node.js/node-tests.cfg
trunk/openlayers/tests/node.js/node.js
trunk/openlayers/tests/node.js/run-test.js
trunk/openlayers/tests/node.js/run.sh
Log:
Some node.js test hacking.
Added: trunk/openlayers/tests/node.js/mockdom.js
===================================================================
--- trunk/openlayers/tests/node.js/mockdom.js (rev 0)
+++ trunk/openlayers/tests/node.js/mockdom.js 2011-02-27 00:39:39 UTC (rev 11551)
@@ -0,0 +1,106 @@
+XMLHttpRequest = function() {
+ return {
+ 'open': function() { },
+ 'send': function() { }
+ }
+};
+
+alert = print;
+
+navigator = {
+ 'appName': 'mockdom',
+ 'userAgent': 'mockdom',
+ 'appVersion': '0.1',
+ 'language': 'en',
+ 'userLanguage': 'en'
+}
+
+element = function(type) {
+ type = type || "";
+
+ return {
+ 'childNodes': [],
+ 'className': '',
+ 'tagName': type.toUpperCase(),
+ 'style': {},
+ 'setAttribute': function(attr, value) {
+ this[attr] = value;
+ },
+ 'appendChild': function(element) {
+ if (this.childNodes.length) {
+ this.childNodes[this.childNodes.length - 1].nextSibling = element;
+ } else {
+ this.firstChild = element;
+ }
+ element.parentNode = this;
+ this.childNodes.push(element);
+
+ },
+ 'removeChild': function(element) {
+ var i = this.childNodes.indexOf(element);
+ this.childNodes.splice(i, 1);
+ },
+ 'addEventListener': function() {
+ },
+ 'removeEventListener': function() {
+ },
+ 'getElementsByTagName': function(name, externalList) {
+ var uc = name.toUpperCase();
+ var list = externalList || [];
+ for(var i = 0; i < this.childNodes.length; i++) {
+ if (this.childNodes[i].tagName == uc) {
+ list.push(this.childNodes[i]);
+ }
+ this.childNodes[i].getElementsByTagName(name, list);
+ }
+ return list;
+ },
+ 'getElementById': function(id) {
+ for(var i = 0; i < this.childNodes.length; i++) {
+ if (this.childNodes[i].id == id) {
+ return this.childNodes[i];
+ } else {
+ var elem = this.childNodes[i].getElementById(id);
+ if (elem) {
+ return elem
+ }
+ }
+ }
+ }
+ }
+};
+
+document = element();
+document.createElement = function(type) {
+ return element(type);
+};
+document.createTextNode = function(text) {
+ var e = element("Text");
+ e.innerHTML = text;
+}
+
+document.appendChild(element("head"));
+document.body = element("body");
+document.appendChild(document.body);
+
+window = {
+ 'addEventListener': function() {
+ },
+ 'getSelection': function() {
+ return {
+ collapseToStart: function() {}
+ }
+ },
+ document: document,
+ navigator: navigator,
+ location: {
+ href: '#',
+ port: '',
+ hostname: 'openlayers.org',
+ host: 'openlayers.org',
+ proto: 'https'
+ }
+};
+document.location = window.location;
+
+window.Function = Function;
Added: trunk/openlayers/tests/node.js/node-tests.cfg
===================================================================
--- trunk/openlayers/tests/node.js/node-tests.cfg (rev 0)
+++ trunk/openlayers/tests/node.js/node-tests.cfg 2011-02-27 00:39:39 UTC (rev 11551)
@@ -0,0 +1,12 @@
+# This build config is supposed to be used for the units tests with "mode=build"
+
+[first]
+mockdom.js
+[last]
+node.js
+
+[include]
+
+[exclude]
+OpenLayers.js
+Firebug/firebug.js
Added: trunk/openlayers/tests/node.js/node.js
===================================================================
--- trunk/openlayers/tests/node.js/node.js (rev 0)
+++ trunk/openlayers/tests/node.js/node.js 2011-02-27 00:39:39 UTC (rev 11551)
@@ -0,0 +1 @@
+exports.OpenLayers = OpenLayers;
Added: trunk/openlayers/tests/node.js/run-test.js
===================================================================
--- trunk/openlayers/tests/node.js/run-test.js (rev 0)
+++ trunk/openlayers/tests/node.js/run-test.js 2011-02-27 00:39:39 UTC (rev 11551)
@@ -0,0 +1,26 @@
+// Requires:
+/// 0. nodejs
+// 1. jsdom installed (npm install jsdom)
+// 2. A build profile with mockdom.js included in [first], and node.js
+// inclded in [last], at ../../build/OpenLayers.js , like node-tests.js.
+// 3. Run with node run-tests.js
+//
+// Missing: integration with a solid node.js testrunner.
+var jsdom = require('jsdom');
+jsdom.env('<html><body></body></html>', function(errors, window) {
+ for (var i in window) {
+ if (i == "console") {
+ continue;
+ }
+ eval(i+"=window['"+i+"'];");
+ }
+ OpenLayers = require("../../build/OpenLayers.js")['OpenLayers'];
+ var map = new OpenLayers.Map(document.createElement("map"));
+ map.addLayer(new OpenLayers.Layer("", {isBaseLayer:true}));
+ map.setCenter(new OpenLayers.LonLat(-71,42), 10);
+ var px = map.getPixelFromLonLat(map.getLonLatFromPixel(new OpenLayers.Pixel(100,100)));
+ console.log(px);
+ var px = map.getLonLatFromPixel(map.getPixelFromLonLat(new OpenLayers.LonLat(10,10)));
+ console.log(px);
+
+});
Added: trunk/openlayers/tests/node.js/run.sh
===================================================================
--- trunk/openlayers/tests/node.js/run.sh (rev 0)
+++ trunk/openlayers/tests/node.js/run.sh 2011-02-27 00:39:39 UTC (rev 11551)
@@ -0,0 +1,10 @@
+#!/bin/sh
+cp mockdom.js node.js ../../lib
+cp node-tests.cfg ../../build
+cd ../../build
+python build.py -c none node-tests
+cd ../tests/node.js/
+
+node run-test.js
+rm ../../lib/mockdom.js
+rm ../../lib/node.js
Property changes on: trunk/openlayers/tests/node.js/run.sh
___________________________________________________________________
Added: svn:executable
+ *
More information about the Commits
mailing list