Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | const path = require('path'); |
| 4 | const helpers = require('yeoman-test'); |
| 5 | const assert = require('yeoman-assert'); |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 6 | const rimraf = require('rimraf'); |
| 7 | const mockery = require('mockery'); |
| 8 | const wiredep = require('wiredep'); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 9 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 10 | const firstCharTouppercase = string => string.replace(/^./, string[0].toUpperCase()) |
| 11 | |
| 12 | // get bower deps installed in ngXosLib |
| 13 | let bowerDeps = wiredep({ |
| 14 | cwd: path.join(__dirname, '../../'), // pretending to be in the ngXosLib root |
| 15 | exclude: ['Chart.js'] |
| 16 | }); |
Matteo Scandolo | db20d5a | 2016-05-16 10:31:32 -0700 | [diff] [blame] | 17 | bowerDeps = bowerDeps.js.map(d => { |
| 18 | let path = d.match(/bower_components\/([1-9a-zA-Z\-`.]+)\//); |
| 19 | if(path){ |
| 20 | return path[1]; |
| 21 | } |
| 22 | }); |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 23 | |
| 24 | // test values |
| 25 | const viewName = 'testDashboard'; |
Matteo Scandolo | ce6624c | 2016-05-11 12:10:17 -0700 | [diff] [blame] | 26 | const fileName = firstCharTouppercase(viewName); |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 27 | const testPath = path.join(__dirname, `../../../ngXosViews/${viewName}/`); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 28 | |
| 29 | const getDefaultFiles = () => { |
| 30 | return [ |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 31 | '.bowerrc', |
| 32 | '.eslintrc', |
| 33 | '.gitignore', |
| 34 | 'bower.json', |
| 35 | 'gulpfile.js', |
| 36 | 'karma.conf.js', |
| 37 | 'package.json', |
| 38 | 'src/index.html', |
| 39 | ].map(i => `${testPath}${i}`); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 42 | const yeomanUserMock = { |
| 43 | git: { |
| 44 | name: () => 'Test User', |
| 45 | email: () => 'test@mail.org' |
| 46 | } |
Matteo Scandolo | b70db48 | 2016-07-06 10:39:36 -0700 | [diff] [blame] | 47 | }; |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 48 | |
| 49 | mockery.enable({ |
| 50 | warnOnReplace: false, |
| 51 | warnOnUnregistered: false, |
| 52 | useCleanCache: true, |
| 53 | }); |
| 54 | mockery.resetCache(); |
| 55 | mockery.registerMock('../node_modules/yeoman-generator/lib/actions/user', yeomanUserMock); |
| 56 | |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 57 | describe('Yeoman XOS generator', function () { |
| 58 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 59 | beforeEach(() => { |
| 60 | }); |
| 61 | |
| 62 | before(done => { |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 63 | this.generator = helpers |
| 64 | .run(require.resolve('../app')) |
| 65 | .inDir(testPath) |
| 66 | .withOptions({ 'skip-install': true }) |
| 67 | .withPrompts({ |
Matteo Scandolo | 4ac9a0b | 2016-05-23 15:31:25 -0700 | [diff] [blame] | 68 | name: viewName |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 69 | }) |
| 70 | .on('end', done); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 71 | }); |
| 72 | |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 73 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 74 | it('should generate base files in the correct directory', () => { |
| 75 | assert.file(getDefaultFiles()); |
| 76 | }); |
| 77 | |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 78 | it('should write username in package & bower json', () => { |
| 79 | assert.fileContent(`${testPath}package.json`, '"author": "Test User"'); |
| 80 | assert.fileContent(`${testPath}bower.json`, '"Test User <test@mail.org>"') |
| 81 | }); |
| 82 | |
| 83 | it('should add all xosLib dependencies in the dev section of bower.json', () => { |
| 84 | bowerDeps.forEach(d => { |
| 85 | assert.fileContent(`${testPath}bower.json`, d); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 86 | }); |
| 87 | }); |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 88 | |
| 89 | it('should set the right module name in all the files', () => { |
| 90 | assert.fileContent(`${testPath}src/index.html`, `ng-app="xos.${viewName}"`) |
Matteo Scandolo | ce6624c | 2016-05-11 12:10:17 -0700 | [diff] [blame] | 91 | assert.fileContent(`${testPath}src/index.html`, `id="xos${fileName}"`) |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 92 | assert.fileContent(`${testPath}src/js/main.js`, `angular.module('xos.${viewName}', [`) |
Matteo Scandolo | ce6624c | 2016-05-11 12:10:17 -0700 | [diff] [blame] | 93 | assert.fileContent(`${testPath}src/sass/main.scss`, `#xos${fileName}`) |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 94 | }); |
| 95 | |
Matteo Scandolo | ce6624c | 2016-05-11 12:10:17 -0700 | [diff] [blame] | 96 | it('should set correct paths in build file', () => { |
| 97 | assert.fileContent(`${testPath}gulp/build.js`, `angular.module('xos.${viewName}')`) |
| 98 | assert.fileContent(`${testPath}gulp/build.js`, `options.dashboards + 'xos${fileName}.html'`) |
| 99 | assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'css/xos${fileName}.css'`) |
| 100 | assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}.css'))`) |
| 101 | assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}.js'))`) |
| 102 | assert.fileContent(`${testPath}gulp/build.js`, `module: 'xos.${viewName}'`) |
| 103 | assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'js/vendor/xos${fileName}Vendor.js'`) |
| 104 | assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'js/xos${fileName}.js'`) |
| 105 | assert.fileContent(`${testPath}gulp/build.js`, `options.static + 'css/xos${fileName}.css'`) |
| 106 | assert.fileContent(`${testPath}gulp/build.js`, `.pipe(concat('xos${fileName}Vendor.js'))`) |
Matteo Scandolo | 07dd276 | 2016-05-11 11:52:10 -0700 | [diff] [blame] | 107 | }); |
| 108 | |
| 109 | after(done => { |
| 110 | // deleting the folder used for test |
| 111 | rimraf(testPath, {}, done) |
| 112 | }); |
Matteo Scandolo | 124bbfc | 2016-05-11 09:03:25 -0700 | [diff] [blame] | 113 | }); |