-
Notifications
You must be signed in to change notification settings - Fork 73
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
0 parents
commit 6cbf223
Showing
16 changed files
with
759 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
.DS_Store | ||
*~ | ||
coverage | ||
test/test-bundle.js | ||
npm-debug.log |
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,30 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"unused": true, | ||
"eqnull": true, | ||
"browser": true, | ||
"node": true, | ||
"strict": true, | ||
"globalstrict": true, | ||
"globals": { "Pouch": true}, | ||
"white": true, | ||
"indent": 2, | ||
"maxlen": 100, | ||
"predef": [ | ||
"process", | ||
"global", | ||
"require", | ||
"console", | ||
"describe", | ||
"beforeEach", | ||
"afterEach", | ||
"it", | ||
"emit" | ||
] | ||
} |
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,7 @@ | ||
.git* | ||
node_modules | ||
.DS_Store | ||
*~ | ||
coverage | ||
npm-debug.log | ||
vendor/ |
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,35 @@ | ||
language: node_js | ||
|
||
services: | ||
- couchdb | ||
|
||
node_js: | ||
- "0.10" | ||
script: npm run $COMMAND | ||
before_script: | ||
- "export DISPLAY=:99.0" | ||
- "sh -e /etc/init.d/xvfb start" | ||
- "sleep 5" | ||
|
||
# Workaround for Selenium #3280 issue | ||
- "sudo sed -i 's/^127\\.0\\.0\\.1.*$/127.0.0.1 localhost/' /etc/hosts" | ||
|
||
# Lets know what CouchDB we are playing with | ||
# and make sure its logging debug | ||
- "curl -X GET http://127.0.0.1:5984/" | ||
- "curl -X PUT http://127.0.0.1:5984/_config/log/level -d '\"debug\"'" | ||
|
||
after_failure: | ||
- "curl -X GET http://127.0.0.1:5984/_log?bytes=1000000" | ||
|
||
env: | ||
matrix: | ||
- COMMAND=test | ||
- CLIENT=selenium:firefox COMMAND=test | ||
- CLIENT=selenium:phantomjs COMMAND=test | ||
- COMMAND=coverage | ||
|
||
branches: | ||
only: | ||
- master | ||
- /^pull*$/ |
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,103 @@ | ||
PouchDB Plugin Seed | ||
===== | ||
|
||
[![Build Status](https://travis-ci.org/pouchdb/plugin-seed.svg)](https://travis-ci.org/pouchdb/plugin-seed) | ||
|
||
Fork this project to build your first PouchDB plugin. It contains everything you need to test in Node, WebSQL, and IndexedDB. It also includes a Travis config file so you | ||
can automatically run the tests in Travis. | ||
|
||
Building | ||
---- | ||
npm install | ||
npm run build | ||
|
||
Your plugin is now located at `dist/pouchdb.mypluginname.js` and `dist/pouchdb.mypluginname.min.js` and is ready for distribution. | ||
|
||
Getting Started | ||
------- | ||
|
||
**First**, change the `name` in `package.json` to whatever you want to call your plugin. Change the `build` script so that it writes to the desired filename (e.g. `pouchdb.mypluginname.js`). Also, change the authors, description, git repo, etc. | ||
|
||
**Next**, modify the `index.js` to do whatever you want your plugin to do. Right now it just adds a `pouch.sayHello()` function that says hello: | ||
|
||
```js | ||
exports.sayHello = utils.toPromise(function (callback) { | ||
callback(null, 'hello'); | ||
}); | ||
``` | ||
|
||
**Optionally**, you can add some tests in `tests/test.js`. These tests will be run both in the local database and a remote CouchDB, which is expected to be running at localhost:5984 in "Admin party" mode. | ||
|
||
The sample test is: | ||
|
||
```js | ||
|
||
it('should say hello', function () { | ||
return db.sayHello().then(function (response) { | ||
response.should.equal('hello'); | ||
}); | ||
}); | ||
``` | ||
|
||
Testing | ||
---- | ||
|
||
### In Node | ||
|
||
This will run the tests in Node using LevelDB: | ||
|
||
npm test | ||
|
||
You can also check for 100% code coverage using: | ||
|
||
npm run coverage | ||
|
||
If you don't like the coverage results, change the values from 100 to something else in `package.json`, or add `/*istanbul ignore */` comments. | ||
|
||
|
||
If you have mocha installed globally you can run single test with: | ||
``` | ||
TEST_DB=local mocha --reporter spec --grep search_phrase | ||
``` | ||
|
||
The `TEST_DB` environment variable specifies the database that PouchDB should use (see `package.json`). | ||
|
||
### In the browser | ||
|
||
Run `npm run dev` and then point your favorite browser to [http://127.0.0.1:8001/test/index.html](http://127.0.0.1:8001/test/index.html). | ||
|
||
The query param `?grep=mysearch` will search for tests matching `mysearch`. | ||
|
||
### Automated browser tests | ||
|
||
You can run e.g. | ||
|
||
CLIENT=selenium:firefox npm test | ||
CLIENT=selenium:phantomjs npm test | ||
|
||
This will run the tests automatically and the process will exit with a 0 or a 1 when it's done. Firefox uses IndexedDB, and PhantomJS uses WebSQL. | ||
|
||
What to tell your users | ||
-------- | ||
|
||
Below is some boilerplate you can use for when you want a real README for your users. | ||
|
||
To use this plugin, include it after `pouchdb.js` in your HTML page: | ||
|
||
```html | ||
<script src="pouchdb.js"></script> | ||
<script src="pouchdb.mypluginname.js"></script> | ||
``` | ||
|
||
Or to use it in Node.js, just npm install it: | ||
|
||
``` | ||
npm install pouchdb-myplugin | ||
``` | ||
|
||
And then attach it to the `PouchDB` object: | ||
|
||
```js | ||
var PouchDB = require('pouchdb'); | ||
PouchDB.plugin(require('pouchdb-myplugin')); | ||
``` |
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,94 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
var PouchDB = require('pouchdb'); | ||
var COUCH_HOST = process.env.COUCH_HOST || 'http://127.0.0.1:5984'; | ||
var HTTP_PORT = 8001; | ||
|
||
var Promise = require('bluebird'); | ||
var request = require('request'); | ||
var http_server = require("http-server"); | ||
var fs = require('fs'); | ||
var indexfile = "./test/test.js"; | ||
var dotfile = "./test/.test-bundle.js"; | ||
var outfile = "./test/test-bundle.js"; | ||
var watchify = require("watchify"); | ||
var w = watchify(indexfile); | ||
|
||
w.on('update', bundle); | ||
bundle(); | ||
|
||
var filesWritten = false; | ||
var serverStarted = false; | ||
var readyCallback; | ||
|
||
function bundle() { | ||
var wb = w.bundle(); | ||
wb.on('error', function (err) { | ||
console.error(String(err)); | ||
}); | ||
wb.on("end", end); | ||
wb.pipe(fs.createWriteStream(dotfile)); | ||
|
||
function end() { | ||
fs.rename(dotfile, outfile, function (err) { | ||
if (err) { return console.error(err); } | ||
console.log('Updated:', outfile); | ||
filesWritten = true; | ||
checkReady(); | ||
}); | ||
} | ||
} | ||
|
||
function startServers(callback) { | ||
readyCallback = callback; | ||
// enable CORS globally, because it's easier this way | ||
|
||
var corsValues = { | ||
'/_config/httpd/enable_cors': 'true', | ||
'/_config/cors/origins': '*', | ||
'/_config/cors/credentials': 'true', | ||
'/_config/cors/methods': 'PROPFIND, PROPPATCH, COPY, MOVE, DELETE, ' + | ||
'MKCOL, LOCK, UNLOCK, PUT, GETLIB, VERSION-CONTROL, CHECKIN, ' + | ||
'CHECKOUT, UNCHECKOUT, REPORT, UPDATE, CANCELUPLOAD, HEAD, ' + | ||
'OPTIONS, GET, POST', | ||
'/_config/cors/headers': | ||
'Cache-Control, Content-Type, Depth, Destination, ' + | ||
'If-Modified-Since, Overwrite, User-Agent, X-File-Name, ' + | ||
'X-File-Size, X-Requested-With, accept, accept-encoding, ' + | ||
'accept-language, authorization, content-type, origin, referer' | ||
}; | ||
|
||
Promise.all(Object.keys(corsValues).map(function (key) { | ||
var value = corsValues[key]; | ||
return request({ | ||
method: 'put', | ||
url: COUCH_HOST + key, | ||
body: JSON.stringify(value) | ||
}); | ||
})).then(function () { | ||
return http_server.createServer().listen(HTTP_PORT); | ||
}).then(function () { | ||
console.log('Tests: http://127.0.0.1:' + HTTP_PORT + '/test/index.html'); | ||
serverStarted = true; | ||
checkReady(); | ||
}).catch(function (err) { | ||
if (err) { | ||
console.log(err); | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
|
||
function checkReady() { | ||
if (filesWritten && serverStarted && readyCallback) { | ||
readyCallback(); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
startServers(); | ||
} else { | ||
module.exports.start = startServers; | ||
} |
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,9 @@ | ||
#!/bin/bash | ||
|
||
: ${CLIENT:="node"} | ||
|
||
if [ "$CLIENT" == "node" ]; then | ||
npm run test-node | ||
else | ||
npm run test-browser | ||
fi |
Oops, something went wrong.