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

[BUGFIX release] Updated blueprints for component and helper tests to output the correct hbs import statement #18691

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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')) {
Copy link
Member Author

@ijlee2 ijlee2 Jan 19, 2020

Choose a reason for hiding this comment

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

Line 94 implies that, if the version is ember-cli-htmlbars is 3.x or less, we will still use the named import (because we are returning undefined, a falsey value). Could you verify if this was intended or a bug?

Copy link
Member

Choose a reason for hiding this comment

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

3.x should use import hbs from 'htmlbars-inline-precompile', which AFAICT is still what is done after this change.

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