random-transactions-sdk 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ var browserify = require('browserify')
4
+ , path = require('path')
5
+ , fs = require('fs');
6
+
7
+ require('http').createServer(function statical(req, res) {
8
+ res.statusCode = 200;
9
+ res.setHeader('Content-Type', 'text/html');
10
+
11
+ switch (req.url) {
12
+ case '/':
13
+ req.url = '/index.html';
14
+ break;
15
+
16
+ case '/dist/requests.js':
17
+ var compiler
18
+ , stream;
19
+
20
+ res.setHeader('Content-Type', 'text/javascript');
21
+
22
+ compiler = browserify({ debug: true, standalone: 'Requests' });
23
+ compiler.add(path.join(__dirname, '..', 'browser.js'));
24
+
25
+ stream = compiler.bundle();
26
+
27
+ stream.pipe(res);
28
+ stream.pipe(fs.createWriteStream(path.join(__dirname, '..', req.url)));
29
+ return;
30
+
31
+ case '/stream':
32
+ res.write('[first chunk]');
33
+ setTimeout(function () {
34
+ res.write('[second chunk]');
35
+
36
+ setTimeout(function () {
37
+ res.end('[final chunk]');
38
+ }, 10000);
39
+ }, 100);
40
+ return;
41
+ }
42
+
43
+ if (!fs.existsSync(__dirname + req.url)) {
44
+ res.write('<script src="/dist/requests.js"></script>');
45
+ return res.end('Nope, doesn\'t exist.');
46
+ }
47
+
48
+ require('fs').createReadStream(__dirname + req.url).pipe(res);
49
+ }).on('connection', function connection(socket) {
50
+ //
51
+ // Force buffer flusing when we call our write.
52
+ //
53
+ socket.setNoDelay(true);
54
+ }).listen(+process.argv[2] || 8080, function listening() {
55
+ console.log('Development server is now running on:');
56
+ console.log('');
57
+ console.log(' http://localhost:'+ this.address().port);
58
+ console.log('');
59
+ });
@@ -0,0 +1,26 @@
1
+ <div id="output">
2
+ <h2>Progress log</h2>
3
+ </div>
4
+
5
+ <script src="/dist/requests.js"></script>
6
+ <script>
7
+ /**
8
+ * Poor mans cross browser logger.
9
+ *
10
+ * @param {String} line The message that needs to be logged
11
+ * @api private
12
+ */
13
+ function log(line) {
14
+ document.getElementById('output').innerHTML += line +'<br />';
15
+ }
16
+
17
+ var r = new Requests('/stream', { streaming: true });
18
+
19
+ r.on('data', function (data) {
20
+ log('<strong>received chunk:</strong> <code>'+ data +'</code>');
21
+ });
22
+
23
+ r.on('end', function () {
24
+ log('<strong>request has ended</strong>');
25
+ });
26
+ </script>
package/test/index.js ADDED
@@ -0,0 +1,107 @@
1
+ 'use strict';
2
+
3
+ var path = require('path')
4
+ , Mocha = require('mocha')
5
+ , argv = require('argh').argv
6
+ , mochify = require('mochify');
7
+
8
+ argv.reporter = argv.reporter || 'spec';
9
+ argv.ui = argv.ui || 'bdd';
10
+ argv.wd = argv.wd || false;
11
+
12
+ /**
13
+ * Poor mans kill switch. Kills all active hooks.
14
+ *
15
+ * @api private
16
+ */
17
+ function kill() {
18
+ require('async-each')(kill.hooks, function each(fn, next) {
19
+ fn(next);
20
+ }, function done(err) {
21
+ if (err) return process.exit(1);
22
+
23
+ process.exit(0);
24
+ });
25
+ }
26
+
27
+ /**
28
+ * All the hooks that need destruction.
29
+ *
30
+ * @type {Array}
31
+ * @private
32
+ */
33
+ kill.hooks = [];
34
+
35
+ //
36
+ // This is the magical test runner that setup's all the things and runs various
37
+ // of test suites until something starts failing.
38
+ //
39
+ (function runner(steps) {
40
+ if (!steps.length) return kill(), runner;
41
+
42
+ var step = steps.shift();
43
+
44
+ step(function unregister(fn) {
45
+ kill.hooks.push(fn);
46
+ }, function register(err) {
47
+ if (err) throw err;
48
+
49
+ runner(steps);
50
+ });
51
+
52
+ return runner;
53
+ })([
54
+ //
55
+ // Run the normal node tests.
56
+ //
57
+ function creamy(kill, next) {
58
+ var mocha = new Mocha();
59
+
60
+ mocha.reporter(argv.reporter);
61
+ mocha.ui(argv.ui);
62
+
63
+ //
64
+ // The next bulk of logic is required to correctly glob and lookup all the
65
+ // files required for testing.
66
+ //
67
+ mocha.files = [
68
+ './test/*.test.js'
69
+ ].map(function lookup(glob) {
70
+ return Mocha.utils.lookupFiles(glob, ['js']);
71
+ }).reduce(function flatten(arr, what) {
72
+ Array.prototype.push.apply(arr, what);
73
+ return arr;
74
+ }, []).map(function resolve(file) {
75
+ return path.resolve(file);
76
+ });
77
+
78
+ //
79
+ // Run the mocha test suite inside this node process with a custom callback
80
+ // so we don't accidentally exit the process and forget to run the test of the
81
+ // tests.
82
+ //
83
+ mocha.run(function ran(err) {
84
+ if (err) err = new Error('Something failed in the mocha test suite');
85
+ next(err);
86
+ });
87
+ },
88
+
89
+ //
90
+ // Start-up a small static file server so we can download files and fixtures
91
+ // inside our PhantomJS test.
92
+ //
93
+ require('./static'),
94
+
95
+ //
96
+ // Run the PhantomJS tests now that we have a small static server setup.
97
+ //
98
+ function phantomjs(kill, next) {
99
+ mochify('./test/*.browser.js', {
100
+ reporter: argv.reporter,
101
+ cover: argv.cover,
102
+ wd: argv.wd,
103
+ ui: argv.ui
104
+ })
105
+ .bundle(next);
106
+ }
107
+ ]);