Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update blueprints to use native JS classes #17621

Merged
merged 5 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions blueprints/controller/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

const useNativeDetector = require('../native-detector');
ppcano marked this conversation as resolved.
Show resolved Hide resolved
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;
const path = require('path');

module.exports = {
module.exports = useNativeDetector({
description: 'Generates a controller.',
fileMapTokens() {
if (isModuleUnificationProject(this.project)) {
Expand All @@ -26,4 +27,4 @@ module.exports = {
};
}
},
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Controller from '@ember/controller';

export default class <%= classifiedModuleName %>Controller extends Controller {
};
12 changes: 12 additions & 0 deletions blueprints/native-detector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const path = require('path');

module.exports = function(blueprint) {
blueprint.filesPath = function() {
let rootPath = process.env.EMBER_VERSION === 'OCTANE' ? 'native-files' : 'files';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, we intend to come up with a better "flag" than process.env.EMBER_VERSION, but this unlocks actually being able to do the blueprint work while we figure that out.

return path.join(this.path, rootPath);
};

return blueprint;
};
133 changes: 133 additions & 0 deletions node-tests/blueprints/controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const expect = chai.expect;

const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
const enableModuleUnification = require('../helpers/module-unification').enableModuleUnification;
const enableOctane = require('../helpers/setup-test-environment').enableOctane;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend to include the enableModuleUnification function into the /helpers/setup-test-environment module, but I would like to do that in an independent PR.

const fixture = require('../helpers/fixture');

describe('Blueprint: controller', function() {
Expand Down Expand Up @@ -302,6 +303,138 @@ describe('Blueprint: controller', function() {
});
});

describe('in app - octane', function() {
enableOctane();

beforeEach(function() {
return emberNew()
.then(() =>
modifyPackages([
{ name: 'ember-qunit', delete: true },
{ name: 'ember-cli-qunit', dev: true },
])
)
.then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0'));
});

it('controller foo', function() {
return emberGenerateDestroy(['controller', 'foo'], _file => {
expect(_file('src/ui/routes/foo/controller.js')).to.equal(
fixture('controller/native-controller.js')
);

expect(_file('src/ui/routes/foo/controller-test.js')).to.equal(
fixture('controller-test/default.js')
);
});
});

it('controller foo/bar', function() {
return emberGenerateDestroy(['controller', 'foo/bar'], _file => {
expect(_file('src/ui/routes/foo/bar/controller.js')).to.equal(
fixture('controller/native-controller-nested.js')
);

expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.equal(
fixture('controller-test/default-nested.js')
);
});
});

describe('with podModulePrefix', function() {
beforeEach(function() {
setupPodConfig({ podModulePrefix: true });
});

it('controller foo --pod podModulePrefix', function() {
return expectError(
emberGenerateDestroy(['controller', 'foo', '--pod']),
"Pods aren't supported within a module unification app"
);
});
});
});

describe('in addon - octane', function() {
enableOctane();

beforeEach(function() {
return emberNew({ target: 'addon' })
.then(() =>
modifyPackages([
{ name: 'ember-qunit', delete: true },
{ name: 'ember-cli-qunit', dev: true },
])
)
.then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0'));
});

it('controller foo', function() {
return emberGenerateDestroy(['controller', 'foo'], _file => {
expect(_file('src/ui/routes/foo/controller.js')).to.equal(
fixture('controller/native-controller.js')
);

expect(_file('src/ui/routes/foo/controller-test.js')).to.equal(
fixture('controller-test/default.js')
);

expect(_file('app/controllers/foo.js')).to.not.exist;
});
});

it('controller foo/bar', function() {
return emberGenerateDestroy(['controller', 'foo/bar'], _file => {
expect(_file('src/ui/routes/foo/bar/controller.js')).to.equal(
fixture('controller/native-controller-nested.js')
);

expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.equal(
fixture('controller-test/default-nested.js')
);

expect(_file('app/controllers/foo/bar.js')).to.not.exist;
});
});

it('controller foo --dummy', function() {
return emberGenerateDestroy(['controller', 'foo', '--dummy'], _file => {
expect(_file('tests/dummy/src/ui/routes/foo/controller.js')).to.equal(
fixture('controller/native-controller.js')
);

expect(_file('src/ui/routes/foo/controller.js')).to.not.exist;

expect(_file('src/ui/routes/foo/controller-test.js')).to.not.exist;
});
});

it('controller foo/bar --dummy', function() {
return emberGenerateDestroy(['controller', 'foo/bar', '--dummy'], _file => {
expect(_file('tests/dummy/src/ui/routes/foo/bar/controller.js')).to.equal(
fixture('controller/native-controller-nested.js')
);

expect(_file('src/ui/routes/foo/bar/controller.js')).to.not.exist;

expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.not.exist;
});
});

describe('with podModulePrefix', function() {
beforeEach(function() {
setupPodConfig({ podModulePrefix: true });
});

it('controller foo --pod podModulePrefix', function() {
return expectError(
emberGenerateDestroy(['controller', 'foo', '--pod']),
"Pods aren't supported within a module unification app"
);
});
});
});

describe('in in-repo-addon', function() {
beforeEach(function() {
return emberNew({ target: 'in-repo-addon' })
Expand Down
4 changes: 4 additions & 0 deletions node-tests/fixtures/controller/native-controller-nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Controller from '@ember/controller';

export default class FooBarController extends Controller {
};
4 changes: 4 additions & 0 deletions node-tests/fixtures/controller/native-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Controller from '@ember/controller';

export default class FooController extends Controller {
};
15 changes: 15 additions & 0 deletions node-tests/helpers/setup-test-environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function enableOctane() {
beforeEach(function() {
process.env.EMBER_CLI_MODULE_UNIFICATION = 'true';
process.env.EMBER_VERSION = 'OCTANE';
});

afterEach(function() {
delete process.env.EMBER_CLI_MODULE_UNIFICATION;
delete process.env.EMBER_VERSION;
});
}

module.exports = {
enableOctane,
};