Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
added --app-name option to fastboot-test blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
simonihmig committed Feb 18, 2017
1 parent 6e094d7 commit 6621164
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const expect = require('chai').expect;
const setupTest = require('ember-fastboot-addon-tests').setupTest;

describe('index', function() {
setupTest(/* appName, options */);
setupTest('fastboot'/*, options */);

it('renders', function() {
return this.visit('/')
Expand Down
2 changes: 1 addition & 1 deletion blueprints/fastboot-test/files/fastboot-tests/__test__.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const expect = require('chai').expect;
const setupTest = require('ember-fastboot-addon-tests').setupTest;

describe('<%= camelizedModuleName %>', function() {
setupTest(/* appName, options */);
setupTest('<%= appName %>'/*, options */);

it('renders', function() {
return this.visit('/<%= url %>')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
});

export default Router;
33 changes: 31 additions & 2 deletions blueprints/fastboot-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@ const EmberRouterGenerator = require('ember-router-generator');
module.exports = {
description: 'Generate a FastBoot test with a custom route/template added to the temporary app',

availableOptions: [
{
name: 'app-name',
type: String,
default: 'fastboot'
}
],

locals(options) {
let packageName = options.project.name();
let moduleName = (options.entity && options.entity.name) || packageName;

return {
url: moduleName
url: moduleName,
appName: options.appName
};
},

fileMapTokens: function() {
return {
__appName__: function(options) {
return options.locals.appName;
}
};
},

Expand All @@ -32,6 +49,18 @@ module.exports = {

afterUninstall(options) {
updateRouter.call(this, 'remove', options);
},

files() {
let files = this._super();
if (this.options) {
let routerFile = `fastboot-tests/fixtures/${this.options.appName}/app/router.js`;
let routerBlueprintFile = 'fastboot-tests/fixtures/__appName__/app/router.js';
if (fs.existsSync(routerFile)) {
files = files.filter((file) => file !== routerBlueprintFile);
}
}
return files;
}
};

Expand All @@ -52,7 +81,7 @@ function updateRouter(action, options) {
}

function findRouter(options) {
return [options.project.root, 'fastboot-tests', 'fixtures', 'fastboot', 'app', 'router.js'];
return [options.project.root, 'fastboot-tests', 'fixtures', options.appName, 'app', 'router.js'];
}

function writeRoute(action, name, options) {
Expand Down
1 change: 0 additions & 1 deletion lib/tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function setupTestsForFastboot(appName, options) {
})
.then(function() {
// @todo add packages from options
// @todo add appname option to blueprint + test
return app.runEmberCommand('install', 'ember-cli-fastboot');
})
.then(function() {
Expand Down
1 change: 1 addition & 0 deletions node-tests/blueprints/ember-fastboot-addon-tests-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Acceptance: ember generate and destroy ember-fastboot-addon-tests', fu
.to.contain('Router.map(function() {');

expect(file('fastboot-tests/index-test.js'))
.to.contain('setupTest(\'fastboot\'/*, options */);')
.to.contain('return this.visit(\'/\')');

expect(file('fastboot-tests/fixtures/fastboot/app/templates/index.hbs'))
Expand Down
48 changes: 42 additions & 6 deletions node-tests/blueprints/fastboot-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,79 @@ const chai = require('ember-cli-blueprint-test-helpers/chai');
const file = chai.file;
const expect = chai.expect;

const defaultBlueprintArgs = ['ember-fastboot-addon-tests', 'dummy'];

describe('Acceptance: ember generate and destroy fastboot-test', function() {
setupTestHooks(this);

it('fastboot-test foo', function() {
let args = ['fastboot-test', 'foo'];

return emberNew()
.then(() => emberGenerate(defaultBlueprintArgs))
.then(() => emberGenerate(args))
.then(() => {
expect(file('fastboot-tests/foo-test.js'))
.to.contain('setupTest(\'fastboot\'/*, options */);')
.to.contain('return this.visit(\'/foo\')');

expect(file('fastboot-tests/fixtures/fastboot/app/router.js'))
.to.contain('this.route(\'foo\')');

expect(file('fastboot-tests/fixtures/fastboot/app/templates/foo.hbs'))
.to.contain('<h1>foo</h1>');
})
.then(() => emberDestroy(args))
.then(() => emberDestroy(defaultBlueprintArgs));
.then(() => {
expect(file('fastboot-tests/foo-test.js')).to.not.exist;
expect(file('fastboot-tests/fixtures/fastboot/app/router.js')).to.exist; // router.js is not deleted
expect(file('fastboot-tests/fixtures/fastboot/app/templates/foo.hbs')).to.not.exist;
});
});

it('fastboot-test foo/bar', function() {
let args = ['fastboot-test', 'foo/bar'];

return emberNew()
.then(() => emberGenerate(defaultBlueprintArgs))
.then(() => emberGenerate(args))
.then(() => {
expect(file('fastboot-tests/foo/bar-test.js'))
.to.contain('setupTest(\'fastboot\'/*, options */);')
.to.contain('return this.visit(\'/foo/bar\')');

expect(file('fastboot-tests/fixtures/fastboot/app/router.js'))
.to.contain('this.route(\'foo\', function() {')
.to.contain('this.route(\'bar\')');

expect(file('fastboot-tests/fixtures/fastboot/app/templates/foo/bar.hbs'))
.to.contain('<h1>fooBar</h1>');
})
.then(() => emberDestroy(args))
.then(() => emberDestroy(defaultBlueprintArgs));
.then(() => {
expect(file('fastboot-tests/foo/bar-test.js')).to.not.exist;
expect(file('fastboot-tests/fixtures/fastboot/app/router.js')).to.exist; // router.js is not deleted
expect(file('fastboot-tests/fixtures/fastboot/app/templates/foo/bar.hbs')).to.not.exist;
});
});

it('fastboot-test foo --app-name test', function() {
let args = ['fastboot-test', 'foo', '--app-name', 'test'];

return emberNew()
.then(() => emberGenerate(args))
.then(() => {
expect(file('fastboot-tests/foo-test.js'))
.to.contain('setupTest(\'test\'/*, options */);')
.to.contain('return this.visit(\'/foo\')');

expect(file('fastboot-tests/fixtures/test/app/router.js'))
.to.contain('this.route(\'foo\')');

expect(file('fastboot-tests/fixtures/test/app/templates/foo.hbs'))
.to.contain('<h1>foo</h1>');
})
.then(() => emberDestroy(args))
.then(() => {
expect(file('fastboot-tests/foo-test.js')).to.not.exist;
expect(file('fastboot-tests/fixtures/test/app/router.js')).to.exist; // router.js is not deleted
expect(file('fastboot-tests/fixtures/test/app/templates/foo.hbs')).to.not.exist;
});
});
});

0 comments on commit 6621164

Please sign in to comment.