Skip to content

Commit

Permalink
fix(tests): style and generator updates
Browse files Browse the repository at this point in the history
Update style spacing (4 spaces to 2 spaces) and new lines. DRY up code a
bit.

Update testing syntax (assertFiles -> assertFile, assertFiles ->
assert.fileContents)
  • Loading branch information
eddiemonge committed May 6, 2014
1 parent ec5754f commit f8b3157
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 109 deletions.
109 changes: 55 additions & 54 deletions test/test-appname-substitution.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,68 @@ var helpers = require('yeoman-generator').test;


describe('Angular generator template mechanism', function () {
//TODO: Add underscore dependency and test with _.camelize(folderName);
var folderName = 'UpperCaseBug';
var angular;
//TODO: Add underscore dependency and test with _.camelize(folderName);
var folderName = 'UpperCaseBug';
var angular;

beforeEach(function (done) {
var deps = [
'../../app',
'../../common',
'../../controller',
'../../main', [
helpers.createDummyGenerator(),
'karma:app'
]
];
helpers.testDirectory(path.join(__dirname, folderName), function (err) {
if (err) {
done(err);
}
angular = helpers.createGenerator('angular:app', deps);
angular.options['skip-install'] = true;
done();
});
beforeEach(function (done) {
var deps = [
'../../app',
'../../common',
'../../controller',
'../../main', [
helpers.createDummyGenerator(),
'karma:app'
]
];
helpers.testDirectory(path.join(__dirname, folderName), function (err) {
if (err) {
done(err);
}
angular = helpers.createGenerator('angular:app', deps);
angular.options['skip-welcome-message'] = true;
angular.options['skip-install'] = true;
done();
});
});

it('should generate the same appName in every file', function (done) {
var expectedAppName = 'upperCaseBugApp';
var expected = [
'app/scripts/app.js',
'app/scripts/controllers/main.js',
'app/index.html',
'test/spec/controllers/main.js'
];
helpers.mockPrompt(angular, {
compass: true,
bootstrap: true,
compassBootstrap: true,
modules: []
});
it('should generate the same appName in every file', function (done) {
var expectedAppName = 'upperCaseBugApp';
var expected = [
'app/scripts/app.js',
'app/scripts/controllers/main.js',
'app/index.html',
'test/spec/controllers/main.js'
];
helpers.mockPrompt(angular, {
compass: true,
bootstrap: true,
compassBootstrap: true,
modules: []
});

angular.run({}, function () {
// Check if all files are created for the test
helpers.assertFiles(expected);
angular.run({}, function () {
// Check if all files are created for the test
helpers.assertFiles(expected);

// read JS Files
var app_js = fs.readFileSync('app/scripts/app.js', 'utf8');
var main_js = fs.readFileSync('app/scripts/controllers/main.js', 'utf8');
var main_test_js = fs.readFileSync('test/spec/controllers/main.js', 'utf8');
// read JS Files
var app_js = fs.readFileSync('app/scripts/app.js', 'utf8');
var main_js = fs.readFileSync('app/scripts/controllers/main.js', 'utf8');
var main_test_js = fs.readFileSync('test/spec/controllers/main.js', 'utf8');

// Test JS Files
var regex_js = new RegExp('module\\(\'' + expectedAppName + '\'');
assert.ok(regex_js.test(app_js), 'app.js template using a wrong appName');
assert.ok(regex_js.test(main_js), 'main.js template using a wrong appName');
assert.ok(regex_js.test(main_test_js), 'controller spec template using a wrong appName');
// Test JS Files
var regex_js = new RegExp('module\\(\'' + expectedAppName + '\'');
assert.ok(regex_js.test(app_js), 'app.js template using a wrong appName');
assert.ok(regex_js.test(main_js), 'main.js template using a wrong appName');
assert.ok(regex_js.test(main_test_js), 'controller spec template using a wrong appName');

// read HTML file
var index_html = fs.readFileSync('app/index.html', 'utf8');
// read HTML file
var index_html = fs.readFileSync('app/index.html', 'utf8');

// Test HTML File
var regex_html = new RegExp('ng-app=\"' + expectedAppName + '\"');
assert.ok(regex_html.test(index_html), 'index.html template using a wrong appName');
done();
});
// Test HTML File
var regex_html = new RegExp('ng-app=\"' + expectedAppName + '\"');
assert.ok(regex_html.test(index_html), 'index.html template using a wrong appName');
done();
});
});
});
102 changes: 50 additions & 52 deletions test/test-file-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ var _ = require('underscore.string');

describe('Angular generator', function () {
var angular;
var expected = [
'app/.htaccess',
'app/404.html',
'app/favicon.ico',
'app/robots.txt',
'app/styles/main.scss',
'app/views/main.html',
'.bowerrc',
'Gruntfile.js',
'package.json',
'bower.json',
'app/index.html'
];

beforeEach(function (done) {
var deps = [
Expand All @@ -27,6 +40,7 @@ describe('Angular generator', function () {
}
angular = helpers.createGenerator('angular:app', deps);
angular.options['skip-install'] = true;
angular.options['skip-welcome-message'] = true;
done();
});
});
Expand All @@ -40,27 +54,17 @@ describe('Angular generator', function () {
});

angular.run({}, function () {
helpers.assertFiles(['.bowerrc', '.gitignore', '.editorconfig', '.jshintrc']);
helpers.assertFile(['.bowerrc', '.gitignore', '.editorconfig', '.jshintrc']);
done();
});
});

it('creates expected files', function (done) {
var expected = ['app/.htaccess',
'app/404.html',
'app/favicon.ico',
'app/robots.txt',
'app/styles/main.scss',
'app/views/main.html',
['.bowerrc', /"directory": "app\/bower_components"/],
'Gruntfile.js',
'package.json',
['bower.json', /"name":\s+"temp"/],
'app/scripts/app.js',
'app/index.html',
'app/scripts/controllers/main.js',
'test/spec/controllers/main.js'
];
it('creates expected JS files', function (done) {
var expect = [].concat(expected, [
'app/scripts/app.js',
'app/scripts/controllers/main.js',
'test/spec/controllers/main.js'
]);
helpers.mockPrompt(angular, {
compass: true,
bootstrap: true,
Expand All @@ -69,27 +73,17 @@ describe('Angular generator', function () {
});

angular.run({}, function() {
helpers.assertFiles(expected);
helpers.assertFile(expected);
done();
});
});

it('creates coffeescript files', function (done) {
var expected = ['app/.htaccess',
'app/404.html',
'app/favicon.ico',
'app/robots.txt',
'app/styles/main.scss',
'app/views/main.html',
['.bowerrc', /"directory": "app\/bower_components"/],
'Gruntfile.js',
'package.json',
['bower.json', /"name":\s+"temp"/],
'app/scripts/app.coffee',
'app/index.html',
'app/scripts/controllers/main.coffee',
'test/spec/controllers/main.coffee'
];
var expect = [].concat(expected, [
'app/scripts/app.coffee',
'app/scripts/controllers/main.coffee',
'test/spec/controllers/main.coffee'
]);
helpers.mockPrompt(angular, {
compass: true,
bootstrap: true,
Expand All @@ -99,7 +93,7 @@ describe('Angular generator', function () {

angular.env.options.coffee = true;
angular.run([], function () {
helpers.assertFiles(expected);
helpers.assertFile(expected);
done();
});
});
Expand Down Expand Up @@ -141,10 +135,23 @@ describe('Angular generator', function () {
modules: []
});
angular.run([], function (){
angularGenerator.options['skip-welcome-message'] = true;
angularGenerator.run([], function () {
helpers.assertFiles([
[path.join('app/scripts', targetDirectory, name + '.js'), new RegExp(generatorType + '\\(\'' + scriptNameFn(name) + suffix + '\'', 'g')],
[path.join('test/spec', targetDirectory, name + '.js'), new RegExp('describe\\(\'' + _.classify(specType) + ': ' + specNameFn(name) + suffix + '\'', 'g')]
assert.fileContent([
[
path.join('app/scripts', targetDirectory, name + '.js'),
new RegExp(
generatorType + '\\(\'' + scriptNameFn(name) + suffix + '\'',
'g'
)
],
[
path.join('test/spec', targetDirectory, name + '.js'),
new RegExp(
'describe\\(\'' + _.classify(specType) + ': ' + specNameFn(name) + suffix + '\'',
'g'
)
]
]);
done();
});
Expand Down Expand Up @@ -174,24 +181,15 @@ describe('Angular generator', function () {
generatorTest(generatorType, 'service', 'services', nameFn, nameFn, '', done);
}

it('should generate a new constant', function (done) {
serviceTest('constant', _.camelize, done);
});

it('should generate a new service', function (done) {
serviceTest('service', _.classify, done);
});

it('should generate a new factory', function (done) {
serviceTest('factory', _.camelize, done);
['constant', 'factory', 'provider', 'value'].forEach(function(t) {
it('should generate a new ' + t, function (done) {
serviceTest(t, _.camelize, done);
});
});

it('should generate a new provider', function (done) {
serviceTest('provider', _.camelize, done);
});

it('should generate a new value', function (done) {
serviceTest('value', _.camelize, done);
it('should generate a new service', function (done) {
serviceTest('service', _.capitalize, done);
});
});

Expand Down
6 changes: 3 additions & 3 deletions test/test-route-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var _ = require('underscore.string');


describe('Angular generator route mechanism', function () {

var folderName = 'routeTests';
var angular;

Expand All @@ -32,6 +31,7 @@ describe('Angular generator route mechanism', function () {
}
angular = helpers.createGenerator('angular:app', deps);
angular.options['skip-install'] = true;
angular.options['skip-welcome-message'] = true;

helpers.mockPrompt(angular, {
compass: true,
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('Angular generator route mechanism', function () {
angularRouteGenerator.run({}, function(){

// Check if new files are created for the route
helpers.assertFiles(expected);
helpers.assertFile(expected);

var app_js = fs.readFileSync('app/scripts/app.js', 'utf8');
var route_regex = new RegExp('when\\(\'/' + route + '\'');
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('Angular generator route mechanism', function () {
angularRouteGenerator.run({}, function(){

// Check if new files are created for the route
helpers.assertFiles(expected);
helpers.assertFile(expected);

var app_js = fs.readFileSync('app/scripts/app.js', 'utf8');
var route_regex = new RegExp('when\\(\'/' + uri + '\'');
Expand Down

0 comments on commit f8b3157

Please sign in to comment.