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

Allowed codemod to run on test files #2

Merged
merged 5 commits into from
Apr 24, 2024
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
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