Skip to content

Commit

Permalink
(#44) - Create separate dist for levelalt and add query param for tes…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
qs44 committed Mar 24, 2014
1 parent 8ef8062 commit 8693dfd
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -23,9 +23,9 @@ env:
- CLIENT=node npm test
- NATIVEPROMISE=1 CLIENT=firefox npm test
- CLIENT=chrome npm test
- CLIENT=firefox INDEX_FILE=index-levelalt.js npm test
- CLIENT=firefox LEVEL_BACKEND=leveljs npm test

matrix:
allow_failures:
- env: CLIENT=chrome npm test
- env: CLIENT=firefox INDEX_FILE=index-levelalt.js npm test
- env: CLIENT=firefox LEVEL_BACKEND=leveljs npm test
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -114,6 +114,8 @@ Alternative Backends
--------------------------------------
PouchDB is looking to support alternative backends that comply with the [LevelDOWN API](https://github.com/rvagg/abstract-leveldown). Simply include `INDEX_FILE=index-levelalt.js` in your `npm run build` and `npm run dev` commands to experiment with this feature!

Doing so will also create a separate distribution, for example, `pouchdb-leveljs.js` rather than `pouchdb-nightly.js`. In order to test a different distribution from `pouchdb-nightly.js`, you must specify in the testing URL: http://127.0.0.1:8000/tests/test.html?sourceFile=pouchdb-leveljs.js.

Git Essentials
--------------------------------------

Expand Down
12 changes: 8 additions & 4 deletions bin/build-js.sh
@@ -1,12 +1,13 @@
#!/bin/bash

: ${INDEX_FILE:="index.js"}

if [ "$INDEX_FILE" == "index-levelalt.js" ]; then
if [ "$LEVEL_BACKEND" == "leveljs" ]; then
node_modules/.bin/browserify lib/index-levelalt.js \
--require ./lib/index:./lib/index-levelalt.js \
--standalone PouchDB \
--outfile dist/pouchdb-nightly.js
--outfile dist/pouchdb-leveljs.js

node_modules/.bin/uglifyjs dist/pouchdb-leveljs.js -mc \
> dist/pouchdb-leveljs.min.js
else
node_modules/.bin/browserify lib/index.js \
--exclude ./adapters/leveldb \
Expand All @@ -16,4 +17,7 @@ else
--ignore level-sublevel \
--standalone PouchDB \
--outfile dist/pouchdb-nightly.js

node_modules/.bin/uglifyjs dist/pouchdb-nightly.js -mc \
> dist/pouchdb-nightly.min.js
fi
13 changes: 8 additions & 5 deletions bin/dev-server.js
Expand Up @@ -13,17 +13,20 @@ fs.mkdir('dist', function (e) {
}
});

var indexfile;
if (process.env.INDEX_FILE) {
indexfile = "./lib/" + process.env.INDEX_FILE;
var indexfile, dotfile, outfile;
if (process.env.LEVEL_BACKEND) {
//indexfile = "./lib/index-" + process.env.LEVEL_BACKEND + ".js";
indexfile = "./lib/index-levelalt.js";
dotfile = "./dist/.pouchdb-" + process.env.LEVEL_BACKEND + ".js";
outfile = "./dist/pouchdb-" + process.env.LEVEL_BACKEND + ".js";
} else {
indexfile = "./lib/index.js";
dotfile = "./dist/.pouchdb-nightly.js";
outfile = "./dist/pouchdb-nightly.js";
}

var watchify = require("watchify");
var w = watchify(indexfile);
var dotfile = "./dist/.pouchdb-nightly.js";
var outfile = "./dist/pouchdb-nightly.js";

w.on('update', bundle);
bundle();
Expand Down
3 changes: 3 additions & 0 deletions bin/test-browser.js
Expand Up @@ -26,6 +26,9 @@ if (process.env.GREP) {
if (process.env.NATIVEPROMISE) {
qs.noBluebird = 1;
}
if (process.env.LEVEL_BACKEND) {
qs.sourceFile = "pouchdb-" + process.env.LEVEL_BACKEND + ".js";
}
testUrl += '?';
testUrl += querystring.stringify(qs);

Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -49,8 +49,7 @@
"scripts": {
"jshint": "jshint -c .jshintrc bin/ lib/ tests/*.js",
"build-js": "./bin/build-js.sh",
"uglify": "uglifyjs dist/pouchdb-nightly.js -mc > dist/pouchdb-nightly.min.js",
"build": "mkdir -p dist && npm run build-js && npm run uglify",
"build": "mkdir -p dist && npm run build-js",
"test-node": "./bin/run-mocha.sh",
"test-browser": "mkdir -p dist && npm run build-js && ./bin/test-browser.js",
"dev": "./bin/dev-server.js",
Expand Down
1 change: 0 additions & 1 deletion tests/test.html
Expand Up @@ -24,7 +24,6 @@
});
var should = chai.should();
</script>
<script src='../dist/pouchdb-nightly.js'></script>
<script src='deps/pouchdb-1.1.0-postfixed.js'></script>
<script src='deps/pouchdb-2.0.0-postfixed.js'></script>
<script src='utils.js'></script>
Expand Down
85 changes: 63 additions & 22 deletions tests/webrunner.js
Expand Up @@ -2,29 +2,70 @@

'use strict';

var runner = mocha.run();

window.results = {
lastPassed: '',
passed: 0,
failed: 0,
failures: []
};

runner.on('pass', function (e) {
window.results.lastPassed = e.title;
window.results.passed++;
});
// use query parameter sourceFile if present,
// eg: test.html?sourceFile=pouchdb-leveljs.js
var sourceFile = window.location.search.match(/[?&]sourceFile=([^&]+)/);

if (!sourceFile) {
sourceFile = '../dist/pouchdb-nightly.js';
} else {
sourceFile = '../dist/' + sourceFile[1];
}

// Thanks to http://engineeredweb.com/blog/simple-async-javascript-loader/
function asyncLoadScript(url, callback) {

// Create a new script and setup the basics.
var script = document.createElement("script"),
firstScript = document.getElementsByTagName('script')[0];

script.async = true;
script.src = url;

// Handle the case where an optional callback was passed in.
if ("function" === typeof(callback)) {
script.onload = function () {
callback();

// Clear it out to avoid getting called more than once or any memory leaks.
script.onload = script.onreadystatechange = undefined;
};
script.onreadystatechange = function () {
if ("loaded" === script.readyState || "complete" === script.readyState) {
script.onload();
}
};
}

runner.on('fail', function (e) {
window.results.failed++;
window.results.failures.push({
title: e.title,
err: e.err
// Attach the script tag to the page (before the first script) so the
//magic can happen.
firstScript.parentNode.insertBefore(script, firstScript);
}

asyncLoadScript(sourceFile, function () {
var runner = mocha.run();
window.results = {
lastPassed: '',
passed: 0,
failed: 0,
failures: []
};

runner.on('pass', function (e) {
window.results.lastPassed = e.title;
window.results.passed++;
});
});

runner.on('end', function () {
window.results.completed = true;
window.results.passed++;
runner.on('fail', function (e) {
window.results.failed++;
window.results.failures.push({
title: e.title,
err: e.err
});
});

runner.on('end', function () {
window.results.completed = true;
window.results.passed++;
});
});

0 comments on commit 8693dfd

Please sign in to comment.