Skip to content

Commit

Permalink
Add blueprint + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed Jan 20, 2017
1 parent ecd1c4e commit b4212c7
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 3 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
bower.json
ember-cli-build.js
testem.js
node-tests/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env:
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-default
- EMBER_TRY_SCENARIO=node-tests

matrix:
fast_finish: true
Expand Down
1 change: 0 additions & 1 deletion blueprints/ember-power-select/files/app/styles/app.scss

This file was deleted.

34 changes: 33 additions & 1 deletion blueprints/ember-power-select/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
/* eslint-env node */
'use strict';

const path = require('path');
const fs = require('fs');

module.exports = {
normalizeEntityName: function() {
normalizeEntityName() {
// this prevents an error when the entityName is
// not specified (since that doesn't actually matter
// to us
},

afterInstall() {
let dependencies = this.project.dependencies();
let type;
let importStatement = '\n@import "ember-power-select";\n';

if ('ember-cli-sass' in dependencies) {
type = 'scss';
} else if ('ember-cli-less' in dependencies) {
type = 'less';
}

if (type) {
let stylePath = path.join('app', 'styles');
let file = path.join(stylePath, `app.${type}`);

if (!fs.existsSync(stylePath)) {
fs.mkdirSync(stylePath);
}
if (fs.existsSync(file)) {
this.ui.writeLine(`Added import statement to ${file}`);
return this.insertIntoFile(file, importStatement, {});
} else {
fs.writeFileSync(file, importStatement);
this.ui.writeLine(`Created ${file}`);
}
}
}
};
7 changes: 7 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ module.exports = {
npm: {
devDependencies: {}
}
},
{
name: 'node-tests',
command: 'npm run nodetest',
bower: {
dependencies: {}
}
}
]
};
103 changes: 103 additions & 0 deletions node-tests/blueprints/ember-power-select-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* eslint-env node, mocha */
'use strict';

const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
const setupTestHooks = blueprintHelpers.setupTestHooks;
const emberNew = blueprintHelpers.emberNew;
const emberGenerate = blueprintHelpers.emberGenerate;
const modifyPackages = blueprintHelpers.modifyPackages;

const chai = require('ember-cli-blueprint-test-helpers/chai');
const file = chai.file;
const expect = chai.expect;

const fs = require('fs');
const path = require('path');

function createStyleFixture(name) {
let stylePath = path.join('app', 'styles');
if (!fs.existsSync(stylePath)) {
fs.mkdirSync(stylePath);
}
fs.writeFileSync(path.join(stylePath, name), 'body { color: red; }');
}

describe('Acceptance: ember generate ember-power-select', function() {
setupTestHooks(this);

it('skips blueprint when no preprocessor present', function() {
let args = ['ember-power-select'];

// pass any additional command line options in the arguments array
return emberNew()
.then(() => emberGenerate(args, (file) => {
expect(file('app/styles/app.scss')).to.not.exist;
expect(file('app/styles/app.less')).to.not.exist;
}));
});

it('creates app.scss if not existing', function() {
let args = ['ember-power-select'];

// pass any additional command line options in the arguments array
return emberNew()
.then(() => modifyPackages([
{ name: 'ember-cli-sass' }
]))
.then(() => emberGenerate(args))
.then(() => {
expect(file('app/styles/app.scss'))
.to.contain('@import "ember-power-select";');
expect(file('app/styles/app.less')).to.not.exist;
});
});

it('adds @import to existing app.scss', function() {
let args = ['ember-power-select'];

// pass any additional command line options in the arguments array
return emberNew()
.then(() => modifyPackages([
{ name: 'ember-cli-sass' }
]))
.then(() => createStyleFixture('app.scss'))
.then(() => emberGenerate(args, (file) => {
expect(file('app/styles/app.scss')).to.contain('@import "ember-power-select";');
expect(file('app/styles/app.less')).to.not.exist;
}));
});

it('creates app.less if not existing', function() {
let args = ['ember-power-select'];

// pass any additional command line options in the arguments array
return emberNew()
.then(() => modifyPackages([
{ name: 'ember-cli-less' }
]))
.then(() => emberGenerate(args))
.then(() => {
expect(file('app/styles/app.less'))
.to.contain('@import "ember-power-select";');
expect(file('app/styles/app.scss')).to.not.exist;
});
});

it('adds @import to existing app.less', function() {
let args = ['ember-power-select'];

// pass any additional command line options in the arguments array
return emberNew()
.then(() => modifyPackages([
{ name: 'ember-cli-less' }
]))
.then(() => createStyleFixture('app.less'))
.then(() => emberGenerate(args))
.then(() => {
expect(file('app/styles/app.less'))
.to.contain('body { color: red; }')
.to.contain('@import "ember-power-select";');
expect(file('app/styles/app.scss')).to.not.exist;
});
});
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember try:each"
"test": "ember try:each",
"nodetest": "mocha node-tests --recursive"
},
"repository": {
"type": "git",
Expand All @@ -37,6 +38,7 @@
"ember-ajax": "^2.4.1",
"ember-cli": "^2.11.0-beta.1",
"ember-cli-app-version": "^2.0.0",
"ember-cli-blueprint-test-helpers": "0.14.0",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-deploy": "0.5.0",
"ember-cli-eslint": "3.0.0",
Expand All @@ -63,6 +65,7 @@
"liquid-fire": "0.26.7",
"loader.js": "^4.0.10",
"memory-scroll": "0.2.0",
"mocha": "2.5.3",
"simple-git": "^1.10.0"
},
"keywords": [
Expand Down

0 comments on commit b4212c7

Please sign in to comment.