aboutsummaryrefslogtreecommitdiffhomepage
path: root/js/commonjs/export_asserts.js
diff options
context:
space:
mode:
authorGravatar Joshua Haberman <jhaberman@gmail.com>2016-02-19 14:39:17 -0800
committerGravatar Joshua Haberman <jhaberman@gmail.com>2016-02-19 14:39:17 -0800
commit32daf513ced8d51e8de6cc8d800cfc972c4df5d6 (patch)
treed430af9b032a81e73757c59209a1ed1d6e9be42e /js/commonjs/export_asserts.js
parent894c4d6a8bb9ab6b6d4791be98656cfb5399d0bc (diff)
parent24c5424be5b220d8d4575e4262ee5d6ad9417959 (diff)
Merge pull request #1215 from haberman/commonjs
Added support for CommonJS require()
Diffstat (limited to 'js/commonjs/export_asserts.js')
-rw-r--r--js/commonjs/export_asserts.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/js/commonjs/export_asserts.js b/js/commonjs/export_asserts.js
new file mode 100644
index 00000000..5219d120
--- /dev/null
+++ b/js/commonjs/export_asserts.js
@@ -0,0 +1,37 @@
+/**
+ * @fileoverview Exports symbols needed only by tests.
+ *
+ * This file exports several Closure Library symbols that are only
+ * used by tests. It is used to generate a file
+ * closure_asserts_commonjs.js that is only used at testing time.
+ */
+
+goog.require('goog.testing.asserts');
+
+var global = Function('return this')();
+
+// All of the closure "assert" functions are exported at the global level.
+//
+// The Google Closure assert functions start with assert, eg.
+// assertThrows
+// assertNotThrows
+// assertTrue
+// ...
+//
+// The one exception is the "fail" function.
+function shouldExport(str) {
+ return str.lastIndexOf('assert') === 0 || str == 'fail';
+}
+
+for (var key in global) {
+ if ((typeof key == "string") && global.hasOwnProperty(key) &&
+ shouldExport(key)) {
+ exports[key] = global[key];
+ }
+}
+
+// The COMPILED variable is set by Closure compiler to "true" when it compiles
+// JavaScript, so in practice this is equivalent to "exports.COMPILED = true".
+// This will disable some debugging functionality in debug.js. We could
+// investigate whether this can/should be enabled in CommonJS builds.
+exports.COMPILED = COMPILED