UNPKG

4.28 kBJavaScriptView Raw
1
2var fs = require('fs');
3var path = require('path');
4var sys = require('util');
5
6var memfs = {}, writeFileSync, readFileSync, writeSync, closeSync, existsSync,
7 mkdirSync, chmodSync, exit;
8
9
10describe('Generators API', function() {
11
12 var app, compound, args = ['--quiet'];
13
14 before(function(done) {
15 app = getApp();
16 compound = app.compound;
17 compound.generators.init(compound);
18 // compound.generators.quiet = true;
19 stubFS();
20 compound.on('ready', function() {
21 done();
22 });
23 });
24
25 after(unstubFS);
26
27 var output, puts;
28
29 beforeEach(function() {
30 output = [];
31 puts = sys.puts;
32 sys.puts = function(str) {
33 output.push(str.replace(/\u001b\[\d+m/g, ''));
34 };
35 });
36
37 afterEach(function() {
38 sys.puts = puts;
39 });
40
41 it('should generate app', function () {
42 compound.generators.perform('init', ['--stylus']);
43 output.should.eql([
44 'create app/',
45 'create app/assets/',
46 'create app/assets/coffeescripts/',
47 'create app/assets/stylesheets/',
48 'create app/models/',
49 'create app/controllers/',
50 'create app/helpers/',
51 'create app/tools/',
52 'create app/views/',
53 'create app/views/layouts/',
54 'create db/',
55 'create db/seeds/',
56 'create db/seeds/development/',
57 'create log/',
58 'create public/',
59 'create public/images',
60 'create public/stylesheets/',
61 'create public/javascripts/',
62 'create node_modules/',
63 'create config/',
64 'create config/locales/',
65 'create config/initializers/',
66 'create config/environments/',
67 'create app/assets/coffeescripts/application.coffee',
68 'create app/assets/stylesheets/application.styl',
69 'create app/tools/database.js',
70 'create config/environment.js',
71 'create config/environments/development.js',
72 'create config/environments/production.js',
73 'create config/environments/test.js',
74 'create config/routes.js',
75 'create config/autoload.js',
76 'create db/schema.js',
77 'create public/index.html',
78 'create public/stylesheets/bootstrap.css',
79 'create public/stylesheets/bootstrap-responsive.css',
80 'create public/images/glyphicons-halflings-white.png',
81 'create public/images/glyphicons-halflings.png',
82 'create public/images/compound.png',
83 'create public/javascripts/rails.js',
84 'create public/javascripts/bootstrap.js',
85 'create public/javascripts/application.js',
86 'create public/favicon.ico',
87 'create Procfile',
88 'create README.md',
89 'create package.json',
90 'create server.js',
91 'create .gitignore',
92 'create config/database.js',
93 'create app/views/layouts/application_layout.ejs',
94 'create app/controllers/application_controller.js'
95 ]);
96 });
97
98 it('should generate app', function () {
99 var package = path.normalize(__dirname + '/../package.json');
100 delete memfs[package];
101 compound.generators.perform('init', ['--db', 'mongodb']);
102 memfs[package].should.include('jugglingdb-mongodb');
103 });
104});
105
106function stubFS() {
107 exit = process.exit;
108 writeFileSync = fs.writeFileSync;
109 readFileSync = fs.readFileSync;
110 closeSync = fs.closeSync;
111 writeSync = fs.writeSync;
112 existsSync = fs.existsSync;
113 mkdirSync = fs.mkdirSync;
114 chmodSync = fs.chmodSync;
115 fs.mkdirSync = function (name) {
116 memfs[name] = true;
117 };
118 fs.chmodSync = function () {};
119 fs.writeFileSync = function (name, content) {
120 memfs[name] = content;
121 return name;
122 };
123 fs.existsSync = function (path) {
124 return path in memfs;
125 };
126}
127
128function unstubFS() {
129 fs.writeFileSync = writeFileSync;
130 fs.mkdirSync = mkdirSync;
131 fs.chmodSync = chmodSync;
132 fs.existsSync = existsSync;
133 process.exit = exit;
134}