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

Added tests for new app generation with handlebars templates #370

Merged
merged 1 commit into from
May 7, 2013
Merged
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
55 changes: 40 additions & 15 deletions test/cli/new.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var fs = require('fs');
var wrench = require('wrench');
var exec = require('child_process').exec;

describe('New app generator', function () {
describe('New app generator', function() {
var sailsbin = './bin/sails.js';
var appName = 'testApp';
var defaultTemplateLang = 'ejs';
Expand All @@ -26,11 +26,11 @@ describe('New app generator', function () {
});
});

describe('sails new <appname>', function () {
describe('sails new <appname>', function() {

it('should create new app in new folder', function(done) {

exec(sailsbin + ' new ' + appName, function (err) {
exec(sailsbin + ' new ' + appName, function(err) {
if (err) { done(new Error(err)); }

assert(checkGeneratedFiles(appName, defaultTemplateLang));
Expand All @@ -39,7 +39,7 @@ describe('New app generator', function () {
});

it('should not overwrite a folder', function(done) {
exec('mkdir ' + appName, function (err) {
exec('mkdir ' + appName, function(err) {
if (err) { done(new Error(err)); }

exec(sailsbin + ' new ' + appName, function(err) {
Expand All @@ -50,15 +50,15 @@ describe('New app generator', function () {
});
});

describe('sails new .', function () {
describe('sails new .', function() {

it('should create new app in existing folder', function(done) {

// make app folder and move into directory
fs.mkdirSync(appName);
process.chdir(appName);

exec( '.' + sailsbin + ' new .', function (err) {
exec( '.' + sailsbin + ' new .', function(err) {
if (err) { done(new Error(err)); }

// move from app to its parent directory
Expand All @@ -70,7 +70,7 @@ describe('New app generator', function () {
});

it('should not overwrite a folder', function(done) {
exec('mkdir ' + appName, function (err) {
exec('mkdir ' + appName, function(err) {
if (err) { done(new Error(err)); }

exec( '.' + sailsbin + ' new ' + appName, function(err) {
Expand All @@ -81,11 +81,11 @@ describe('New app generator', function () {
});
});

describe('sails new with no template option', function () {
describe('sails new with no template option', function() {

it('should create new app with ejs templates', function(done) {

exec(sailsbin + ' new ' + appName, function (err) {
exec(sailsbin + ' new ' + appName, function(err) {
if (err) { done(new Error(err)); }

assert(checkGeneratedFiles(appName, 'ejs'));
Expand All @@ -97,11 +97,11 @@ describe('New app generator', function () {
});
});

describe('sails new <appname> with options --template=ejs', function () {
describe('sails new <appname> with options --template=ejs', function() {

it('should create new app with ejs templates', function(done) {

exec(sailsbin + ' new ' + appName + ' --template=ejs', function (err) {
exec(sailsbin + ' new ' + appName + ' --template=ejs', function(err) {
if (err) { done(new Error(err)); }

assert(checkGeneratedFiles(appName, 'ejs'));
Expand All @@ -113,11 +113,11 @@ describe('New app generator', function () {
});
});

describe('sails new <appname> with options --template=jade', function () {
describe('sails new <appname> with options --template=jade', function() {

it('should create new app with jade templates', function(done) {

exec(sailsbin + ' new ' + appName + ' --template=jade', function (err) {
exec(sailsbin + ' new ' + appName + ' --template=jade', function(err) {
if (err) { done(new Error(err)); }

assert(checkGeneratedFiles(appName, 'jade'));
Expand All @@ -129,11 +129,11 @@ describe('New app generator', function () {
});
});

describe('sails new <appname> with options --template=haml', function () {
describe('sails new <appname> with options --template=haml', function() {

it('should create new app with haml templates', function(done) {

exec(sailsbin + ' new ' + appName + ' --template=haml', function (err) {
exec(sailsbin + ' new ' + appName + ' --template=haml', function(err) {
if (err) { done(new Error(err)); }

assert(checkGeneratedFiles(appName, 'haml'));
Expand All @@ -144,6 +144,22 @@ describe('New app generator', function () {
});
});
});

describe('sails new <appname> with options --template=handlebars', function() {

it('should create new app with handlebars templates', function(done) {

exec(sailsbin + ' new ' + appName + ' --template=handlebars', function(err) {
if (err) { done(new Error(err)); }

assert(checkGeneratedFiles(appName, 'handlebars'));

var viewConfig = fs.readFileSync('./' + appName + '/config/views.js', 'utf8');
assert(viewConfig.indexOf('hbs') !== -1);
done();
});
});
});
});

function checkGeneratedFiles(appName, templateLang) {
Expand Down Expand Up @@ -224,6 +240,15 @@ function checkGeneratedFiles(appName, templateLang) {
'views/home',
'views/home/index.haml'
];
} else if (templateLang === 'handlebars') {

templateFiles = [
'views/404.hbs',
'views/500.hbs',
'views/home',
'views/layout.hbs',
'views/home/index.hbs'
];
}

// Compare stringified arrays because [1,2,3] != (and !==) [1,2,3]
Expand Down