This repository was archived by the owner on Apr 24, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
var util = require ( 'util' ) ;
3
+ var path = require ( 'path' ) ;
4
+ var fs = require ( 'fs' ) ;
3
5
var yeoman = require ( 'yeoman-generator' ) ;
4
6
5
7
var ModuleGenerator = module . exports = function ModuleGenerator ( ) {
@@ -24,3 +26,22 @@ ModuleGenerator.prototype.module = function module() {
24
26
ModuleGenerator . prototype . test = function test ( ) {
25
27
this . template ( 'example.spec.js' , 'test/specs/' + this . name + '.spec.js' ) ;
26
28
} ;
29
+
30
+ ModuleGenerator . prototype . loadSpecs = function loadSpecs ( ) {
31
+ var specsToLoad , specFileContent , specTpl ;
32
+ var specs = [ ] ;
33
+ var specsPath = path . join ( process . cwd ( ) , 'test/specs' ) ;
34
+
35
+ if ( fs . existsSync ( specsPath ) ) {
36
+ specs = fs . readdirSync ( specsPath ) ;
37
+ specs = specs . map ( function cutFileending ( specFile ) {
38
+ return specFile . replace ( '.js' , '' ) ;
39
+ } ) ;
40
+ specsToLoad = '"' + specs . join ( '", "' ) + '"' ;
41
+ specTpl = path . join ( this . sourceRoot ( ) , 'spec.js' ) ;
42
+ specFileContent = this . readFileAsString ( specTpl ) ;
43
+ specFileContent = specFileContent . replace ( '<%= specs %>' , specsToLoad ) ;
44
+
45
+ this . write ( path . join ( process . cwd ( ) , 'test/spec.js' ) , specFileContent ) ;
46
+ }
47
+ } ;
Original file line number Diff line number Diff line change @@ -10,6 +10,28 @@ define(['modules/<%= name %>'], function (<%= name %>) {
10
10
// Test suite <%= name %>
11
11
describe('<%= name %>', function () {
12
12
13
+ <<<<<<< HEAD
14
+ =======
15
+ it('is available', function () {
16
+ expect(<%= name %>).not.toBe(null);
17
+ });
18
+
19
+ it('has getter for event name', function () {
20
+ expect(<%= name %>.getEventName()).toBe('_test');
21
+ });
22
+
23
+ it('fires event on init', function () {
24
+ var eventCalled;
25
+
26
+ $(document).on(<%= name %>.getEventName(), function () {
27
+ eventCalled = true;
28
+ });
29
+
30
+ <%= name %>.init();
31
+
32
+ expect(eventCalled).toBeTruthy();
33
+ });
34
+ >>>>>>> Add test-spec in test/spec.js.
13
35
});
14
36
15
37
});
You can’t perform that action at this time.
0 commit comments