Skip to content

Commit 6ca75d0

Browse files
committed
🧪 test: fix folder name conflict in tests
1 parent 5f56116 commit 6ca75d0

File tree

5 files changed

+62
-35
lines changed

5 files changed

+62
-35
lines changed

src/commands/generate/component/common/common.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Commands: [Generate] => [Component] => [Common]', () => {
4444
filesystem.remove(baseFolder);
4545
});
4646

47-
test('should generate a common component html with default template <p>sample works</p>', async () => {
47+
test('should generate a common component html correct content', async () => {
4848
const name = 'sample-with-default-template';
4949

5050
await runNgxdCLI(`g c c ${name}`);
@@ -67,7 +67,7 @@ describe('Commands: [Generate] => [Component] => [Common]', () => {
6767
});
6868

6969
test('should generate a common component with spec file', async () => {
70-
const name = 'sample-style-template-url';
70+
const name = 'sample-spec';
7171
await runNgxdCLI(`g c c ${name}`);
7272

7373
const ts = filesystem.read(`${name}/${name}.component.spec.ts`);
@@ -78,7 +78,7 @@ describe('Commands: [Generate] => [Component] => [Common]', () => {
7878
});
7979

8080
test('should properly interpolate component name on spec file', async () => {
81-
const name = 'sample-style-template-url';
81+
const name = 'sample-spec-two';
8282
await runNgxdCLI(`g c c ${name}`);
8383

8484
const ts = filesystem.read(`${name}/${name}.component.spec.ts`);
@@ -91,7 +91,7 @@ describe('Commands: [Generate] => [Component] => [Common]', () => {
9191
});
9292

9393
test('should not contain ngOnInit on import statement', async () => {
94-
const name = 'sample-style-template-url';
94+
const name = 'sample-import';
9595
await runNgxdCLI(`g c c ${name}`);
9696

9797
const ts = filesystem.read(`${name}/${name}.component.ts`);

src/commands/generate/component/dialog/dialog.test.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { filesystem } from 'gluegun';
33
import { runNgxdCLI } from '../../../../utils/cli-test-setup';
44

55
describe('Commands: [Generate] => [Component] => [Dialog]', () => {
6-
const name = 'gdc';
6+
const TESTING_DIR = '__GDC_TEST__';
7+
const COMMAND = 'g c d';
78

89
beforeEach(() => {
910
jest.useFakeTimers();
@@ -12,11 +13,15 @@ describe('Commands: [Generate] => [Component] => [Dialog]', () => {
1213

1314
afterEach(() => {
1415
jest.clearAllTimers();
15-
filesystem.remove(`${name}`);
1616
});
1717

18-
test('should generate a dialog component with 3 files', async () => {
19-
await runNgxdCLI(`g c d ${name}`);
18+
afterAll(() => {
19+
filesystem.remove(TESTING_DIR);
20+
});
21+
22+
test('should generate a dialog component with 3 files', async (done) => {
23+
const name = 'gdc-base-fruit';
24+
await runNgxdCLI(`${COMMAND} ${name}`);
2025

2126
const html = filesystem.read(`${name}/${name}.dialog.html`);
2227
const scss = filesystem.read(`${name}/${name}.dialog.scss`);
@@ -25,14 +30,16 @@ describe('Commands: [Generate] => [Component] => [Dialog]', () => {
2530
expect(html).toBeDefined();
2631
expect(scss).toBeDefined();
2732
expect(ts).toBeDefined();
33+
34+
filesystem.remove(name);
35+
done();
2836
});
2937

30-
test('should generate a dialog component on provided path', async () => {
31-
const name = 'sample-with-path';
32-
const baseFolder = 'sample-app';
33-
const path = `${baseFolder}/src/app/components`;
38+
test('should generate a dialog component on provided path', async (done) => {
39+
const path = `${TESTING_DIR}/components`;
40+
const name = 'fruit1';
3441

35-
await runNgxdCLI(`g c d ${name} --path ${path}`);
42+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
3643

3744
const html = filesystem.read(`${path}/${name}/${name}.dialog.html`);
3845
const scss = filesystem.read(`${path}/${name}/${name}.dialog.scss`);
@@ -41,23 +48,30 @@ describe('Commands: [Generate] => [Component] => [Dialog]', () => {
4148
expect(html).toBeDefined();
4249
expect(scss).toBeDefined();
4350
expect(ts).toBeDefined();
44-
45-
// filesystem.remove(baseFolder);
51+
done();
4652
});
4753

48-
test('should generate a dialog component html with default template <p>sample works</p>', async () => {
49-
await runNgxdCLI(`g c d ${name}`);
50-
const html = filesystem.read(`${name}/${name}.dialog.html`);
54+
test('should generate a dialog component html with default template <p>fruit2 works</p>', async (done) => {
55+
const path = `${TESTING_DIR}/components`;
56+
const name = 'fruit2';
5157

58+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
59+
60+
const html = filesystem.read(`${path}/${name}/${name}.dialog.html`);
5261
expect(html).toContain(`<p>${name} works</p>`);
62+
done();
5363
});
5464

55-
test('should generate a dialog component with correct templateUrl: and styleUrls ', async () => {
56-
await runNgxdCLI(`g c d ${name}`);
65+
test('should generate a dialog component with correct templateUrl: and styleUrls ', async (done) => {
66+
const path = `${TESTING_DIR}/components`;
67+
const name = 'fruitThree';
5768

58-
const ts = filesystem.read(`${name}/${name}.dialog.ts`);
69+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
70+
71+
const ts = filesystem.read(`${path}/${name}/${name}.dialog.ts`);
5972

60-
expect(ts).toContain(`templateUrl: './${name}.dialog.html'`);
61-
expect(ts).toContain(`styleUrls: ['./${name}.dialog.scss']`);
73+
expect(ts).toContain(`templateUrl: './fruit-three.dialog.html'`);
74+
expect(ts).toContain(`styleUrls: ['./fruit-three.dialog.scss']`);
75+
done();
6276
});
6377
});

src/commands/generate/component/page/page.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ import { filesystem } from 'gluegun';
33
import { runNgxdCLI } from '../../../../utils/cli-test-setup';
44

55
describe('Commands: [Generate] => [Component] => [Page]', () => {
6-
const name = 'gpc';
7-
86
beforeEach(() => {
97
jest.useFakeTimers();
108
jest.setTimeout(100000);
119
});
1210

1311
afterEach(() => {
1412
jest.clearAllTimers();
15-
filesystem.remove(`${name}`);
1613
});
1714

1815
test('should generate a page component with 3 files', async () => {
16+
const name = 'base-gcp-fruit';
1917
await runNgxdCLI(`g c p ${name}`);
2018

2119
const html = filesystem.read(`${name}/${name}.page.html`);
@@ -25,6 +23,8 @@ describe('Commands: [Generate] => [Component] => [Page]', () => {
2523
expect(html).toBeDefined();
2624
expect(scss).toBeDefined();
2725
expect(ts).toBeDefined();
26+
27+
filesystem.remove(name);
2828
});
2929

3030
test('should generate a page component on provided path', async () => {
@@ -46,18 +46,22 @@ describe('Commands: [Generate] => [Component] => [Page]', () => {
4646
});
4747

4848
test('should generate a page component html with default template <p>sample works</p>', async () => {
49+
const name = 'sample-with-default-template';
4950
await runNgxdCLI(`g c p ${name}`);
5051
const html = filesystem.read(`${name}/${name}.page.html`);
5152

5253
expect(html).toContain(`<p>${name} works</p>`);
54+
filesystem.remove(name);
5355
});
5456

5557
test('should generate a page component with correct templateUrl: and styleUrls ', async () => {
58+
const name = 'sample-style-template-url';
5659
await runNgxdCLI(`g c p ${name}`);
5760

5861
const ts = filesystem.read(`${name}/${name}.page.ts`);
5962

6063
expect(ts).toContain(`templateUrl: './${name}.page.html'`);
6164
expect(ts).toContain(`styleUrls: ['./${name}.page.scss']`);
65+
filesystem.remove(name);
6266
});
6367
});

src/commands/generate/service/api/api.test.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { filesystem } from 'gluegun';
33
import { runNgxdCLI } from '../../../../utils/cli-test-setup';
44

55
describe('Commands: [Generate] => [Service] => [Api]', () => {
6-
const name = 'gsa';
76
const TESTING_DIR = '__GSA_TEST__';
87
const COMMAND = 'g s a';
98

@@ -16,7 +15,12 @@ describe('Commands: [Generate] => [Service] => [Api]', () => {
1615
jest.clearAllTimers();
1716
});
1817

18+
afterAll(() => {
19+
filesystem.remove(TESTING_DIR);
20+
});
21+
1922
test('should generate a api service with 2 files', async () => {
23+
const name = 'gsa-base-fruit';
2024
await runNgxdCLI(`${COMMAND} ${name}`);
2125

2226
const ts = filesystem.read(`${name}/${name}.api.ts`);
@@ -28,7 +32,8 @@ describe('Commands: [Generate] => [Service] => [Api]', () => {
2832
});
2933

3034
test('should generate a api service at given path', async () => {
31-
const path = `${TESTING_DIR}`;
35+
const name = 'fruit1';
36+
const path = `${TESTING_DIR}/services`;
3237

3338
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
3439

@@ -42,21 +47,22 @@ describe('Commands: [Generate] => [Service] => [Api]', () => {
4247
});
4348

4449
test('should generate a api service with correct content ', async () => {
45-
const name = 'fruit';
50+
const name = 'fruit2';
51+
const path = `${TESTING_DIR}/services`;
4652

47-
await runNgxdCLI(`${COMMAND} ${name}`);
53+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
4854

49-
const ts = filesystem.read(`${name}/${name}.api.ts`);
50-
const spec = filesystem.read(`${name}/${name}.api.spec.ts`);
55+
const ts = filesystem.read(`${path}/${name}/${name}.api.ts`);
56+
const spec = filesystem.read(`${path}/${name}/${name}.api.spec.ts`);
5157

5258
expect(ts).toContain(`import { Injectable } from '@angular/core'`);
5359
expect(ts).toContain(`@Injectable({`);
5460
expect(ts).toContain(`providedIn: 'root'`);
55-
expect(ts).toContain(`export class FruitApi {`);
61+
expect(ts).toContain(`export class Fruit2Api {`);
5662

57-
expect(spec).toContain("describe('FruitApi', () => {");
63+
expect(spec).toContain("describe('Fruit2Api', () => {");
5864
expect(spec).toContain("it('should be created', () => {");
59-
expect(spec).toContain('service = TestBed.inject(FruitApi);');
65+
expect(spec).toContain('service = TestBed.inject(Fruit2Api);');
6066

6167
filesystem.remove(`${name}`);
6268
});

src/utils/functions.test.helper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function getLineNumber(lines: string[], lineNumber: number): string {
2+
return lines[--lineNumber];
3+
}

0 commit comments

Comments
 (0)