Permalink
Browse files

bundler middleware example, relocated test helper, misc test fixes

  • Loading branch information...
1 parent 2d48d63 commit e619c6c64d924f4e64a2f3bca54abed67f5a020f @cadorn cadorn committed Feb 20, 2012
View
@@ -1,2 +1,2 @@
node_modules/
-/npm-debug.log
+npm-debug.log
@@ -3,7 +3,10 @@ exports.main = function(options)
{
var deferred = require.API.Q.defer();
- var uri = require.sandbox.id + require.resolve("./hello.txt");
+ // NOTE: You can also use `require.resolve()` instead of `require.id()`.
+ // We use the latter so we can load this module in the browser as well.
+ // (The browser loader only supports `require.id()` out of the box)
+ var uri = require.sandbox.id + require.id("./hello.txt");
require.API.JQUERY(function($)
{
@@ -0,0 +1,64 @@
+
+var PATH = require("path"),
+ CONNECT = require("connect"),
+ BUNDLER = require("sourcemint-platform-nodejs/lib/bundler");
+
+
+var EXAMPLES_BASE_PATH = __dirname + "/../../02-NodeJSLoaderFeatures",
+ LOADER_BASE_PATH = PATH.dirname(PATH.dirname(PATH.dirname(require.resolve("sourcemint-loader-js/workspace/www/index.html"))));
+
+
+exports.main = function(onReadyDeferred, options)
+{
+ var server = CONNECT();
+
+ server.use(CONNECT.router(function(app)
+ {
+ app.get(/^\/$/, CONNECT.static(LOADER_BASE_PATH + "/workspace/www"));
+ app.get(/^\/loader./, CONNECT.static(LOADER_BASE_PATH));
+ app.get(/^\/loader.min.js.gz-size/, CONNECT.static(LOADER_BASE_PATH + "/workspace/www"));
+ app.get(/^\/examples\/DevUI/, CONNECT.static(LOADER_BASE_PATH));
+
+ app.get(/^\/examples\/([^\/]*?)(\.js)?(\/(.*))?$/, function (req, res)
+ {
+ var examplePath = EXAMPLES_BASE_PATH + "/" + req.params[0];
+
+ // Only some of the loader examples can be generated from source packages as the other examples
+ // are there to test incorrect bundles.
+ if (!PATH.existsSync(examplePath)) {
+ // There is no NodeJS source package so we simply serve the bundle from the loader.
+ (CONNECT.static(LOADER_BASE_PATH))(req, res);
+ return;
+ }
+
+ // TODO: Maybe we can do without this.
+ req.url = req.url.substring(10 + req.params[0].length + (req.params[1] || "").length);
+
+ // TODO: Make this `connect` compatible.
+ BUNDLER.Middleware(examplePath, __dirname + "/dist", {
+ packageIdHashSeed: "__EXAMPLE__"
+ }).handle(req, res);
+ });
+ }));
+
+ /*TEST*/ if (onReadyDeferred) {
+ /*TEST*/ server.once("listening", function() {
+ /*TEST*/ onReadyDeferred.resolve(function onTestDone(stoppedCallback) {
+ /*TEST*/ server.once("close", function() {
+ /*TEST*/ stoppedCallback();
+ /*TEST*/ });
+ /*TEST*/ server.close();
+ /*TEST*/ });
+ /*TEST*/ });
+ /*TEST*/ }
+
+ server.listen(options.port, "127.0.0.1");
+
+ console.log("Server running at http://127.0.0.1:" + options.port + "/");
+}
+
+if (require.main === module) {
+ exports.main(null, {
+ port: 1337
+ });
+}
@@ -0,0 +1,38 @@
+{
+ "name": "sourcemint-platform-nodejs-examples-04-NodeJSPlatformFeatures-02-BundlerMiddleware",
+ "version": "0.1.0",
+ "engines": {
+ "nodejs": "0.x"
+ },
+ "dependencies": {
+ "connect": "1.x",
+ "sourcemint-platform-nodejs": "0.x",
+ "sourcemint-loader-js": "0.x"
+ },
+ "devDependencies": {
+ "zombie": "0.x"
+ },
+ "scripts": {
+ "test": "node test"
+ },
+ "main": "./main.js",
+ "config": {
+ "github.com/sourcemint/bundler-js/0/-meta/config/0": {
+ "packages": {
+ "connect": {
+ "descriptor": {
+ "config": {
+ "github.com/sourcemint/bundler-js/0/-meta/config/0": {
+ "resolvers": {
+ "/lib/connect.js": [
+ "./lib/middleware/router.js"
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
@@ -0,0 +1,33 @@
+
+var HELPER = require("../../../tests/test-helper"),
+ ASSERT = require("assert"),
+ BROWSER = require("zombie");
+
+
+HELPER.makeTest(require, exports, module, function(Q, onTestDoneDeferred, options)
+{
+ Q.call(function()
+ {
+ (new BROWSER({
+ silent: true,
+ debug: false
+ })).visit("http://127.0.0.1:" + options.port + "/", function(err, browser)
+ {
+ if (err) {
+ onTestDoneDeferred.reject(err);
+ } else
+ if (browser.window.console.output) {
+ Q.call(function() {
+ throw new Error(browser.window.console.output);
+ }).fail(onTestDoneDeferred.reject);
+ } else
+ if (browser.error) {
+ Q.call(function() {
+ throw new Error(browser.error);
+ }).fail(onTestDoneDeferred.reject);
+ } else {
+ onTestDoneDeferred.resolve();
+ }
+ });
+ }).fail(onTestDoneDeferred.reject);
+});
@@ -2,7 +2,8 @@
var ERROR = require("sourcemint-platform-nodejs/lib/util/error"),
EXEC = require("child_process").exec;
PATH = require("path"),
- FS = require("fs");
+ FS = require("fs"),
+ Q = require("q");
exports.main = function()
@@ -3,7 +3,8 @@ var LOADER = require("sourcemint-platform-nodejs/lib/loader"),
ERROR = require("sourcemint-platform-nodejs/lib/util/error"),
BUNDLER = require("sourcemint-bundler-js/lib/bundler"),
PATH = require("path"),
- FS = require("fs");
+ FS = require("fs"),
+ Q = require("q");
exports.main = function()
@@ -14,6 +15,11 @@ exports.main = function()
FS.readdirSync(basePath).forEach(function(filename)
{
+ // TODO: Get this working in bundle format.
+ if (filename === "02-BundlerMiddleware") {
+ return;
+ }
+
var exampleBasePath = basePath + "/" + filename;
if (PATH.existsSync(exampleBasePath + "/package.json"))
@@ -5,6 +5,7 @@
"nodejs": "0.x"
},
"dependencies": {
+ "q": "0.x",
"sourcemint-platform-nodejs": "0.x",
"sourcemint-bundler-js": "0.x"
},
@@ -1,5 +1,5 @@
-var HELPER = require("../test-helper"),
+var HELPER = require("../../../tests/test-helper"),
ASSERT = require("assert"),
HTTP = require("http");
@@ -1,5 +1,5 @@
-var HELPER = require("../test-helper"),
+var HELPER = require("../../../tests/test-helper"),
ASSERT = require("assert"),
HTTP = require("http");
View
@@ -2,7 +2,8 @@
var Q = require("q"),
PATH = require("path"),
FS = require("fs"),
- EXEC = require("child_process").exec;
+ EXEC = require("child_process").exec,
+ UTIL = require("n-util");
const EXAMPLES_BASE_PATH = __dirname + "/../examples";
@@ -81,8 +82,10 @@ function linkPackages()
{
FS.mkdirSync(basePath + "/node_modules", 0775);
}
-
- Object.keys(descriptor.dependencies).forEach(function(name)
+
+ var deps = descriptor.devDependencies || {};
+ UTIL.update(deps, descriptor.dependencies || {});
+ Object.keys(deps).forEach(function(name)
{
if (name === "sourcemint-platform-nodejs" ||
ourDescriptor.dependencies[name] === descriptor.dependencies[name] ||
@@ -92,12 +95,7 @@ function linkPackages()
// TODO: Find a symlink test that does not throw if it does not exist.
FS.lstatSync(basePath + "/node_modules/" + name);
} catch(e) {
- if (name === "sourcemint-platform-nodejs")
- {
- FS.symlinkSync("../../..", basePath + "/node_modules/" + name);
- } else {
- FS.symlinkSync("../../../node_modules/" + name, basePath + "/node_modules/" + name);
- }
+ FS.symlinkSync(filename.replace(/[^\/]+/g, "..") + "/../../node_modules/" + name, basePath + "/node_modules/" + name);
}
}
});
@@ -1,7 +1,7 @@
var Q = require("q"),
HTTP = require("http"),
- ERROR = require("sourcemint-platform-nodejs/lib/util/error");
+ ERROR = require("../lib/util/error");
exports.makeTest = function(REQUIRE, EXPORTS, MODULE, testCallback)

0 comments on commit e619c6c

Please sign in to comment.