# insert-hooks
## Usage
```
npx ember-freshdesk-codemods insert-hooks path/of/files/ or/some**/*glob.js
# or
yarn global add ember-freshdesk-codemods
ember-freshdesk-codemods insert-hooks path/of/files/ or/some**/*glob.js
```
## Input / Output
* [before-after-test](#before-after-test)
* [setup-rendering-test](#setup-rendering-test)
* [setup-test](#setup-test)
---
**before-after-test**
**Input** ([before-after-test.input.js](transforms/insert-hooks/__testfixtures__/before-after-test.input.js)):
```js
import {
describe,
it,
beforeEach,
afterEach
} from 'mocha';
import {
setupTranslations,
setupAcceptance
} from '@freshdesk/test-helpers';
describe.skip('Some test', function() {
setupAcceptance();
setupTranslations(true);
beforeEach(function() {
// ...
});
afterEach(function() {
// ...
});
it('Some test', function() {
// ...
});
context('Testing withing context', function() {
// Should not add hook in beforeEach within a context
beforeEach(function() {
// ...
});
});
});
```
**Output** ([before-after-test.output.js](transforms/insert-hooks/__testfixtures__/before-after-test.output.js)):
```js
import { describe, it, beforeEach } from 'mocha';
import { setupAcceptance } from '@freshdesk/test-helpers';
describe.skip('Some test', function() {
let hooks = setupAcceptance();
hooks.beforeEach(function() {
// ...
});
hooks.afterEach(function() {
// ...
});
it('Some test', function() {
// ...
});
context('Testing withing context', function() {
// Should not add hook in beforeEach within a context
beforeEach(function() {
// ...
});
});
});
```
---
**setup-rendering-test**
**Input** ([setup-rendering-test.input.js](transforms/insert-hooks/__testfixtures__/setup-rendering-test.input.js)):
```js
import { describe, it } from 'mocha';
import { setupRenderingWithMirage } from 'ember-mocha';
import { setupTranslations, setupSinonSandbox } from '@freshdesk/test-helpers';
describe('Some test', function() {
setupRenderingWithMirage();
setupTranslations(true);
it('Some test', function() {
// ...
});
});
```
**Output** ([setup-rendering-test.output.js](transforms/insert-hooks/__testfixtures__/setup-rendering-test.output.js)):
```js
import { describe, it } from 'mocha';
import { setupRenderingWithMirage } from 'ember-mocha';
describe('Some test', function() {
setupRenderingWithMirage();
it('Some test', function() {
// ...
});
});
```
---
**setup-test**
**Input** ([setup-test.input.js](transforms/insert-hooks/__testfixtures__/setup-test.input.js)):
```js
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';
import { setupTranslations, setupSinonSandbox } from '@freshdesk/test-helpers';
describe('Some test', function() {
setupTest();
setupTranslations(true);
setupSinonSandbox();
setupSolution({
isDefaultLocale: true
});
setupSolution();
it('Some test', function() {
// ...
});
});
```
**Output** ([setup-test.output.js](transforms/insert-hooks/__testfixtures__/setup-test.output.js)):
```js
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';
import {
setupTranslations,
setupSinonSandbox
} from '@freshdesk/test-helpers';
describe('Some test', function() {
let hooks = setupTest();
setupTranslations(hooks);
setupSinonSandbox(hooks);
setupSolution(hooks, {
isDefaultLocale: true
});
setupSolution(hooks);
it('Some test', function() {
// ...
});
});
```