/test/test-requirejs.js

https://bitbucket.org/mcsaatchi/generator-carnaby · JavaScript · 151 lines · 129 code · 21 blank · 1 comment · 1 complexity · 0de83f69189a72ae91bd3da9cabfff72 MD5 · raw file

  1. /*global describe:true, beforeEach:true, it:true */
  2. 'use strict';
  3. var path = require('path');
  4. var helpers = require('yeoman-generator').test;
  5. var assert = require('assert');
  6. describe('Backbone generator with RequireJS', function () {
  7. beforeEach(function (done) {
  8. helpers.testDirectory(path.join(__dirname, './temp'), function (err) {
  9. if (err) {
  10. return done(err);
  11. }
  12. this.carnaby = {};
  13. this.carnaby.app = helpers.createGenerator('carnaby:app', [
  14. '../../app', [
  15. helpers.createDummyGenerator(),
  16. 'mocha:app'
  17. ]
  18. ]);
  19. this.carnaby.app.options['skip-install'] = true;
  20. helpers.mockPrompt(this.carnaby.app, {
  21. 'compassBootstrap': true,
  22. 'includeRequireJS': true
  23. });
  24. done();
  25. }.bind(this));
  26. });
  27. describe('creates expected files', function (done) {
  28. it('with compassBootstrap', function (done) {
  29. var expected = [
  30. ['bower.json', /("name": "temp")(|.|\n)*(requirejs)/],
  31. ['package.json', /"name": "temp"/],
  32. 'Gruntfile.js',
  33. 'app/404.html',
  34. 'app/favicon.ico',
  35. 'app/robots.txt',
  36. ['app/index.html', /(Bootstrap)(|.|\n)*(RequireJS)/i],
  37. 'app/.htaccess',
  38. '.gitignore',
  39. '.gitattributes',
  40. '.bowerrc',
  41. '.jshintrc',
  42. '.editorconfig',
  43. 'Gruntfile.js',
  44. 'package.json',
  45. 'app/scripts/vendor/bootstrap.js',
  46. ['app/scripts/main.js', /bootstrap/]
  47. ];
  48. this.carnaby.app.run({}, function () {
  49. helpers.assertFiles(expected);
  50. done();
  51. });
  52. });
  53. it('without compassBootstrap', function (done) {
  54. var expected = [
  55. ['bower.json', /("name": "temp")(|.|\n)*(requirejs)/],
  56. ['package.json', /"name": "temp"/],
  57. ['Gruntfile.js', /requirejs/],
  58. 'app/404.html',
  59. 'app/favicon.ico',
  60. 'app/robots.txt',
  61. ['app/index.html', /(RequireJS)/i],
  62. 'app/.htaccess',
  63. '.gitignore',
  64. '.gitattributes',
  65. '.bowerrc',
  66. '.jshintrc',
  67. '.editorconfig',
  68. 'Gruntfile.js',
  69. 'package.json',
  70. ];
  71. this.carnaby.app.run({}, function () {
  72. helpers.assertFiles(expected);
  73. done();
  74. });
  75. });
  76. });
  77. describe('Backbone Model', function () {
  78. it('creates backbone model', function (done) {
  79. var model = helpers.createGenerator('carnaby:model', ['../../model'], ['foo']);
  80. this.carnaby.app.run({}, function () {
  81. model.run([], function () {
  82. helpers.assertFiles([
  83. ['app/scripts/models/foo-model.js', /var FooModel = Backbone.Model.extend\(\{/]
  84. ]);
  85. });
  86. done();
  87. });
  88. });
  89. });
  90. describe('Backbone Collection with RequireJS', function () {
  91. it('creates backbone collection', function (done) {
  92. var collection = helpers.createGenerator('carnaby:collection', ['../../collection'], ['foo']);
  93. this.carnaby.app.run({}, function () {
  94. collection.run([], function () {
  95. helpers.assertFiles([
  96. ['app/scripts/collections/foo-collection.js', /var FooCollection = Backbone.Collection.extend\(\{/]
  97. ]);
  98. });
  99. done();
  100. });
  101. });
  102. });
  103. describe('Backbone Router with RequireJS', function () {
  104. it('creates backbone router', function (done) {
  105. var router = helpers.createGenerator('carnaby:router', ['../../router'], ['foo']);
  106. this.carnaby.app.run({}, function () {
  107. router.run([], function () {
  108. helpers.assertFiles([
  109. ['app/scripts/routes/foo-router.js', /var FooRouter = Backbone.Router.extend\(\{/]
  110. ]);
  111. });
  112. done();
  113. });
  114. });
  115. });
  116. describe('Backbone View', function () {
  117. it('creates backbone view', function (done) {
  118. var view = helpers.createGenerator('carnaby:view', ['../../view'], ['foo']);
  119. this.carnaby.app.run({}, function () {
  120. view.run([], function () {
  121. helpers.assertFiles([
  122. ['app/scripts/views/foo-view.js', /var FooView = Backbone.View.extend\(\{(.|\n)*app\/scripts\/templates\/foo.hbs/],
  123. 'app/scripts/templates/foo.hbs'
  124. ]);
  125. });
  126. done();
  127. });
  128. });
  129. });
  130. });