Permalink
Browse files

initial commit; refactor test from openlayers svn

  • Loading branch information...
1 parent b564d28 commit e5122594ee9e3ec8e9a46865584c132ac6c25a24 @booo committed Jul 22, 2011
Showing with 2,788 additions and 0 deletions.
  1. +12 −0 README.md
  2. +13 −0 build.sh
  3. +2,572 −0 lib/OpenLayers.js
  4. +104 −0 mockdom.js
  5. +12 −0 node.cfg
  6. +1 −0 node.js
  7. +46 −0 package.json
  8. +28 −0 run-test.js
View
12 README.md
@@ -0,0 +1,12 @@
+#OpenLayers 3 for node.js. Have fun.
+
+Thanks to all giants I stand on.
+
+##Build
+Checkout the git submodule. Run `build.sh` to build the package.
+
+##Testing
+Run `run-test.s` to run a simple test. Make sure to install jsdom via `npm`.
+
+##Using
+Just use `npm link` to make the package available fo node. In your node project use `npm link openlayers` to install it local. Use `require("openlayers").OpenLayers` in your code.
View
13 build.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+cp mockdom.js node.js deps/openlayers3/lib
+cp node.cfg deps/openlayers3/build
+cd deps/openlayers3/build
+python build.py node
+cd ../../..
+
+cp deps/openlayers3/build/OpenLayers.js ./lib/
+#node run-test.js
+rm deps/openlayers3/lib/mockdom.js
+rm deps/openlayers3/lib/node.js
+rm deps/openlayers3/build/OpenLayers.js
+rm deps/openlayers3/build/node.cfg
View
2,572 lib/OpenLayers.js
2,572 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
104 mockdom.js
@@ -0,0 +1,104 @@
+XMLHttpRequest = function() {
+ return {
+ 'open': function() { },
+ 'send': function() { }
+ }
+};
+
+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;
View
12 node.cfg
@@ -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
View
1 node.js
@@ -0,0 +1 @@
+exports.OpenLayers = OpenLayers;
View
46 package.json
@@ -0,0 +1,46 @@
+{
+ "name": "openlayers",
+ "version": "3.0.0",
+ "description": "openlayers for nodejs",
+ "homepage": "",
+ "keywords": ["openlayers", "node"],
+ "author": {
+ "name": "",
+ "email": "",
+ "web": ""
+ },
+ "maintainers": [
+ {
+ "name": "",
+ "email": "",
+ "web": ""
+ }
+ ],
+ "contributors": [
+ {
+ "name": "",
+ "email": "",
+ "web": ""
+ }
+ ],
+ "bugs": {
+ "web": ""
+ },
+ "licenses": [],
+ "repository" : {},
+ "dependencies": {
+ },
+ "engines" : {
+ "node": ">=0.4.5"
+ },
+ "main": "./lib/OpenLayers",
+ "directories": {
+ },
+ "scripts": {
+ "install": ""
+ },
+ "repository": "",
+ "dependencies": {
+ "jsdom": "*"
+ }
+}
View
28 run-test.js
@@ -0,0 +1,28 @@
+#!/usr/bin/env node
+
+// Requires:
+/// 0. nodejs
+// 1. jsdom installed (npm install jsdom)
+// 2. A build profile with mockdom.js included in [first], and node.js
+// included 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("./lib/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);
+
+});

0 comments on commit e512259

Please sign in to comment.