|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var path = require('path'); |
| 4 | +var helpers = require('yeoman-test'); |
| 5 | +var assert = require('yeoman-assert'); |
| 6 | + |
| 7 | +var getDefaultFilesForAppPath = function (appPath) { |
| 8 | + return [ |
| 9 | + appPath + '/404.html', |
| 10 | + appPath + '/favicon.ico', |
| 11 | + appPath + '/robots.txt', |
| 12 | + appPath + '/styles/main.scss', |
| 13 | + appPath + '/views/main.html', |
| 14 | + appPath + '/index.html', |
| 15 | + '.bowerrc', |
| 16 | + '.editorconfig', |
| 17 | + '.gitignore', |
| 18 | + '.jshintrc', |
| 19 | + 'Gruntfile.js', |
| 20 | + 'package.json', |
| 21 | + 'bower.json' |
| 22 | + ]; |
| 23 | +}; |
| 24 | + |
| 25 | +describe('angular:app', function () { |
| 26 | + var appPath = 'customAppPath'; |
| 27 | + |
| 28 | + beforeEach(function () { |
| 29 | + this.angular = helpers |
| 30 | + .run(require.resolve('../app')) |
| 31 | + .withGenerators([ |
| 32 | + require.resolve('../common'), |
| 33 | + require.resolve('../controller'), |
| 34 | + require.resolve('../main'), |
| 35 | + [helpers.createDummyGenerator(), 'karma:app'] |
| 36 | + ]) |
| 37 | + .withOptions({ |
| 38 | + 'skip-welcome-message': true, |
| 39 | + 'skip-message': true |
| 40 | + }) |
| 41 | + .withArguments(['upperCaseBug']) |
| 42 | + .withPrompts({ |
| 43 | + compass: true, |
| 44 | + bootstrap: true, |
| 45 | + compassBootstrap: true, |
| 46 | + modules: [] |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe('default settings', function () { |
| 51 | + beforeEach(function (done) { |
| 52 | + this.angular.on('end', done); |
| 53 | + }); |
| 54 | + |
| 55 | + it('generates base files', function () { |
| 56 | + assert.file(getDefaultFilesForAppPath('app')); |
| 57 | + assert.file([ |
| 58 | + '.jscsrc', |
| 59 | + 'app/index.html', |
| 60 | + 'app/scripts/app.js', |
| 61 | + 'app/scripts/controllers/main.js', |
| 62 | + 'test/spec/controllers/main.js' |
| 63 | + ]); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + describe('--coffee', function () { |
| 68 | + beforeEach(function (done) { |
| 69 | + this.angular.withOptions({ |
| 70 | + coffee: true |
| 71 | + }).on('end', done); |
| 72 | + }); |
| 73 | + |
| 74 | + it('generates CoffeeScript files', function () { |
| 75 | + assert.file([].concat(getDefaultFilesForAppPath('app'), [ |
| 76 | + 'app/scripts/app.coffee', |
| 77 | + 'app/scripts/controllers/main.coffee', |
| 78 | + 'test/spec/controllers/main.coffee' |
| 79 | + ])); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + describe('--typescript', function () { |
| 84 | + beforeEach(function (done) { |
| 85 | + this.angular.withOptions({ |
| 86 | + typescript: true |
| 87 | + }).on('end', done); |
| 88 | + }); |
| 89 | + |
| 90 | + it('generates CoffeeScript files', function () { |
| 91 | + assert.file([].concat(getDefaultFilesForAppPath('app'), [ |
| 92 | + 'app/scripts/app.ts', |
| 93 | + 'app/scripts/controllers/main.ts', |
| 94 | + 'test/spec/controllers/main.ts' |
| 95 | + ])); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + describe('--appPath', function () { |
| 100 | + beforeEach(function (done) { |
| 101 | + this.angular.withOptions({ |
| 102 | + appPath: 'alternative' |
| 103 | + }).on('end', done); |
| 104 | + }); |
| 105 | + |
| 106 | + it('generates base files inside the appPath', function () { |
| 107 | + assert.file(getDefaultFilesForAppPath('alternative')); |
| 108 | + assert.file([ |
| 109 | + '.jscsrc', |
| 110 | + 'alternative/scripts/app.js', |
| 111 | + 'alternative/scripts/controllers/main.js', |
| 112 | + 'test/spec/controllers/main.js' |
| 113 | + ]); |
| 114 | + }); |
| 115 | + }); |
| 116 | + |
| 117 | + describe('--appName', function () { |
| 118 | + beforeEach(function (done) { |
| 119 | + this.angular |
| 120 | + .withArguments(['upperCaseBug']) |
| 121 | + .on('end', done); |
| 122 | + }); |
| 123 | + |
| 124 | + it('generates the same appName in every file', function () { |
| 125 | + assert.fileContent( |
| 126 | + 'app/scripts/app.js', |
| 127 | + /module\('upperCaseBugApp'/ |
| 128 | + ); |
| 129 | + assert.fileContent( |
| 130 | + 'app/scripts/controllers/main.js', |
| 131 | + /module\('upperCaseBugApp'/ |
| 132 | + ); |
| 133 | + assert.fileContent( |
| 134 | + 'test/spec/controllers/main.js', |
| 135 | + /module\('upperCaseBugApp'/ |
| 136 | + ); |
| 137 | + |
| 138 | + assert.fileContent( |
| 139 | + 'app/index.html', |
| 140 | + /ng-app="upperCaseBugApp"/ |
| 141 | + ); |
| 142 | + }); |
| 143 | + }); |
| 144 | +}); |
0 commit comments