Skip to content

Commit

Permalink
Allowed codemod to run on test files (#2)
Browse files Browse the repository at this point in the history
* chore: Added the file extension to fixtures for v2 addon

* chore: Added fixtures (failing tests)

* feature: Allowed codemod to run on test files

* chore: Updated fixtures

* chore: Added changeset

---------

Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
  • Loading branch information
ijlee2 and ijlee2 authored Apr 24, 2024
1 parent a887494 commit a4d3945
Show file tree
Hide file tree
Showing 22 changed files with 435 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-lobsters-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ember-codemod-remove-inject-as-service": minor
---

Allowed codemod to run on test files
4 changes: 2 additions & 2 deletions src/steps/create-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import type { CodemodOptions, Options } from '../types/index.js';
function getSrc(projectType: CodemodOptions['projectType']): string[] {
switch (projectType) {
case 'app': {
return ['app/**/*.{js,ts}'];
return ['app/**/*.{js,ts}', 'tests/**/*.{js,ts}'];
}

case 'v1-addon': {
return ['addon/**/*.{js,ts}', 'tests/dummy/app/**/*.{js,ts}'];
return ['addon/**/*.{js,ts}', 'tests/**/*.{js,ts}'];
}

case 'v2-addon': {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Service, {
inject as service,
type Registry as Services,
} from '@ember/service';
import { click, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | example-1', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
this.owner.register(
'service:domain-1/business-logic',
class Domain1BusinessLogicService extends Service {
@service private declare readonly intl: Services['intl'];

get message(): string {
return this.intl.t('hello.message', { name: 'Tomster' });
}
},
);
});

test('it renders', async function (assert) {
await render(hbs`<Example1 />`);

assert.ok(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Service, { inject } from '@ember/service';
import { click, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | example-5', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
this.owner.register(
'service:domain-1/business-logic',
class Domain1BusinessLogicService extends Service {
@inject intl;

get message() {
return this.intl.t('hello.message', { name: 'Tomster' });
}
},
);
});

test('it renders', async function (assert) {
await render(hbs`<Example5 />`);

assert.ok(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { computed } from '@ember/object';
import Service, { inject as s } from '@ember/service';
import { click, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | example-6', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
this.owner.register(
'service:domain-1/business-logic',
Service.extend({
intl: s('intl'),

message: computed(function () {
return this.intl.t('hello.message', { name: 'Tomster' });
}),
}),
);
});

test('it renders', async function (assert) {
await render(hbs`<Example6 />`);

assert.ok(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Registry as Services } from '@ember/service';
import Service from '@ember/service';
import type { TestContext as BaseTestContext } from '@ember/test-helpers';
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';

interface TestContext extends BaseTestContext {
service: Services['domain-1/business-logic'];
}

module('Unit | Service | domain-1/business-logic', function (hooks) {
setupTest(hooks);

hooks.beforeEach(function (this: TestContext) {
this.owner.register(
'service:current-user',
class CurrentUserService extends Service {
user = {
name: 'Tomster',
};
},
);

this.service = this.owner.lookup(
'service:domain-1/business-logic',
) as Services['domain-1/business-logic'];
});

test('message', function (this: TestContext, assert) {
assert.strictEqual(this.service.message, 'Hello, Tomster!');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Service, {
service,
type Registry as Services,
} from '@ember/service';
import { click, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | example-1', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
this.owner.register(
'service:domain-1/business-logic',
class Domain1BusinessLogicService extends Service {
@service
declare intl: Services['intl'];

get message(): string {
return this.intl.t('hello.message', { name: 'Tomster' });
}
},
);
});

test('it renders', async function (assert) {
await render(hbs`<Example1 />`);

assert.ok(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Service, { service } from '@ember/service';
import { click, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | example-5', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
this.owner.register(
'service:domain-1/business-logic',
class Domain1BusinessLogicService extends Service {
@service intl;

get message() {
return this.intl.t('hello.message', { name: 'Tomster' });
}
},
);
});

test('it renders', async function (assert) {
await render(hbs`<Example5 />`);

assert.ok(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { computed } from '@ember/object';
import Service, { service } from '@ember/service';
import { click, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | example-6', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
this.owner.register(
'service:domain-1/business-logic',
Service.extend({
intl: service('intl'),

message: computed(function () {
return this.intl.t('hello.message', { name: 'Tomster' });
}),
}),
);
});

test('it renders', async function (assert) {
await render(hbs`<Example6 />`);

assert.ok(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Registry as Services } from '@ember/service';
import Service from '@ember/service';
import type { TestContext as BaseTestContext } from '@ember/test-helpers';
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';

interface TestContext extends BaseTestContext {
service: Services['domain-1/business-logic'];
}

module('Unit | Service | domain-1/business-logic', function (hooks) {
setupTest(hooks);

hooks.beforeEach(function (this: TestContext) {
this.owner.register(
'service:current-user',
class CurrentUserService extends Service {
user = {
name: 'Tomster',
};
},
);

this.service = this.owner.lookup(
'service:domain-1/business-logic',
) as Services['domain-1/business-logic'];
});

test('message', function (this: TestContext, assert) {
assert.strictEqual(this.service.message, 'Hello, Tomster!');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Service, { service, type Registry as Services } from '@ember/service';
import { click, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | example-1', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
this.owner.register(
'service:domain-1/business-logic',
class Domain1BusinessLogicService extends Service {
@service declare intl: Services['intl'];

get message(): string {
return this.intl.t('hello.message', { name: 'Tomster' });
}
},
);
});

test('it renders', async function (assert) {
await render(hbs`<Example1 />`);

assert.ok(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Service, { service as s } from '@ember/service';
import { click, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | example-6', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
this.owner.register(
'service:domain-1/business-logic',
class Domain1BusinessLogicService extends Service {
@s intl;

get message() {
return this.intl.t('hello.message', { name: 'Tomster' });
}
},
);
});

test('it renders', async function (assert) {
await render(hbs`<Example6 />`);

assert.ok(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Registry as Services } from '@ember/service';
import Service from '@ember/service';
import type { TestContext as BaseTestContext } from '@ember/test-helpers';
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';

interface TestContext extends BaseTestContext {
service: Services['domain-1/business-logic'];
}

module('Unit | Service | domain-1/business-logic', function (hooks) {
setupTest(hooks);

hooks.beforeEach(function (this: TestContext) {
this.owner.register(
'service:current-user',
class CurrentUserService extends Service {
user = {
name: 'Tomster',
};
},
);

this.service = this.owner.lookup(
'service:domain-1/business-logic',
) as Services['domain-1/business-logic'];
});

test('message', function (this: TestContext, assert) {
assert.strictEqual(this.service.message, 'Hello, Tomster!');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Service, { service, type Registry as Services } from '@ember/service';
import { click, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | example-1', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
this.owner.register(
'service:domain-1/business-logic',
class Domain1BusinessLogicService extends Service {
@service
declare intl: Services['intl'];

get message(): string {
return this.intl.t('hello.message', { name: 'Tomster' });
}
},
);
});

test('it renders', async function (assert) {
await render(hbs`<Example1 />`);

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

0 comments on commit a4d3945

Please sign in to comment.