1 | fs = require 'fs'
|
2 | fsu = require 'fs-util'
|
3 | path = require 'path'
|
4 | vows = require "vows"
|
5 | assert = require "assert"
|
6 |
|
7 | {spawn_toaster,snapshot} = require "#{__dirname}/utils/utils"
|
8 |
|
9 |
|
10 |
|
11 | vows.describe('Generators (-n, -i)')
|
12 | .addBatch( 'A new project created':
|
13 |
|
14 |
|
15 |
|
16 | 'with default values':
|
17 | topic: ->
|
18 | folder = path.resolve "#{__dirname}/_tmp/new_default_project"
|
19 |
|
20 |
|
21 | fsu.rm_rf folder if fs.existsSync folder
|
22 |
|
23 |
|
24 | toaster = spawn_toaster ['-n', folder]
|
25 | toaster.stdout.on 'data', (data)->
|
26 |
|
27 | question = data.toString()
|
28 | if question.indexOf( "Path to your src folder" ) >= 0
|
29 | toaster.stdin.write '\n'
|
30 |
|
31 | else if question.indexOf( "Path to your release file" ) >= 0
|
32 | toaster.stdin.write '\n'
|
33 |
|
34 | else if question.indexOf( "Starting from your webroot" ) >= 0
|
35 | toaster.stdin.write '\n'
|
36 |
|
37 | toaster.stderr.on 'data', (data)=>
|
38 | @callback null, null
|
39 |
|
40 | toaster.on 'exit', (code)=>
|
41 | model = snapshot "#{__dirname}/_templates/new_default_project"
|
42 | created = snapshot "#{__dirname}/_tmp/new_default_project"
|
43 | @callback model, created
|
44 |
|
45 | undefined
|
46 |
|
47 | 'should match the default template':( model, created )->
|
48 | assert.isObject model
|
49 | assert.isObject created
|
50 | for alias, contents of model
|
51 | a = created[ alias ]
|
52 | b = contents
|
53 | assert.equal a, b
|
54 |
|
55 |
|
56 |
|
57 | 'with custom values':
|
58 | topic: ->
|
59 |
|
60 |
|
61 | if fs.existsSync (folder = __dirname + "/_tmp/new_custom_project")
|
62 | fsu.rm_rf folder
|
63 |
|
64 | toaster = spawn_toaster ['-n', folder]
|
65 | toaster.stdout.on 'data', (data)->
|
66 |
|
67 | question = data.toString()
|
68 | if question.indexOf( "Path to your src folder" ) >= 0
|
69 | toaster.stdin.write 'custom_src'
|
70 |
|
71 | else if question.indexOf( "Path to your release file" ) >= 0
|
72 | toaster.stdin.write 'custom_www/custom_js/custom_app.js'
|
73 |
|
74 | else if question.indexOf( "Starting from your webroot" ) >= 0
|
75 | toaster.stdin.write 'custom_js'
|
76 |
|
77 | toaster.stderr.on 'data', (data)->
|
78 | @callback null, null
|
79 |
|
80 | toaster.on 'exit', (code)=>
|
81 | model = snapshot "#{__dirname}/_templates/new_custom_project"
|
82 | created = snapshot "#{__dirname}/_tmp/new_custom_project"
|
83 | @callback model, created
|
84 |
|
85 | undefined
|
86 |
|
87 | 'should match the custom template':( model, created )->
|
88 | assert.isObject model
|
89 | assert.isObject created
|
90 | for alias, contents of model
|
91 | a = created[ alias ]
|
92 | b = contents
|
93 | assert.equal a, b
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | ).addBatch( 'A config file created for an existent project':
|
100 | topic: ->
|
101 | template = (__dirname + "/_templates/existing_project/toaster.coffee")
|
102 | folder = (__dirname + "/_tmp/existing_project")
|
103 | created = "#{folder}/toaster.coffee"
|
104 |
|
105 |
|
106 | fsu.rm_rf folder if fs.existsSync folder
|
107 | fs.mkdirSync folder, "0777"
|
108 |
|
109 | toaster = spawn_toaster ['-i', '_tmp/existing_project']
|
110 |
|
111 | toaster.stdout.on 'data', (data)->
|
112 | question = data.toString()
|
113 | if question.indexOf( "Path to your src folder" ) >= 0
|
114 | toaster.stdin.write 'src'
|
115 |
|
116 | else if question.indexOf( "Path to your release file" ) >= 0
|
117 | toaster.stdin.write 'www/js/app.js'
|
118 |
|
119 | else if question.indexOf( "Starting from your webroot" ) >= 0
|
120 | toaster.stdin.write 'js'
|
121 |
|
122 | toaster.stderr.on 'data', (data)=>
|
123 | @callback null, null
|
124 |
|
125 | toaster.on 'exit', (code)=>
|
126 | model = fs.readFileSync template, "utf-8"
|
127 | created = fs.readFileSync created, "utf-8"
|
128 | @callback model, created
|
129 |
|
130 | undefined
|
131 |
|
132 | 'should match the \'toaster.coffee\' template':( model, created )->
|
133 | assert.equal true, true
|
134 |
|
135 | ).export module |
\ | No newline at end of file |