Skip to content

Commit a4d3945

Browse files
authored
Allowed codemod to run on test files (#2)
* 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 <[email protected]>
1 parent a887494 commit a4d3945

File tree

22 files changed

+435
-12
lines changed

22 files changed

+435
-12
lines changed

.changeset/pink-lobsters-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ember-codemod-remove-inject-as-service": minor
3+
---
4+
5+
Allowed codemod to run on test files

src/steps/create-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import type { CodemodOptions, Options } from '../types/index.js';
33
function getSrc(projectType: CodemodOptions['projectType']): string[] {
44
switch (projectType) {
55
case 'app': {
6-
return ['app/**/*.{js,ts}'];
6+
return ['app/**/*.{js,ts}', 'tests/**/*.{js,ts}'];
77
}
88

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

1313
case 'v2-addon': {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Service, {
2+
inject as service,
3+
type Registry as Services,
4+
} from '@ember/service';
5+
import { click, render } from '@ember/test-helpers';
6+
import { hbs } from 'ember-cli-htmlbars';
7+
import { setupRenderingTest } from 'ember-qunit';
8+
import { module, test } from 'qunit';
9+
10+
module('Integration | Component | example-1', function (hooks) {
11+
setupRenderingTest(hooks);
12+
13+
hooks.beforeEach(function (assert) {
14+
this.owner.register(
15+
'service:domain-1/business-logic',
16+
class Domain1BusinessLogicService extends Service {
17+
@service private declare readonly intl: Services['intl'];
18+
19+
get message(): string {
20+
return this.intl.t('hello.message', { name: 'Tomster' });
21+
}
22+
},
23+
);
24+
});
25+
26+
test('it renders', async function (assert) {
27+
await render(hbs`<Example1 />`);
28+
29+
assert.ok(true);
30+
});
31+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Service, { inject } from '@ember/service';
2+
import { click, render } from '@ember/test-helpers';
3+
import { hbs } from 'ember-cli-htmlbars';
4+
import { setupRenderingTest } from 'ember-qunit';
5+
import { module, test } from 'qunit';
6+
7+
module('Integration | Component | example-5', function (hooks) {
8+
setupRenderingTest(hooks);
9+
10+
hooks.beforeEach(function (assert) {
11+
this.owner.register(
12+
'service:domain-1/business-logic',
13+
class Domain1BusinessLogicService extends Service {
14+
@inject intl;
15+
16+
get message() {
17+
return this.intl.t('hello.message', { name: 'Tomster' });
18+
}
19+
},
20+
);
21+
});
22+
23+
test('it renders', async function (assert) {
24+
await render(hbs`<Example5 />`);
25+
26+
assert.ok(true);
27+
});
28+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { computed } from '@ember/object';
2+
import Service, { inject as s } from '@ember/service';
3+
import { click, render } from '@ember/test-helpers';
4+
import { hbs } from 'ember-cli-htmlbars';
5+
import { setupRenderingTest } from 'ember-qunit';
6+
import { module, test } from 'qunit';
7+
8+
module('Integration | Component | example-6', function (hooks) {
9+
setupRenderingTest(hooks);
10+
11+
hooks.beforeEach(function (assert) {
12+
this.owner.register(
13+
'service:domain-1/business-logic',
14+
Service.extend({
15+
intl: s('intl'),
16+
17+
message: computed(function () {
18+
return this.intl.t('hello.message', { name: 'Tomster' });
19+
}),
20+
}),
21+
);
22+
});
23+
24+
test('it renders', async function (assert) {
25+
await render(hbs`<Example6 />`);
26+
27+
assert.ok(true);
28+
});
29+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { Registry as Services } from '@ember/service';
2+
import Service from '@ember/service';
3+
import type { TestContext as BaseTestContext } from '@ember/test-helpers';
4+
import { setupTest } from 'ember-qunit';
5+
import { module, test } from 'qunit';
6+
7+
interface TestContext extends BaseTestContext {
8+
service: Services['domain-1/business-logic'];
9+
}
10+
11+
module('Unit | Service | domain-1/business-logic', function (hooks) {
12+
setupTest(hooks);
13+
14+
hooks.beforeEach(function (this: TestContext) {
15+
this.owner.register(
16+
'service:current-user',
17+
class CurrentUserService extends Service {
18+
user = {
19+
name: 'Tomster',
20+
};
21+
},
22+
);
23+
24+
this.service = this.owner.lookup(
25+
'service:domain-1/business-logic',
26+
) as Services['domain-1/business-logic'];
27+
});
28+
29+
test('message', function (this: TestContext, assert) {
30+
assert.strictEqual(this.service.message, 'Hello, Tomster!');
31+
});
32+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Service, {
2+
service,
3+
type Registry as Services,
4+
} from '@ember/service';
5+
import { click, render } from '@ember/test-helpers';
6+
import { hbs } from 'ember-cli-htmlbars';
7+
import { setupRenderingTest } from 'ember-qunit';
8+
import { module, test } from 'qunit';
9+
10+
module('Integration | Component | example-1', function (hooks) {
11+
setupRenderingTest(hooks);
12+
13+
hooks.beforeEach(function (assert) {
14+
this.owner.register(
15+
'service:domain-1/business-logic',
16+
class Domain1BusinessLogicService extends Service {
17+
@service
18+
declare intl: Services['intl'];
19+
20+
get message(): string {
21+
return this.intl.t('hello.message', { name: 'Tomster' });
22+
}
23+
},
24+
);
25+
});
26+
27+
test('it renders', async function (assert) {
28+
await render(hbs`<Example1 />`);
29+
30+
assert.ok(true);
31+
});
32+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Service, { service } from '@ember/service';
2+
import { click, render } from '@ember/test-helpers';
3+
import { hbs } from 'ember-cli-htmlbars';
4+
import { setupRenderingTest } from 'ember-qunit';
5+
import { module, test } from 'qunit';
6+
7+
module('Integration | Component | example-5', function (hooks) {
8+
setupRenderingTest(hooks);
9+
10+
hooks.beforeEach(function (assert) {
11+
this.owner.register(
12+
'service:domain-1/business-logic',
13+
class Domain1BusinessLogicService extends Service {
14+
@service intl;
15+
16+
get message() {
17+
return this.intl.t('hello.message', { name: 'Tomster' });
18+
}
19+
},
20+
);
21+
});
22+
23+
test('it renders', async function (assert) {
24+
await render(hbs`<Example5 />`);
25+
26+
assert.ok(true);
27+
});
28+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { computed } from '@ember/object';
2+
import Service, { service } from '@ember/service';
3+
import { click, render } from '@ember/test-helpers';
4+
import { hbs } from 'ember-cli-htmlbars';
5+
import { setupRenderingTest } from 'ember-qunit';
6+
import { module, test } from 'qunit';
7+
8+
module('Integration | Component | example-6', function (hooks) {
9+
setupRenderingTest(hooks);
10+
11+
hooks.beforeEach(function (assert) {
12+
this.owner.register(
13+
'service:domain-1/business-logic',
14+
Service.extend({
15+
intl: service('intl'),
16+
17+
message: computed(function () {
18+
return this.intl.t('hello.message', { name: 'Tomster' });
19+
}),
20+
}),
21+
);
22+
});
23+
24+
test('it renders', async function (assert) {
25+
await render(hbs`<Example6 />`);
26+
27+
assert.ok(true);
28+
});
29+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { Registry as Services } from '@ember/service';
2+
import Service from '@ember/service';
3+
import type { TestContext as BaseTestContext } from '@ember/test-helpers';
4+
import { setupTest } from 'ember-qunit';
5+
import { module, test } from 'qunit';
6+
7+
interface TestContext extends BaseTestContext {
8+
service: Services['domain-1/business-logic'];
9+
}
10+
11+
module('Unit | Service | domain-1/business-logic', function (hooks) {
12+
setupTest(hooks);
13+
14+
hooks.beforeEach(function (this: TestContext) {
15+
this.owner.register(
16+
'service:current-user',
17+
class CurrentUserService extends Service {
18+
user = {
19+
name: 'Tomster',
20+
};
21+
},
22+
);
23+
24+
this.service = this.owner.lookup(
25+
'service:domain-1/business-logic',
26+
) as Services['domain-1/business-logic'];
27+
});
28+
29+
test('message', function (this: TestContext, assert) {
30+
assert.strictEqual(this.service.message, 'Hello, Tomster!');
31+
});
32+
});

0 commit comments

Comments
 (0)