aboutsummaryrefslogtreecommitdiff
path: root/node_modules/load-script/test
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/load-script/test')
-rw-r--r--node_modules/load-script/test/hello.js1
-rw-r--r--node_modules/load-script/test/index.js90
-rw-r--r--node_modules/load-script/test/throw.js1
3 files changed, 92 insertions, 0 deletions
diff --git a/node_modules/load-script/test/hello.js b/node_modules/load-script/test/hello.js
new file mode 100644
index 00000000..77a64c6b
--- /dev/null
+++ b/node_modules/load-script/test/hello.js
@@ -0,0 +1 @@
+log('Hello world')
diff --git a/node_modules/load-script/test/index.js b/node_modules/load-script/test/index.js
new file mode 100644
index 00000000..a620764b
--- /dev/null
+++ b/node_modules/load-script/test/index.js
@@ -0,0 +1,90 @@
+var assert = require('assert');
+var load = require('../')
+
+var last_msg = undefined;
+log = function(msg) {
+ last_msg = msg;
+}
+
+test('success', function(done) {
+ load('test/hello.js', function (err) {
+ assert.ifError(err);
+ assert.equal(last_msg, 'Hello world');
+ last_msg = undefined;
+ done();
+ })
+});
+
+test('opts.async', function(done) {
+ load('test/hello.js', {async: false}, function(err, script) {
+ assert.ifError(err);
+ assert.equal(script.async, false);
+ done();
+ })
+});
+
+test('opts.attrs', function(done) {
+ load('test/hello.js', {attrs: {foo: 'boo'}}, function(err, script) {
+ assert.ifError(err);
+ assert.equal(script.getAttribute('foo'), 'boo');
+ done();
+ })
+});
+
+test('opts.charset', function(done) {
+ load('test/hello.js', {charset: 'iso-8859-1'}, function(err, script) {
+ assert.ifError(err);
+ assert.equal(script.charset, 'iso-8859-1');
+ done();
+ })
+});
+
+test('opts.text', function(done) {
+ load('test/hello.js', {text: 'foo=5;'}, function(err, script) {
+ assert.ifError(err);
+ done();
+ })
+});
+
+test('opts.type', function(done) {
+ load('test/hello.js', {type: 'text/ecmascript'}, function(err, script) {
+ assert.ifError(err);
+ assert.equal(script.type, 'text/ecmascript');
+ done();
+ })
+});
+
+test('no exist', function(done) {
+ load('unexistent.js', function (err, legacy) {
+ if (!legacy) {
+ assert.ok(err);
+ }
+
+ var tid = setTimeout(function() {
+ done();
+ }, 200);
+
+ // some browsers will also throw as well as report erro
+ var old = window.onerror;
+ window.onerror = function(msg, file, line) {
+ if (msg !== 'Error loading script') {
+ assert(false);
+ }
+ window.onerror = old;
+ clearTimeout(tid);
+ done();
+ };
+ })
+});
+
+test('throw', function(done) {
+ var old = window.onerror;
+ // silence the script error
+ window.onerror = function() {};
+ load('test/throw.js', function (err) {
+ assert.ifError(err);
+ window.onerror = old;
+ done();
+ })
+});
+
diff --git a/node_modules/load-script/test/throw.js b/node_modules/load-script/test/throw.js
new file mode 100644
index 00000000..a42d606f
--- /dev/null
+++ b/node_modules/load-script/test/throw.js
@@ -0,0 +1 @@
+throw new Error('Hello error')