Skip to content

Commit

Permalink
[BUGFIX release] Fix generated import paths for test setup functions …
Browse files Browse the repository at this point in the history
…in addons (#8013)
  • Loading branch information
bertdeblock authored Jul 15, 2022
1 parent 453fb4d commit 0fb37af
Show file tree
Hide file tree
Showing 25 changed files with 277 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/adapter/blueprints/adapter-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');

const testInfo = require('ember-cli-test-info');
const useTestFrameworkDetector = require('@ember-data/private-build-infra/src/utilities/test-framework-detector');
const modulePrefixForProject = require('@ember-data/private-build-infra/src/utilities/module-prefix-for-project');

module.exports = useTestFrameworkDetector({
description: 'Generates an ember-data adapter unit test',
Expand All @@ -22,6 +23,7 @@ module.exports = useTestFrameworkDetector({
locals(options) {
return {
friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Adapter'),
modulePrefix: modulePrefixForProject(options.project),
};
},
});
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
32 changes: 32 additions & 0 deletions packages/adapter/node-tests/blueprints/adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,36 @@ describe('Acceptance: generate and destroy adapter blueprints', function () {
});
});
});

describe('in addon', function () {
beforeEach(function () {
return emberNew({ target: 'addon' });
});

describe('with ember-qunit (default)', function () {
it('adapter-test foo', function () {
return emberGenerateDestroy(['adapter-test', 'foo'], (_file) => {
expect(_file('tests/unit/adapters/foo-test.js')).to.equal(fixture(__dirname, 'adapter-test/rfc232-addon.js'));
});
});
});

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

it('adapter-test foo', function () {
return emberGenerateDestroy(['adapter-test', 'foo'], (_file) => {
expect(_file('tests/unit/adapters/foo-test.js')).to.equal(
fixture(__dirname, 'adapter-test/mocha-rfc232-addon.js')
);
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'dummy/tests/helpers';

describe('Unit | Adapter | foo', function() {
setupTest();

// Replace this with your real tests.
it('exists', function() {
let adapter = this.owner.lookup('adapter:foo');
expect(adapter).to.be.ok;
});
});
12 changes: 12 additions & 0 deletions packages/adapter/node-tests/fixtures/adapter-test/rfc232-addon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'dummy/tests/helpers';

module('Unit | Adapter | foo', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let adapter = this.owner.lookup('adapter:foo');
assert.ok(adapter);
});
});
2 changes: 2 additions & 0 deletions packages/model/blueprints/model-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');

const testInfo = require('ember-cli-test-info');
const useTestFrameworkDetector = require('@ember-data/private-build-infra/src/utilities/test-framework-detector');
const modulePrefixForProject = require('@ember-data/private-build-infra/src/utilities/module-prefix-for-project');

const ModelBlueprint = require('../model');

Expand All @@ -25,6 +26,7 @@ module.exports = useTestFrameworkDetector({
const result = ModelBlueprint.locals.apply(this, arguments);

result.friendlyTestDescription = testInfo.description(options.entity.name, 'Unit', 'Model');
result.modulePrefix = modulePrefixForProject(options.project);

return result;
},
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
32 changes: 32 additions & 0 deletions packages/model/node-tests/blueprints/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,36 @@ describe('Acceptance: generate and destroy model blueprints', function () {
});
});
});

