Skip to content

Commit

Permalink
Add warning when using the default view engine
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Oct 27, 2016
1 parent ee43be8 commit 2718358
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The quickest way to get started with express is to utilize the executable `expre
Create the app:

```bash
$ express /tmp/foo && cd /tmp/foo
$ express --view=hbs /tmp/foo && cd /tmp/foo
```

Install dependencies:
Expand Down
21 changes: 20 additions & 1 deletion bin/express
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,18 @@ function main() {

// View engine
if (program.view === undefined) {
program.view = 'jade'
if (program.ejs) program.view = 'ejs'
if (program.hbs) program.view = 'hbs'
if (program.hogan) program.view = 'hjs'
if (program.pug) program.view = 'pug'
}

// Default view engine
if (program.view === undefined) {
warning("the default view engine will not be jade in future releases\nuse `--view=jade' or `--help' for additional options")
program.view = 'jade'
}

// Generate application
emptyDirectory(destinationPath, function (empty) {
if (empty || program.force) {
Expand All @@ -411,6 +416,20 @@ function main() {
});
}

/**
* Display a warning similar to how errors are displayed by commander.
*
* @param {String} message
*/

function warning(message) {
console.error()
message.split('\n').forEach(function (line) {
console.error(' warning: %s', line)
})
console.error()
}

/**
* echo str > path.
*
Expand Down
25 changes: 19 additions & 6 deletions test/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ describe('express(1)', function () {
var ctx = setupTestEnvironment(this.fullTitle())

it('should create basic app', function (done) {
run(ctx.dir, [], function (err, stdout) {
runRaw(ctx.dir, [], function (err, code, stdout, stderr) {
if (err) return done(err);
ctx.files = parseCreatedFiles(stdout, ctx.dir)
ctx.output = stdout
ctx.stderr = stderr
ctx.stdout = stdout
assert.equal(ctx.files.length, 17)
done();
});
});

it('should print jade view warning', function () {
assert.equal(ctx.stderr, "\n warning: the default view engine will not be jade in future releases\n warning: use `--view=jade' or `--help' for additional options\n\n")
})

it('should provide debug instructions', function () {
assert.ok(/DEBUG=test-express\(1\)-\(no-args\)-(?:[0-9\.]+):\* (?:\& )?npm start/.test(ctx.output))
assert.ok(/DEBUG=test-express\(1\)-\(no-args\)-(?:[0-9\.]+):\* (?:\& )?npm start/.test(ctx.stdout))
});

it('should have basic files', function () {
Expand Down Expand Up @@ -912,16 +917,16 @@ function run(dir, args, callback) {
return callback(err);
}

process.stderr.write(stderr);
process.stderr.write(stripWarnings(stderr))

try {
assert.equal(stderr, '');
assert.equal(stripWarnings(stderr), '')
assert.strictEqual(code, 0);
} catch (e) {
return callback(e);
}

callback(null, stdout.replace(/\x1b\[(\d+)m/g, '_color_$1_'));
callback(null, stripColors(stdout))
});
}

Expand Down Expand Up @@ -971,3 +976,11 @@ function setupTestEnvironment (title) {

return ctx
}

function stripColors (str) {
return str.replace(/\x1b\[(\d+)m/g, '_color_$1_')
}

function stripWarnings (str) {
return str.replace(/\n(?: warning: [^\n]+\n)+\n/g, '')
}

0 comments on commit 2718358

Please sign in to comment.