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] Fix generated import paths for test setup functions in addons #20114

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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { setupApplicationTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupApplicationTest } from '<%= modulePrefix %>/tests/helpers';
import { visit, currentURL } from '@ember/test-helpers';

describe('<%= friendlyTestName %>', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupApplicationTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestName %>', function (hooks) {
setupApplicationTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if (testType === 'integration') { %>import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupRenderingTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupRenderingTest } from '<%= modulePrefix %>/tests/helpers';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

Expand All @@ -26,7 +26,7 @@ describe('<%= friendlyTestDescription %>', function () {
});
});<% } else if (testType === 'unit') { %>import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

describe('<%= friendlyTestDescription %>', function () {
setupTest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if (testType === 'integration') { %>import { module, test } from 'qunit';
import { setupRenderingTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupRenderingTest } from '<%= modulePrefix %>/tests/helpers';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

Expand All @@ -24,7 +24,7 @@ module('<%= friendlyTestDescription %>', function (hooks) {
assert.dom(this.element).hasText('template block text');
});
});<% } else if (testType === 'unit') { %>import { module, test } from 'qunit';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestDescription %>', function (hooks) {
setupTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

describe('<%= friendlyTestDescription %>', function () {
setupTest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestDescription %>', function (hooks) {
setupTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupRenderingTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupRenderingTest } from '<%= modulePrefix %>/tests/helpers';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupRenderingTest } from '<%= modulePrefix %>/tests/helpers';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

describe('<%= friendlyTestDescription %>', function () {
setupTest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestDescription %>', function (hooks) {
setupTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

describe('<%= friendlyTestDescription %>', function () {
setupTest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestDescription %>', function (hooks) {
setupTest(hooks);
Expand Down
9 changes: 9 additions & 0 deletions blueprints/-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { dasherize } = require('ember-cli-string-utils');

function modulePrefixForProject(project) {
return dasherize(project.config().modulePrefix);
}

module.exports = {
modulePrefixForProject,
};
4 changes: 3 additions & 1 deletion blueprints/acceptance-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const pathUtil = require('ember-cli-path-utils');
const stringUtils = require('ember-cli-string-utils');

const maybePolyfillTypeScriptBlueprints = require('../-maybe-polyfill-typescript-blueprints');
const { modulePrefixForProject } = require('../-utils');
const useTestFrameworkDetector = require('../test-framework-detector');

module.exports = useTestFrameworkDetector({
Expand Down Expand Up @@ -35,7 +36,8 @@ module.exports = useTestFrameworkDetector({
].join(' | ');

return {
testFolderRoot: testFolderRoot,
modulePrefix: modulePrefixForProject(options.project),
testFolderRoot,
friendlyTestName,
destroyAppExists,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { setupApplicationTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupApplicationTest } from '<%= modulePrefix %>/tests/helpers';
import { visit, currentURL } from '@ember/test-helpers';

describe('<%= friendlyTestName %>', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupApplicationTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestName %>', function (hooks) {
setupApplicationTest(hooks);
Expand Down
2 changes: 2 additions & 0 deletions blueprints/component-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const getPathOption = require('ember-cli-get-component-path-option');
const semver = require('semver');

const maybePolyfillTypeScriptBlueprints = require('../-maybe-polyfill-typescript-blueprints');
const { modulePrefixForProject } = require('../-utils');
const useTestFrameworkDetector = require('../test-framework-detector');

function invocationFor(options) {
Expand Down Expand Up @@ -81,6 +82,7 @@ module.exports = useTestFrameworkDetector({
let selfCloseComponent = (descriptor) => `<${descriptor} />`;

return {
modulePrefix: modulePrefixForProject(options.project),
path: getPathOption(options),
testType: testType,
componentName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if (testType === 'integration') { %>import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupRenderingTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupRenderingTest } from '<%= modulePrefix %>/tests/helpers';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

Expand All @@ -26,7 +26,7 @@ describe('<%= friendlyTestDescription %>', function () {
});
});<% } else if (testType === 'unit') { %>import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

describe('<%= friendlyTestDescription %>', function () {
setupTest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if (testType === 'integration') { %>import { module, test } from 'qunit';
import { setupRenderingTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupRenderingTest } from '<%= modulePrefix %>/tests/helpers';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

Expand All @@ -24,7 +24,7 @@ module('<%= friendlyTestDescription %>', function (hooks) {
assert.dom(this.element).hasText('template block text');
});
});<% } else if (testType === 'unit') { %>import { module, test } from 'qunit';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestDescription %>', function (hooks) {
setupTest(hooks);
Expand Down
2 changes: 2 additions & 0 deletions blueprints/controller-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const useTestFrameworkDetector = require('../test-framework-detector');
const path = require('path');

const maybePolyfillTypeScriptBlueprints = require('../-maybe-polyfill-typescript-blueprints');
const { modulePrefixForProject } = require('../-utils');

module.exports = useTestFrameworkDetector({
description: 'Generates a controller unit test.',
Expand All @@ -22,6 +23,7 @@ module.exports = useTestFrameworkDetector({
let controllerPathName = dasherizedModuleName;

return {
modulePrefix: modulePrefixForProject(options.project),
controllerPathName: controllerPathName,
friendlyTestDescription: ['Unit', 'Controller', dasherizedModuleName].join(' | '),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

describe('<%= friendlyTestDescription %>', function () {
setupTest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestDescription %>', function (hooks) {
setupTest(hooks);
Expand Down
5 changes: 2 additions & 3 deletions blueprints/helper-test/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

const stringUtils = require('ember-cli-string-utils');
const isPackageMissing = require('ember-cli-is-package-missing');
const semver = require('semver');

const maybePolyfillTypeScriptBlueprints = require('../-maybe-polyfill-typescript-blueprints');
const { modulePrefixForProject } = require('../-utils');

const useTestFrameworkDetector = require('../test-framework-detector');

Expand Down Expand Up @@ -34,15 +34,14 @@ module.exports = useTestFrameworkDetector({

locals: function (options) {
let friendlyTestName = ['Integration', 'Helper', options.entity.name].join(' | ');
let dasherizedModulePrefix = stringUtils.dasherize(options.project.config().modulePrefix);

let hbsImportStatement = this._useNamedHbsImport()
? "import { hbs } from 'ember-cli-htmlbars';"
: "import hbs from 'htmlbars-inline-precompile';";

return {
modulePrefix: modulePrefixForProject(options.project),
friendlyTestName,
dasherizedModulePrefix,
hbsImportStatement,
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupRenderingTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupRenderingTest } from '<%= modulePrefix %>/tests/helpers';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupRenderingTest } from '<%= modulePrefix %>/tests/helpers';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

Expand Down
2 changes: 2 additions & 0 deletions blueprints/route-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const stringUtil = require('ember-cli-string-utils');

const useTestFrameworkDetector = require('../test-framework-detector');
const maybePolyfillTypeScriptBlueprints = require('../-maybe-polyfill-typescript-blueprints');
const { modulePrefixForProject } = require('../-utils');

module.exports = useTestFrameworkDetector({
description: 'Generates a route unit test.',
Expand Down Expand Up @@ -57,6 +58,7 @@ module.exports = useTestFrameworkDetector({
}

return {
modulePrefix: modulePrefixForProject(options.project),
friendlyTestDescription: ['Unit', 'Route', options.entity.name].join(' | '),
moduleName: stringUtil.dasherize(moduleName),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

describe('<%= friendlyTestDescription %>', function () {
setupTest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestDescription %>', function (hooks) {
setupTest(hooks);
Expand Down
2 changes: 2 additions & 0 deletions blueprints/service-test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const maybePolyfillTypeScriptBlueprints = require('../-maybe-polyfill-typescript-blueprints');
const { modulePrefixForProject } = require('../-utils');
const useTestFrameworkDetector = require('../test-framework-detector');

module.exports = useTestFrameworkDetector({
Expand All @@ -26,6 +27,7 @@ module.exports = useTestFrameworkDetector({

locals(options) {
return {
modulePrefix: modulePrefixForProject(options.project),
friendlyTestDescription: ['Unit', 'Service', options.entity.name].join(' | '),
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

describe('<%= friendlyTestDescription %>', function () {
setupTest();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

module('<%= friendlyTestDescription %>', function (hooks) {
setupTest(hooks);
Expand Down
18 changes: 18 additions & 0 deletions node-tests/blueprints/acceptance-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,23 @@ describe('Blueprint: acceptance-test', function () {
});
});
});

describe('with ember-mocha@0.16.2', function () {
beforeEach(function () {
modifyPackages([
{ name: 'ember-qunit', delete: true },
{ name: 'ember-mocha', dev: true },
]);
generateFakePackageManifest('ember-mocha', '0.16.2');
});

it('acceptance-test foo', function () {
return emberGenerateDestroy(['acceptance-test', 'foo'], (_file) => {
expect(_file('tests/acceptance/foo-test.js')).to.equal(
fixture('acceptance-test/mocha-rfc268-addon.js')
);
});
});
});
});
});
Loading