Skip to content

Commit 5dc65fb

Browse files
committed
feat: add complete E2E Todo app
1 parent 04c165e commit 5dc65fb

File tree

7 files changed

+56
-3
lines changed

7 files changed

+56
-3
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ node_js:
1212
before_install:
1313
- npm install cypress hyperapp
1414
script:
15+
# build full apps
16+
- npm run build
17+
# test everything
1518
- npm test -- --record
1619
after_success:
1720
- npm run semantic-release || true

actions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const toggle = ({ id, done }) => state => {
99
// as much as you want
1010
return {
1111
todos: state.todos.map(
12-
t => (t.id === id ? Cypress._.merge({}, t, { done }) : t)
12+
t => (t.id === id ? Object.assign({}, t, { done }) : t)
1313
)
1414
}
1515
}

apps/todo-app.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// import { h, app } from 'hyperapp'
2+
import { TodoList } from '../components/todo-list'
3+
import { toggle } from '../actions'
4+
5+
const { h, app } = window.hyperapp
6+
7+
// notice how much this application looks like TodoList "unit" test
8+
// in cypress/integration/todo-list-spec.js
9+
10+
console.log('starting todo app')
11+
const state = {
12+
todos: [
13+
{
14+
id: 1,
15+
value: 'Write HyperApp',
16+
done: false
17+
},
18+
{
19+
id: 2,
20+
value: 'Test it using Cypress',
21+
done: false
22+
}
23+
]
24+
}
25+
const actions = { toggle }
26+
const view = (state, actions) =>
27+
// renders TodoList component, passing
28+
// current state and actions
29+
h(TodoList, {
30+
todos: state.todos,
31+
toggle: actions.toggle
32+
})
33+
34+
app(state, actions, view, document.getElementById('app'))

apps/todo.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<body>
2+
<div id="app"></div>
3+
<script src="https://unpkg.com/[email protected]"></script>
4+
<script src="todo-app-bundle.umd.js"></script>
5+
</body>

components/todo-list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export const TodoList = ({ todos, toggle }) =>
1111
{ class: 'todo-list' },
1212
// for each todo object, call TodoItem view function,
1313
// combining todo with toggle action and passing as properties object
14-
todos.map(todo => h(TodoItem, Cypress._.merge({}, todo, { toggle })))
14+
todos.map(todo => h(TodoItem, Object.assign({}, todo, { toggle })))
1515
)
1616
])

cypress/integration/todo-app.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-env mocha */
2+
describe('Todo App E2E', () => {
3+
beforeEach(() => {
4+
cy.visit('apps/todo.html')
5+
})
6+
7+
it('works', () => {})
8+
})

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
"cy:run": "cypress run",
6363
"unit": "mocha src/*-spec.js",
6464
"unused-deps": "dependency-check --unused --no-dev .",
65-
"semantic-release": "semantic-action pre && npm publish && semantic-action post"
65+
"semantic-release": "semantic-action pre && npm publish && semantic-action post",
66+
"build": "npm run build:todo-app",
67+
"build:todo-app": "microbundle -i apps/todo-app.js -o apps/todo-app-bundle.js --format umd --compress false"
6668
},
6769
"release": {
6870
"analyzeCommits": "simple-commit-message",
@@ -76,6 +78,7 @@
7678
"git-issues": "1.3.1",
7779
"github-post-release": "1.13.1",
7880
"license-checker": "15.0.0",
81+
"microbundle": "0.2.4",
7982
"mocha": "4.0.1",
8083
"nsp": "3.1.0",
8184
"pre-git": "3.17.0",

0 commit comments

Comments
 (0)