diff --git a/blueprints/component-test/index.js b/blueprints/component-test/index.js index 05c6cfdc2bb..79ab3acd454 100644 --- a/blueprints/component-test/index.js +++ b/blueprints/component-test/index.js @@ -62,9 +62,9 @@ module.exports = useTestFrameworkDetector({ componentPathName = [options.path, dasherizedModuleName].filter(Boolean).join('/'); } - let hbsImportStatement = this._useSeparateInlinePrecompileAddon() - ? "import hbs from 'htmlbars-inline-precompile';" - : "import { hbs } from 'ember-cli-htmlbars';"; + let hbsImportStatement = this._useNamedHbsImport() + ? "import { hbs } from 'ember-cli-htmlbars';" + : "import hbs from 'htmlbars-inline-precompile';"; let templateInvocation = invocationFor(options); let componentName = templateInvocation; @@ -86,21 +86,21 @@ module.exports = useTestFrameworkDetector({ }; }, - _useSeparateInlinePrecompileAddon() { + _useNamedHbsImport() { let htmlbarsAddon = this.project.addons.find(a => a.name === 'ember-cli-htmlbars'); - if (htmlbarsAddon === undefined) { + if (htmlbarsAddon && semver.gte(htmlbarsAddon.pkg.version, '4.0.0-alpha.1')) { return true; - } else if (semver.gte(htmlbarsAddon.pkg.version, '4.0.0-alpha.1')) { - return false; } + + return false; }, afterInstall: function(options) { if ( !options.dryRun && options.testType === 'integration' && - this._useSeparateInlinePrecompileAddon() && + !this._useNamedHbsImport() && isPackageMissing(this, 'ember-cli-htmlbars-inline-precompile') ) { return this.addPackagesToProject([ diff --git a/blueprints/component-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js b/blueprints/component-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js index 8d074b2e8ba..68422cb9543 100644 --- a/blueprints/component-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js +++ b/blueprints/component-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js @@ -2,7 +2,7 @@ import { describe, it } from 'mocha'; import { setupRenderingTest } from 'ember-mocha'; import { render } from '@ember/test-helpers'; -import hbs from 'htmlbars-inline-precompile'; +<%= hbsImportStatement %> describe('<%= friendlyTestDescription %>', function() { setupRenderingTest(); diff --git a/blueprints/helper-test/index.js b/blueprints/helper-test/index.js index b0f51f0243b..8d042b7e073 100644 --- a/blueprints/helper-test/index.js +++ b/blueprints/helper-test/index.js @@ -2,6 +2,7 @@ const stringUtils = require('ember-cli-string-utils'); const isPackageMissing = require('ember-cli-is-package-missing'); +const semver = require('semver'); const useTestFrameworkDetector = require('../test-framework-detector'); const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject; @@ -76,17 +77,33 @@ module.exports = useTestFrameworkDetector({ dasherizedModulePrefix = stringUtils.dasherize(options.project.config().modulePrefix); } + let hbsImportStatement = this._useNamedHbsImport() + ? "import { hbs } from 'ember-cli-htmlbars';" + : "import hbs from 'htmlbars-inline-precompile';"; + return { - friendlyTestName: friendlyTestName, - dasherizedModulePrefix: dasherizedModulePrefix, - testType: testType, + testType, + friendlyTestName, + dasherizedModulePrefix, + hbsImportStatement, }; }, + _useNamedHbsImport() { + let htmlbarsAddon = this.project.addons.find(a => a.name === 'ember-cli-htmlbars'); + + if (htmlbarsAddon && semver.gte(htmlbarsAddon.pkg.version, '4.0.0-alpha.1')) { + return true; + } + + return false; + }, + afterInstall: function(options) { if ( !options.dryRun && options.testType === 'integration' && + !this._useNamedHbsImport() && isPackageMissing(this, 'ember-cli-htmlbars-inline-precompile') ) { return this.addPackagesToProject([ diff --git a/blueprints/helper-test/mocha-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js b/blueprints/helper-test/mocha-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js index caccbb8f1ce..444c51c08ea 100644 --- a/blueprints/helper-test/mocha-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js +++ b/blueprints/helper-test/mocha-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; <% if (testType == 'integration') { %>import { describe, it } from 'mocha'; import { setupRenderingTest } from 'ember-mocha'; import { render } from '@ember/test-helpers'; -import hbs from 'htmlbars-inline-precompile'; +<%= hbsImportStatement %> describe('<%= friendlyTestName %>', function() { setupRenderingTest(); diff --git a/blueprints/helper-test/qunit-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js b/blueprints/helper-test/qunit-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js index 28a173e366a..421aeadbbb9 100644 --- a/blueprints/helper-test/qunit-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js +++ b/blueprints/helper-test/qunit-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js @@ -1,7 +1,7 @@ <% if (testType === 'integration') { %>import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { render } from '@ember/test-helpers'; -import hbs from 'htmlbars-inline-precompile'; +<%= hbsImportStatement %> module('<%= friendlyTestName %>', function(hooks) { setupRenderingTest(hooks);