-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for the rang:screen command
- Loading branch information
Showing
7 changed files
with
186 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
node_modules | ||
test/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Dependencies | ||
*/ | ||
var gulp = require('gulp'); | ||
var mocha = require('gulp-mocha'); | ||
|
||
gulp.task('test', function () { | ||
return gulp.src(['test/test-*.js'], { read: false }) | ||
.pipe(mocha({ | ||
reporter: 'dot', | ||
globals: { | ||
chai: require('chai') | ||
} | ||
})); | ||
}); | ||
|
||
gulp.task('watch-test', function() { | ||
gulp.watch(['generators/**', 'test/**'], ['test']); | ||
}); | ||
|
||
gulp.task('default', ['test']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Silence Yeoman during tests | ||
* uses https://github.com/balderdashy/fixture-stdout | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Fixture = require('fixture-stdout'); | ||
var fixtureOut = new Fixture(); | ||
var fixtureErr = new Fixture({ | ||
stream: process.stderr | ||
}); | ||
|
||
var _writesOut = []; | ||
var _writesErr = []; | ||
|
||
/** | ||
* Mute | ||
*/ | ||
function mute() { | ||
var captureStdout = function ( string ) { | ||
_writesOut.push({ string: string }); | ||
return false; | ||
}; | ||
|
||
var captureStderr = function ( string ) { | ||
_writesErr.push({ string: string }); | ||
return false; | ||
}; | ||
|
||
fixtureOut.capture( captureStdout ); | ||
fixtureErr.capture( captureStderr ); | ||
} | ||
|
||
/** | ||
* Unmute | ||
*/ | ||
function unmute() { | ||
fixtureOut.release(); | ||
fixtureErr.release(); | ||
} | ||
|
||
// Return the output that was captured | ||
function getMutedWrites() { | ||
return { | ||
out: _writesOut, | ||
err: _writesErr | ||
} | ||
} | ||
|
||
module.exports.mute = mute; | ||
module.exports.unmute = unmute; | ||
module.exports.getMutedWrites = getMutedWrites; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Dependencies | ||
*/ | ||
var path = require('path'); | ||
var helpers = require('yeoman-generator').test; | ||
var assert = require('yeoman-generator').assert; | ||
var output = require('./mute'); | ||
|
||
describe('rang:screen generator', function () { | ||
var rangScreen; | ||
var tempFolder = 'tmp/tmpRangScreen'; | ||
var mockPrompts = { | ||
screen: 'test', | ||
url: 'test' | ||
}; | ||
|
||
var expectedFile = [ | ||
'workspace/scripts/app/screens/test/main.js', | ||
'workspace/scripts/app/screens/test/templates/test.tmpl.html', | ||
'workspace/scripts/app/screens/test/controllers/testController.js' | ||
]; | ||
|
||
var expectedContent = [ | ||
[ | ||
'workspace/scripts/app/screens/test/main.js', | ||
/var testTemplate = require\('text!\.\/templates\/test\.tmpl\.html'\);/ | ||
], | ||
[ | ||
'workspace/scripts/app/screens/test/main.js', | ||
/var testController = require\('\.\/controllers\/testController'\);/ | ||
], | ||
[ 'workspace/scripts/app/screens/test/main.js', /Module: test screen/ ], | ||
[ 'workspace/scripts/app/screens/test/main.js', /var module = angular.module\('app\.test', \[]\);/ ], | ||
[ 'workspace/scripts/app/screens/test/main.js', /controller\( testController \)/ ], | ||
[ 'workspace/scripts/app/screens/test/main.js', /state\('root\.test'/ ], | ||
[ 'workspace/scripts/app/screens/test/main.js', /url: '\/test',/ ], | ||
[ 'workspace/scripts/app/screens/test/main.js', /template: testTemplate,/ ], | ||
[ 'workspace/scripts/app/screens/test/main.js', /controller: 'testController'/ ], | ||
[ 'workspace/scripts/app/screens/test/controllers/testController.js', /testController:/ ], | ||
[ 'workspace/scripts/app/appModules.js', /require\('screens\/test\/main'\)/ ] | ||
]; | ||
|
||
beforeEach(function (done) { | ||
helpers.testDirectory( path.join( __dirname, tempFolder ), function ( error ) { | ||
if ( error ) { | ||
done( error ); | ||
} | ||
|
||
rangScreen = helpers.createGenerator( 'rang:screen', ['../../../generators/screen'], [], {} ); | ||
rangScreen.on('run', output.mute); | ||
rangScreen.on('end', output.unmute); | ||
|
||
helpers.stub( rangScreen, '_getDependencies', function () { | ||
return "return [\n" + | ||
" require('screens/old/module')\n" + | ||
"];"; | ||
}); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should generate the expected files and their content', function ( done ) { | ||
helpers.mockPrompt( rangScreen, mockPrompts ); | ||
|
||
rangScreen.run({}, function () { | ||
|
||
assert.file( expectedFile ); | ||
assert.fileContent( expectedContent ); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); |