-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pemrouz
committed
Aug 5, 2016
1 parent
13170ab
commit 2cd0007
Showing
5 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'utilise' | ||
import rijs from './rijs' | ||
const ripple = rijs() | ||
, test = require('tap').test | ||
|
||
test('api', t => { | ||
t.plan(2) | ||
t.same(typeof ripple.upload, 'function') | ||
t.same(typeof ripple.upload.log, 'object') | ||
}) | ||
|
||
test('upload', t => { | ||
// t.plan(2) | ||
const form = once(document.body)('form', 1) | ||
, canvas = form('canvas', 1).node().toBlob(createBlob) | ||
|
||
function createBlob(file) { | ||
t.plan(3) | ||
|
||
// you would normally create this object from a HTML form | ||
// (see https://github.com/utilise/utilise#--form) | ||
// since we can't programmatically manipulate input[type="file"] | ||
// we mimic the same | ||
const photos = [file] | ||
, forms = { name: 'foo', photos } | ||
photos.__proto__ = FileList.prototype | ||
file.name = 'photo.jpg' | ||
|
||
// upload the form and listen for updates | ||
ripple.upload('events', form) | ||
.on('progress.event', progress => | ||
t.ok(progress > 0 && progress < 100, 'progress is number') | ||
) | ||
.on('response.event', ([status, message]) => { | ||
t.same(status, 200, 'status 200') | ||
t.same(message, 'ok', 'message ok') | ||
form.remove() | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import backpressure from 'rijs.backpressure' | ||
import components from 'rijs.components' | ||
import versioned from 'rijs.versioned' | ||
import sessions from 'rijs.sessions' | ||
import features from 'rijs.features' | ||
import offline from 'rijs.offline' | ||
import helpers from 'rijs.helpers' | ||
import precss from 'rijs.precss' | ||
import shadow from 'rijs.shadow' | ||
import resdir from 'rijs.resdir' | ||
import mysql from 'rijs.mysql' | ||
import serve from 'rijs.serve' | ||
import needs from 'rijs.needs' | ||
import sync from 'rijs.sync' | ||
import core from 'rijs.core' | ||
import data from 'rijs.data' | ||
import css from 'rijs.css' | ||
import fn from 'rijs.fn' | ||
import db from 'rijs.db' | ||
import upload from '../' | ||
|
||
export default function create(opts){ | ||
const ripple = core() // empty base collection of resources | ||
|
||
// enrich.. | ||
data(ripple) // register data types | ||
css(ripple) // register css types | ||
fn(ripple) // register fn types | ||
helpers(ripple) // expose helper functions and constants | ||
mysql(ripple) // adds mysql adaptor crud hooks | ||
db(ripple, opts) // enable external connections | ||
components(ripple) // invoke web components, fn.call(<el>, data) | ||
needs(ripple) // define default attrs for components | ||
precss(ripple) // preapplies scoped css | ||
shadow(ripple) // encapsulates with shadow dom or closes gap | ||
serve(ripple, opts) // serve client libraries | ||
offline(ripple) // loads/saves from/to localstorage | ||
sync(ripple, opts) // syncs resources between server/client | ||
backpressure(ripple) // restricts broadcast to clients based on need | ||
features(ripple) // extend components with features | ||
versioned(ripple) // versioning info and time travel | ||
sessions(ripple, opts) // populates sessionid on each connection | ||
resdir(ripple, opts) // loads from resources folder | ||
upload(ripple) | ||
|
||
return ripple | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'utilise' | ||
import rijs from './rijs' | ||
import popper from 'popper' | ||
import devnull from 'dev-null' | ||
|
||
// the popper js api returns a ripple instance | ||
// which we can later extend with more resources | ||
const ripple = popper({ | ||
watch: '.' | ||
, ripple: rijs | ||
, runner: 'tape' | ||
, browsers: ['ie11', 'chrome', 'firefox'] | ||
, port: 1945 | ||
, tests: `browserify ./test/client.js \ | ||
-t babelify \ | ||
-t tapify \ | ||
-i socket.io \ | ||
-i socket.io-client \ | ||
-i socket.io-stream \ | ||
| sed -E \"s/require\\('socket\\.io-stream'\\)/window.ss/g\"` | ||
// socket.io{-stream} does not play well in browserify | ||
// so we include these as globals | ||
, globals: ` | ||
<script src="socket.io/socket.io.js"></script> | ||
<script src="https://npmcdn.com/socket.io-stream/socket.io-stream.js"></script> | ||
` | ||
}) | ||
|
||
// register a resource | ||
ripple('events', [], { from }) | ||
|
||
// request handler | ||
function from(req, res){ | ||
// ignore all other requests to this resource | ||
if (req.type !== 'upload') return | ||
|
||
// pipe the photos somewhere | ||
req.value | ||
.photos[0] | ||
.pipe(devnull()) | ||
.on('finish', finish) | ||
|
||
function finish() { | ||
if (req.value.name !== 'foo') | ||
throw new Error('name not as expected') | ||
|
||
if (req.value.photos.length !== 1) | ||
throw new Error('photos not as expected') | ||
|
||
res(200, 'ok') | ||
} | ||
} |