Skip to content

Commit

Permalink
feat: example for README
Browse files Browse the repository at this point in the history
  • Loading branch information
analog-nico committed May 2, 2016
1 parent 3518105 commit 11bbe13
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
.idea/
coverage/
node_modules/
test/results/routes.generated.txt
test/results/*.generated.txt
npm-debug.log
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

express-print-routes prints the tree of all your [Express](http://expressjs.com) routes and middlewares to a file.

```
router
├── query *
├── expressInit *
├── logger *
├── hpp *
├── router /^\/api\/?(?=\/|$)/
│ router
│ ├── bound dispatch /users/:id GET
│ │ └── __getUser / GET
│ │
│ └── bound dispatch /users/:id POST
│ └── __updateUser / POST
├── serveStatic *
└── __handleError *
```

## Installation

[![Build Status](https://img.shields.io/travis/analog-nico/express-print-routes/master.svg?style=flat-square)](https://travis-ci.org/analog-nico/express-print-routes)
Expand Down
16 changes: 16 additions & 0 deletions test/results/example.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
router
├── query *
├── expressInit *
├── logger *
├── hpp *
├── router /^\/api\/?(?=\/|$)/
│ router
│ ├── bound dispatch /users/:id GET
│ │ └── __getUser / GET
│ │
│ └── bound dispatch /users/:id POST
│ └── __updateUser / POST
├── serveStatic *
└── __handleError *
31 changes: 31 additions & 0 deletions test/spec/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,35 @@ describe('The express-print-routes middleware', function () {

});

it('should print example in README', function (done) {

var app = express();

app.use(function logger() {});
app.use(function hpp() {});

var router = express.Router();
app.use('/api', router);
router.get('/users/:id', function __getUser() {});
router.post('/users/:id', function __updateUser() {});

app.use(function serveStatic() {});
app.use(function __handleError() {});

printRoutes(app, path.join(__dirname, '../results/example.generated.txt'));


setTimeout(function () {

var expected = fs.readFileSync(path.join(__dirname, '../results/example.expected.txt'), 'utf8');
var generated = fs.readFileSync(path.join(__dirname, '../results/example.generated.txt'), 'utf8');

expect(generated).to.eql(expected);

done();

}, 100);

});

});

0 comments on commit 11bbe13

Please sign in to comment.