Skip to content

Commit

Permalink
[BUGFIX release] Updated blueprints for component and helper t… (#18691)
Browse files Browse the repository at this point in the history
[BUGFIX release] Updated blueprints for component and helper tests to output the correct hbs import statement
  • Loading branch information
rwjblue authored Jan 24, 2020
2 parents 465e1a8 + 2fed4bf commit f323419
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
16 changes: 8 additions & 8 deletions blueprints/component-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 20 additions & 3 deletions blueprints/helper-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit f323419

Please sign in to comment.