describe('in addon', function () {
beforeEach(function () {
return emberNew({ target: 'addon' });
});

describe('with ember-qunit (default)', function () {
it('model-test foo', function () {
return emberGenerateDestroy(['model-test', 'foo'], (_file) => {
expect(_file('tests/unit/models/foo-test.js')).to.equal(fixture(__dirname, 'model-test/rfc232-addon.js'));
});
});
});

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

it('model-test foo', function () {
return emberGenerateDestroy(['model-test', 'foo'], (_file) => {
expect(_file('tests/unit/models/foo-test.js')).to.equal(
fixture(__dirname, 'model-test/mocha-rfc232-addon.js')
);
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'dummy/tests/helpers';

describe('Unit | Model | foo', function() {
setupTest();

// Replace this with your real tests.
it('exists', function() {
let store = this.owner.lookup('service:store');
let model = store.createRecord('foo', {});
expect(model).to.be.ok;
});
});
13 changes: 13 additions & 0 deletions packages/model/node-tests/fixtures/model-test/rfc232-addon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { module, test } from 'qunit';
import { setupTest } from 'dummy/tests/helpers';

module('Unit | Model | foo', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('foo', {});
assert.ok(model);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { dasherize } = require('ember-cli-string-utils');

module.exports = function modulePrefixForProject(project) {
return dasherize(project.config().modulePrefix);
};
2 changes: 2 additions & 0 deletions packages/serializer/blueprints/serializer-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');

const testInfo = require('ember-cli-test-info');
const useTestFrameworkDetector = require('@ember-data/private-build-infra/src/utilities/test-framework-detector');
const modulePrefixForProject = require('@ember-data/private-build-infra/src/utilities/module-prefix-for-project');

module.exports = useTestFrameworkDetector({
description: 'Generates a serializer unit test.',
Expand All @@ -22,6 +23,7 @@ module.exports = useTestFrameworkDetector({
locals(options) {
return {
friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Serializer'),
modulePrefix: modulePrefixForProject(options.project),
};
},
});
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 packages/serializer/blueprints/transform-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');

const testInfo = require('ember-cli-test-info');
const useTestFrameworkDetector = require('@ember-data/private-build-infra/src/utilities/test-framework-detector');
const modulePrefixForProject = require('@ember-data/private-build-infra/src/utilities/module-prefix-for-project');

module.exports = useTestFrameworkDetector({
description: 'Generates a transform unit test.',
Expand All @@ -22,6 +23,7 @@ module.exports = useTestFrameworkDetector({
locals(options) {
return {
friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Transform'),
modulePrefix: modulePrefixForProject(options.project),
};
},
});
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
34 changes: 34 additions & 0 deletions packages/serializer/node-tests/blueprints/serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,38 @@ describe('Acceptance: generate and destroy serializer blueprints', function () {
});
});
});

describe('in addon', function () {
beforeEach(function () {
return emberNew({ target: 'addon' });
});

describe('with ember-qunit (default)', function () {
it('serializer-test foo', function () {
return emberGenerateDestroy(['serializer-test', 'foo'], (_file) => {
expect(_file('tests/unit/serializers/foo-test.js')).to.equal(
fixture(__dirname, 'serializer-test/rfc232-addon.js')
);
});
});
});

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

it('serializer-test foo', function () {
return emberGenerateDestroy(['serializer-test', 'foo'], (_file) => {
expect(_file('tests/unit/serializers/foo-test.js')).to.equal(
fixture(__dirname, 'serializer-test/mocha-rfc232-addon.js')
);
});
});
});
});
});
34 changes: 34 additions & 0 deletions packages/serializer/node-tests/blueprints/transform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,38 @@ describe('Acceptance: generate and destroy transform blueprints', function () {
});
});
});

describe('in addon', function () {
beforeEach(function () {
return emberNew({ target: 'addon' });
});

describe('with ember-qunit (default)', function () {
it('transform-test foo', function () {
return emberGenerateDestroy(['transform-test', 'foo'], (_file) => {
expect(_file('tests/unit/transforms/foo-test.js')).to.equal(
fixture(__dirname, 'transform-test/rfc232-addon.js')
);
});
});
});

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

it('transform-test foo', function () {
return emberGenerateDestroy(['transform-test', 'foo'], (_file) => {
expect(_file('tests/unit/transforms/foo-test.js')).to.equal(
fixture(__dirname, 'transform-test/mocha-rfc232-addon.js')
);
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'dummy/tests/helpers';

describe('Unit | Serializer | foo', function() {
setupTest();

// Replace this with your real tests.
it('exists', function() {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('foo');

expect(serializer).to.be.ok;
});

it('serializes records', function() {
let store = this.owner.lookup('service:store');
let record = store.createRecord('foo', {});

let serializedRecord = record.serialize();

expect(serializedRecord).to.be.ok;
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { module, test } from 'qunit';
import { setupTest } from 'dummy/tests/helpers';

module('Unit | Serializer | foo', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('foo');

assert.ok(serializer);
});

test('it serializes records', function(assert) {
let store = this.owner.lookup('service:store');
let record = store.createRecord('foo', {});

let serializedRecord = record.serialize();

assert.ok(serializedRecord);
});
});
Loading

0 comments on commit 0fb37af

Please sign in to comment.