|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var ng = require('../helpers/ng'); |
| 4 | +var expect = require('chai').expect; |
| 5 | +var Blueprint = require('ember-cli/lib/models/blueprint'); |
| 6 | +var path = require('path'); |
| 7 | +var tmp = require('../helpers/tmp'); |
| 8 | +var root = process.cwd(); |
| 9 | +var conf = require('ember-cli/tests/helpers/conf'); |
| 10 | +var forEach = require('lodash/collection/forEach'); |
| 11 | +var existsSync = require('exists-sync'); |
| 12 | + |
| 13 | +var defaultIgnoredFiles = Blueprint.ignoredFiles; |
| 14 | + |
| 15 | +describe('Acceptance: ng generate', function() { |
| 16 | + this.timeout(20000); |
| 17 | + |
| 18 | + before(function() { |
| 19 | + conf.setup(); |
| 20 | + }); |
| 21 | + |
| 22 | + after(function() { |
| 23 | + conf.restore(); |
| 24 | + }); |
| 25 | + |
| 26 | + beforeEach(function() { |
| 27 | + Blueprint.ignoredFiles = defaultIgnoredFiles; |
| 28 | + |
| 29 | + return tmp.setup('./tmp') |
| 30 | + .then(function() { |
| 31 | + process.chdir('./tmp'); |
| 32 | + }).then(function() { |
| 33 | + return ng([ |
| 34 | + 'new', |
| 35 | + 'foo', |
| 36 | + '--skip-npm', |
| 37 | + '--skip-bower', |
| 38 | + '--skip-git' |
| 39 | + ]); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + afterEach(function() { |
| 44 | + return tmp.teardown('./tmp'); |
| 45 | + }); |
| 46 | + |
| 47 | + function confirmBlueprinted(files) { |
| 48 | + forEach(files, function(file) { |
| 49 | + expect(existsSync(file)); |
| 50 | + }); |
| 51 | + } |
| 52 | + |
| 53 | + function confirmBlueprintedComponent(settings) { |
| 54 | + settings = settings || { |
| 55 | + style: 'css' |
| 56 | + }; |
| 57 | + |
| 58 | + var componentPath = path.join(process.cwd(), 'src/app/components/bar'); |
| 59 | + |
| 60 | + var files = [ |
| 61 | + path.join(componentPath, 'bar.' + settings.style), |
| 62 | + path.join(componentPath, 'bar.html'), |
| 63 | + path.join(componentPath, 'bar.ts'), |
| 64 | + path.join(componentPath, 'bar.spec.ts') |
| 65 | + ]; |
| 66 | + |
| 67 | + confirmBlueprinted(files); |
| 68 | + } |
| 69 | + |
| 70 | + function confirmBlueprintedService() { |
| 71 | + process.chdir('./src/app/services/bar'); |
| 72 | + |
| 73 | + var servicePath = path.join(process.cwd(), 'src/app/services/bar'); |
| 74 | + |
| 75 | + var files = [ |
| 76 | + path.join(servicePath, 'bar.ts'), |
| 77 | + path.join(servicePath, 'bar.spec.ts') |
| 78 | + ]; |
| 79 | + |
| 80 | + confirmBlueprinted(files); |
| 81 | + } |
| 82 | + |
| 83 | + it('component', function() { |
| 84 | + return ng([ |
| 85 | + 'generate', |
| 86 | + 'component', |
| 87 | + 'bar' |
| 88 | + ]).then(confirmBlueprintedComponent()); |
| 89 | + }); |
| 90 | + |
| 91 | + it('component with less', function() { |
| 92 | + return ng([ |
| 93 | + 'generate', |
| 94 | + 'component', |
| 95 | + 'bar', |
| 96 | + '--style=less' |
| 97 | + ]).then(confirmBlueprintedComponent({style: 'less'})); |
| 98 | + }); |
| 99 | + |
| 100 | + it('services', function() { |
| 101 | + return ng([ |
| 102 | + 'generate', |
| 103 | + 'service', |
| 104 | + 'bar' |
| 105 | + ]).then(confirmBlueprintedService); |
| 106 | + }); |
| 107 | + |
| 108 | +}); |
0 commit comments