mirror of
https://github.com/gundb/panic-server.git
synced 2026-05-07 03:00:26 -04:00
Test gun by passing options, Browser constructor automatically begins a test on a new window, added package.json, patch function for options (validation/default values).
Exposed a function named "test" that takes an options object, with things like how many gun requests to fire in total, what data to send, where to put it, what peers to connect to, etc... Exposed a Browser constructor that opens up a new window and runs the test function with the options provided, returning an interface to the window. Added a patch function to validate the option input and provide defaults where there aren't any values.
This commit is contained in:
37
patch.js
Normal file
37
patch.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/*globals Gun*/
|
||||
/*
|
||||
Expect an object like this:
|
||||
|
||||
|
||||
var thing = {
|
||||
interval: Number,
|
||||
peers: Array,
|
||||
amount: Number,
|
||||
id: String,
|
||||
key: String,
|
||||
path: String,
|
||||
data: *
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
function patch(opt) {
|
||||
'use strict';
|
||||
if (!opt) {
|
||||
throw new Error('No options provided');
|
||||
}
|
||||
if (!opt.id) {
|
||||
throw new Error('No ID given');
|
||||
}
|
||||
var url = location.protocol + '//';
|
||||
url += location.host;
|
||||
url += '/gun';
|
||||
|
||||
opt.key = opt.key || 'panic/test/';
|
||||
opt.interval = opt.interval || 20;
|
||||
opt.peers = opt.peers || [url];
|
||||
opt.amount = opt.amount || 1000;
|
||||
opt.path = opt.path || Gun.text.random();
|
||||
opt.data = opt.data || Gun.text.random();
|
||||
return opt;
|
||||
}
|
||||
Reference in New Issue
Block a user