Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hypermonkey #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.sw*
node_modules
bundle*
6 changes: 5 additions & 1 deletion browser/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import httpism from 'httpism/browser';

export default {
loadTODOs() {
return window.fetch('/api/todos').then(res => res.json());
return httpism.get('/api/todos').then(res => res.body).catch(e => {
console.log('eee', e)
});
}
}
4 changes: 2 additions & 2 deletions browser/app.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsx plastiq.jsx */
import plastiq from 'plastiq';
/** @jsx hyperdom.jsx */
import hyperdom from 'hyperdom';
import Api from './api';

function navigateTo(route) {
Expand Down
6 changes: 3 additions & 3 deletions browser/browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import plastiq from 'plastiq';
import hyperdom from 'hyperdom';
import App from './app.jsx';
import router from 'plastiq-router';
import router from 'hyperdom-router';

router.start();
plastiq.append(document.body, new App({router: router}));
hyperdom.append(window.document.body, new App({router: router}));
6 changes: 1 addition & 5 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@ app.get('*', (req, res) => {
res.sendFile(process.cwd() + '/public/index.html');
});

var port = process.env.PORT || 4322;

app.listen(port, function () {
console.log(`listening on http://localhost:${port}/`);
});
export default app;
7 changes: 7 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import app from './app';

var port = process.env.PORT || 4322;

app.listen(port, function () {
console.log(`listening on http://localhost:${port}/`);
});
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"scripts": {
"start": "babel-node lib/app.js",
"start": "babel-node lib/server.js",
"dev": "nodemon --exec babel-node lib/app.js",
"test-karma": "karma start --single-run",
"test-electron": "electron-mocha --renderer --compilers js:babel-core/register test/**/*Spec.js",
"test-vdom": "mocha --compilers js:babel-core/register test/**/*Spec.js"
},
"dependencies": {
"babel-cli": "^6.16.0",
"babel-core": "^6.18.2",
"babel-plugin-transform-regenerator": "^6.16.1",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
Expand All @@ -17,22 +19,25 @@
"express": "^4.14.0",
"express-babelify-middleware": "^0.2.1",
"httpism": "^2.4.2",
"plastiq": "^1.33.0",
"plastiq-router": "^2.18.0"
"hyperdom": "^0.2.0",
"hyperdom-router": "featurist/plastiq-router#hyperdomify"
},
"devDependencies": {
"browser-monkey": "featurist/browser-monkey",
"browser-monkey": "github:featurist/browser-monkey",
"browserify": "^13.1.0",
"chai": "^3.5.0",
"electron-mocha": "^3.1.1",
"electron-prebuilt-compile": "^1.4.3",
"global": "^4.3.1",
"hypermonkey": "0.0.3",
"karma": "^1.3.0",
"karma-browserify": "^5.1.0",
"karma-chrome-launcher": "^2.0.0",
"karma-mocha": "^1.2.0",
"mocha": "^3.1.2",
"nodemon": "^1.11.0",
"vdom-query": "dereke/vdom-query#rewrite-like-jquery",
"vdom-query": "featurist/vdom-query",
"vinehill": "0.0.4",
"watchify": "^3.7.0"
},
"name": "bm-demo",
Expand Down
46 changes: 0 additions & 46 deletions test/mountApp.js

This file was deleted.

9 changes: 2 additions & 7 deletions test/pageHelper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { expect } from 'chai';

export default function(browser) {
var $ = browser.get('$');

return browser.component({
fetchTODOs: function() {
return this.find('button').click();
Expand All @@ -12,11 +10,8 @@ export default function(browser) {
return this.find('.loading', {text: 'Loading...'}).shouldExist();
},

expectTODOs: async function(...expectedTodos) {
var actualTodos = (await this.find('ul li').elements())
.map(e => $(e).innerText());

expect(actualTodos.sort()).to.eql(expectedTodos.sort());
expectTODOs: function(...expectedTodos) {
return this.find('ul li').shouldHave({text: expectedTodos, timeout: 2000});
}
});
}
30 changes: 0 additions & 30 deletions test/stubBrowser.js

This file was deleted.

27 changes: 15 additions & 12 deletions test/todosSpec.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
import router from 'plastiq-router';
import window from 'global';
import hypermonkey from 'hypermonkey';
import App from '../browser/app';
import mountApp from './mountApp';
import fakeApi from './fakeApi';
import ServerApp from '../lib/app';
import pageHelper from './pageHelper';

describe('todos app', () => {
var page;
var page, monkey;

beforeEach(() => {
router.start();
var browser = mountApp(new App({api: fakeApi, router: router}));
page = pageHelper(browser);
monkey = hypermonkey()
.withServer('http://localhost:1234', ServerApp)
.withApp(router => new App({router: router}))
.start();

page = pageHelper(monkey.browser);
});

afterEach(() => router.clear());
afterEach(() => monkey.stop());

context('when user lands on "/"', () => {
before(() => {
beforeEach(() => {
window.history.pushState(null, null, '/');
});

it('allows user to fetch todos', async () => {
await page.fetchTODOs();
await page.observeLoadingBar();
await page.expectTODOs('one', 'two');
await page.expectTODOs('buy beer', 'call Dave', 'watch tv');
});
});

context('when user lands on "/todos"', () => {
before(() => {
beforeEach(() => {
window.history.pushState(null, null, '/todos');
});

it('fetches todos automatically', async () => {
await page.observeLoadingBar();
await page.expectTODOs('one', 'two');
await page.expectTODOs('buy beer', 'call Dave', 'watch tv');
});
});
});
Loading