From abb94735ee87d7bb44880cf52d230c26febddc3c Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Mon, 3 Oct 2016 22:50:21 -0400 Subject: [PATCH] fix(redirect): redirecting to index page after each action, closes #9 --- .gitignore | 1 + cypress/integration/try-cy-spec.js | 17 +++++++++++++---- package.json | 10 +++++----- src/app.js | 10 +++++++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 8ff716c..f6a89fd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ src/.DS_Store todos.json cypress/screenshots/ npm-debug.log +.DS_Store diff --git a/cypress/integration/try-cy-spec.js b/cypress/integration/try-cy-spec.js index 0c9e697..d8e219b 100644 --- a/cypress/integration/try-cy-spec.js +++ b/cypress/integration/try-cy-spec.js @@ -16,6 +16,13 @@ describe('a cy unit test', function () { describe('todomvc app', function () { const baseUrl = Cypress.env('HOST') || 'http://localhost:3000' + function addTodo () { + cy.get('.new-todo') + .type('new todo{enter}') + .get('ul.todo-list') + .find('li').should('not.be.empty') + } + beforeEach(function () { cy.visit(baseUrl) }) @@ -29,10 +36,12 @@ describe('todomvc app', function () { }) it('can insert new todo', function () { - cy.get('.new-todo') - .type('new todo{enter}') - .get('ul.todo-list') - .find('li').should('not.be.empty') + addTodo() + }) + + it('can reload the page after adding new todo', () => { + addTodo() + cy.reload() }) it('can view active todos', function () { diff --git a/package.json b/package.json index f0631d4..2881f4b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "npm run lint", "lint": "standard *.js src/**/*.js", - "start": "node --harmony src/start.js", + "start": "node src/start.js", "semantic-release": "semantic-release pre && npm publish && semantic-release post", "commit": "commit-wizard", "prod-test": "CYPRESS_HOST=$NOW_URL cypress ci" @@ -36,8 +36,8 @@ "homepage": "https://github.com/bahmutov/todomvc-express#readme", "dependencies": { "body-parser": "1.15.2", - "check-more-types": "2.22.0", - "express": "4.14.0", + "check-more-types": "2.23.0", + "express": "5.0.0-alpha.2", "fake-todos": "1.8.0", "js-beautify": "1.6.4", "lazy-ass": "1.5.0", @@ -49,8 +49,8 @@ }, "devDependencies": { "pre-git": "3.10.0", - "semantic-release": "6.3.0", - "standard": "8.0.0" + "semantic-release": "6.3.1", + "standard": "8.3.0" }, "config": { "pre-git": { diff --git a/src/app.js b/src/app.js index b1c7610..54fe7a6 100644 --- a/src/app.js +++ b/src/app.js @@ -30,6 +30,10 @@ function sendIndexPage (req, res) { res.send(renderIndexPage()) } +function toIndex (req, res) { + res.redirect('/') +} + function sendAppCss (req, res) { const cssPath = require('path').join(__dirname, 'app.css') const css = require('fs').readFileSync(cssPath, 'utf-8') @@ -76,8 +80,8 @@ app.get('/', sendIndexPage) app.get('/app.css', sendAppCss) // actions -app.post('/', addTodo, sendIndexPage) -app.delete('/', deleteTodo, sendIndexPage) -app.patch('/', markTodo, sendIndexPage) +app.post('/', addTodo, toIndex) +app.delete('/', deleteTodo, toIndex) +app.patch('/', markTodo, toIndex) module.exports = app