aboutsummaryrefslogtreecommitdiffhomepage
path: root/js/commonjs
diff options
context:
space:
mode:
authorGravatar Josh Haberman <jhaberman@gmail.com>2016-03-31 14:18:34 -0700
committerGravatar Josh Haberman <jhaberman@gmail.com>2016-04-07 14:04:55 -0700
commit15239361e31d53c10b918aa9fe8ce057155588b4 (patch)
treee7b0f3307c3b0ffbe448cefe7e1ca89dae116f79 /js/commonjs
parentaeacf51602f78c206ea3e8b103e0a7a3c3a5d8c5 (diff)
Fix for CommonJS tests.
Diffstat (limited to 'js/commonjs')
-rw-r--r--js/commonjs/export_testdeps.js18
-rw-r--r--js/commonjs/rewrite_tests_for_commonjs.js20
2 files changed, 30 insertions, 8 deletions
diff --git a/js/commonjs/export_testdeps.js b/js/commonjs/export_testdeps.js
new file mode 100644
index 00000000..59c77ca2
--- /dev/null
+++ b/js/commonjs/export_testdeps.js
@@ -0,0 +1,18 @@
+/**
+ * @fileoverview Export symbols needed by tests in CommonJS style.
+ *
+ * This file is like export.js, but for symbols that are only used by tests.
+ * However we exclude assert functions here, because they are exported into
+ * the global namespace, so those are handled as a special case in
+ * export_asserts.js.
+ */
+
+goog.require('goog.crypt.base64');
+goog.require('jspb.arith.Int64');
+goog.require('jspb.arith.UInt64');
+goog.require('jspb.BinaryEncoder');
+goog.require('jspb.BinaryDecoder');
+goog.require('jspb.utils');
+
+exports.goog = goog;
+exports.jspb = jspb;
diff --git a/js/commonjs/rewrite_tests_for_commonjs.js b/js/commonjs/rewrite_tests_for_commonjs.js
index ffa87722..b6d90d28 100644
--- a/js/commonjs/rewrite_tests_for_commonjs.js
+++ b/js/commonjs/rewrite_tests_for_commonjs.js
@@ -61,6 +61,18 @@ function camelCase(str) {
var module = null;
var pkg = null;
+
+// Header: goes in every file at the top.
+console.log("var global = Function('return this')();");
+console.log("var googleProtobuf = require('google-protobuf');");
+console.log("var testdeps = require('testdeps_commonjs');");
+console.log("global.goog = testdeps.goog;");
+console.log("global.jspb = testdeps.jspb;");
+console.log("var asserts = require('closure_asserts_commonjs');");
+console.log("");
+console.log("// Bring asserts into the global namespace.");
+console.log("googleProtobuf.object.extend(global, asserts);");
+
lineReader.on('line', function(line) {
var isRequire = line.match(/goog\.require\('([^']*)'\)/);
var isLoadFromFile = line.match(/CommonJS-LoadFromFile: (\S*) (.*)/);
@@ -72,14 +84,6 @@ lineReader.on('line', function(line) {
console.log("googleProtobuf.exportSymbol('" + fullSym + "', " + module + sym + ', global);');
}
} else if (isLoadFromFile) {
- if (!module) {
- console.log("var googleProtobuf = require('google-protobuf');");
- console.log("var asserts = require('closure_asserts_commonjs');");
- console.log("var global = Function('return this')();");
- console.log("");
- console.log("// Bring asserts into the global namespace.");
- console.log("googleProtobuf.object.extend(global, asserts);");
- }
var module_path = isLoadFromFile[1].split('/');
module = camelCase(module_path[module_path.length - 1]);
pkg = isLoadFromFile[2];