Skip to content

Commit 47f6f2e

Browse files
committed
✨ feat: add standalone component as default
1 parent ed28161 commit 47f6f2e

File tree

12 files changed

+155
-147
lines changed

12 files changed

+155
-147
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ coverage
66
dist
77
build
88

9+
debug.log

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"cSpell.words": ["devs", "GLUEGUN", "ngxd"]
2+
"cSpell.words": ["cria", "devs", "gluegun", "Gluegun", "GLUEGUN", "ngxd", "serviço"]
33
}

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

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

55
describe('Commands: [Generate] => [Component] => [Common]', () => {
6+
const TESTING_DIR = '__GCC_TEST__';
7+
const COMMAND = 'g c c';
8+
69
beforeEach(() => {
710
jest.useFakeTimers();
811
jest.setTimeout(100000);
912
});
1013

1114
afterEach(() => {
1215
jest.clearAllTimers();
16+
filesystem.remove(TESTING_DIR);
1317
});
1418

1519
test('should generate a common component with 3 files', async () => {
16-
const name = 'sample-with-three-files';
20+
const name = 'gcc-3-files';
1721
await runNgxdCLI(`g c c ${name}`);
1822

1923
const html = filesystem.read(`${name}/${name}.component.html`);
@@ -27,7 +31,7 @@ describe('Commands: [Generate] => [Component] => [Common]', () => {
2731
});
2832

2933
test('should generate a common component on provided path', async () => {
30-
const name = 'sample-with-path';
34+
const name = 'gcc-provided-path';
3135
const baseFolder = 'sample-app';
3236
const path = `${baseFolder}/src/app/components`;
3337

@@ -44,60 +48,59 @@ describe('Commands: [Generate] => [Component] => [Common]', () => {
4448
filesystem.remove(baseFolder);
4549
});
4650

47-
test('should generate a common component html correct content', async () => {
48-
const name = 'sample-with-default-template';
49-
50-
await runNgxdCLI(`g c c ${name}`);
51+
test('should generate a common component html default template', async () => {
52+
const path = `${TESTING_DIR}/components`;
53+
const name = 'gcc-default-template';
5154

52-
const html = filesystem.read(`${name}/${name}.component.html`);
55+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
5356

57+
const html = filesystem.read(`${path}/${name}/${name}.component.html`);
5458
expect(html).toContain(`<p>${name} works</p>`);
55-
filesystem.remove(`${name}`);
5659
});
5760

5861
test('should generate a common component with correct templateUrl: and styleUrls ', async () => {
59-
const name = 'sample-style-template-url';
60-
await runNgxdCLI(`g c c ${name}`);
62+
const path = `${TESTING_DIR}/components`;
63+
const name = 'gcc-template-style';
6164

62-
const ts = filesystem.read(`${name}/${name}.component.ts`);
65+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
66+
67+
const ts = filesystem.read(`${path}/${name}/${name}.component.ts`);
6368

6469
expect(ts).toContain(`templateUrl: './${name}.component.html'`);
6570
expect(ts).toContain(`styleUrls: ['./${name}.component.scss']`);
66-
filesystem.remove(`${name}`);
6771
});
6872

6973
test('should generate a common component with spec file', async () => {
70-
const name = 'sample-spec';
71-
await runNgxdCLI(`g c c ${name}`);
74+
const path = `${TESTING_DIR}/components`;
75+
const name = 'gcc-spec';
7276

73-
const ts = filesystem.read(`${name}/${name}.component.spec.ts`);
77+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
7478

75-
expect(ts).toBeDefined();
79+
const ts = filesystem.read(`${path}/${name}/${name}.component.spec.ts`);
7680

77-
filesystem.remove(`${name}`);
81+
expect(ts).toBeDefined();
7882
});
7983

8084
test('should properly interpolate component name on spec file', async () => {
81-
const name = 'sample-spec-two';
82-
await runNgxdCLI(`g c c ${name}`);
85+
const path = `${TESTING_DIR}/components`;
86+
const name = 'gcc-spec-interpolate';
87+
88+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
8389

84-
const ts = filesystem.read(`${name}/${name}.component.spec.ts`);
90+
const ts = filesystem.read(`${path}/${name}/${name}.component.spec.ts`);
8591

8692
const pascalCaseName = strings.pascalCase(name);
8793

8894
expect(ts).toContain(`describe('${pascalCaseName}Component', () => {`);
89-
90-
filesystem.remove(`${name}`);
9195
});
9296

93-
test('should not contain ngOnInit on import statement', async () => {
94-
const name = 'sample-import';
95-
await runNgxdCLI(`g c c ${name}`);
96-
97-
const ts = filesystem.read(`${name}/${name}.component.ts`);
97+
test('should contain "standalone: true" on component decorator by default', async () => {
98+
const path = `${TESTING_DIR}/components`;
99+
const name = 'gcc-standalone';
100+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
98101

99-
expect(ts).not.toContain(`OnInit`);
102+
const ts = filesystem.read(`${path}/${name}/${name}.component.ts`);
100103

101-
filesystem.remove(`${name}`);
104+
expect(ts).toContain(`standalone: true`);
102105
});
103106
});

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ describe('Commands: [Generate] => [Component] => [Dialog]', () => {
1111
jest.setTimeout(100000);
1212
});
1313

14-
afterEach(() => {
15-
jest.clearAllTimers();
16-
});
17-
1814
afterAll(() => {
15+
jest.clearAllTimers();
1916
filesystem.remove(TESTING_DIR);
2017
});
2118

22-
test('should generate a dialog component with 3 files', async (done) => {
19+
test('should generate a dialog component with 3 files', async () => {
2320
const name = 'gdc-base-fruit';
2421
await runNgxdCLI(`${COMMAND} ${name}`);
2522

@@ -32,12 +29,11 @@ describe('Commands: [Generate] => [Component] => [Dialog]', () => {
3229
expect(ts).toBeDefined();
3330

3431
filesystem.remove(name);
35-
done();
3632
});
3733

38-
test('should generate a dialog component on provided path', async (done) => {
34+
test('should generate a dialog component on provided path', async () => {
3935
const path = `${TESTING_DIR}/components`;
40-
const name = 'fruit1';
36+
const name = 'gdc-provided-path';
4137

4238
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
4339

@@ -48,30 +44,27 @@ describe('Commands: [Generate] => [Component] => [Dialog]', () => {
4844
expect(html).toBeDefined();
4945
expect(scss).toBeDefined();
5046
expect(ts).toBeDefined();
51-
done();
5247
});
5348

54-
test('should generate a dialog component html with default template <p>fruit2 works</p>', async (done) => {
49+
test('should generate a dialog component html with default template <p>gdc-default-template works</p>', async () => {
5550
const path = `${TESTING_DIR}/components`;
56-
const name = 'fruit2';
51+
const name = 'gdc-default-template';
5752

5853
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
5954

6055
const html = filesystem.read(`${path}/${name}/${name}.dialog.html`);
6156
expect(html).toContain(`<p>${name} works</p>`);
62-
done();
6357
});
6458

65-
test('should generate a dialog component with correct templateUrl: and styleUrls ', async (done) => {
59+
test('should generate a dialog component with correct templateUrl: and styleUrls ', async () => {
6660
const path = `${TESTING_DIR}/components`;
67-
const name = 'fruitThree';
61+
const name = 'gdc-template-style';
6862

6963
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
7064

7165
const ts = filesystem.read(`${path}/${name}/${name}.dialog.ts`);
7266

73-
expect(ts).toContain(`templateUrl: './fruit-three.dialog.html'`);
74-
expect(ts).toContain(`styleUrls: ['./fruit-three.dialog.scss']`);
75-
done();
67+
expect(ts).toContain(`templateUrl: './${name}.dialog.html'`);
68+
expect(ts).toContain(`styleUrls: ['./${name}.dialog.scss']`);
7669
});
7770
});

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

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

55
describe('Commands: [Generate] => [Component] => [Page]', () => {
6+
const TESTING_DIR = '__GWC_TEST__';
7+
const COMMAND = 'g c p';
8+
69
beforeEach(() => {
710
jest.useFakeTimers();
811
jest.setTimeout(100000);
912
});
1013

1114
afterEach(() => {
1215
jest.clearAllTimers();
16+
filesystem.remove(TESTING_DIR);
1317
});
1418

1519
test('should generate a page component with 3 files', async () => {
16-
const name = 'base-gcp-fruit';
17-
await runNgxdCLI(`g c p ${name}`);
18-
19-
const html = filesystem.read(`${name}/${name}.page.html`);
20-
const scss = filesystem.read(`${name}/${name}.page.scss`);
21-
const ts = filesystem.read(`${name}/${name}.page.ts`);
22-
23-
expect(html).toBeDefined();
24-
expect(scss).toBeDefined();
25-
expect(ts).toBeDefined();
26-
27-
filesystem.remove(name);
28-
});
29-
30-
test('should generate a page component on provided path', async () => {
31-
const name = 'sample-with-path';
32-
const baseFolder = 'sample-app';
33-
const path = `${baseFolder}/src/app/components`;
34-
35-
await runNgxdCLI(`g c p ${name} --path ${path}`);
20+
const path = `${TESTING_DIR}/components`;
21+
const name = 'gcp-3-files';
22+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
3623

3724
const html = filesystem.read(`${path}/${name}/${name}.page.html`);
3825
const scss = filesystem.read(`${path}/${name}/${name}.page.scss`);
@@ -42,26 +29,43 @@ describe('Commands: [Generate] => [Component] => [Page]', () => {
4229
expect(scss).toBeDefined();
4330
expect(ts).toBeDefined();
4431

45-
filesystem.remove(baseFolder);
32+
filesystem.remove(TESTING_DIR);
4633
});
4734

4835
test('should generate a page component html with default template <p>sample works</p>', async () => {
49-
const name = 'sample-with-default-template';
50-
await runNgxdCLI(`g c p ${name}`);
51-
const html = filesystem.read(`${name}/${name}.page.html`);
36+
const path = `${TESTING_DIR}/components`;
37+
const name = 'gcp-default-template';
38+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
39+
40+
const html = filesystem.read(`${path}/${name}/${name}.page.html`);
5241

5342
expect(html).toContain(`<p>${name} works</p>`);
54-
filesystem.remove(name);
43+
44+
filesystem.remove(TESTING_DIR);
5545
});
5646

5747
test('should generate a page component with correct templateUrl: and styleUrls ', async () => {
58-
const name = 'sample-style-template-url';
59-
await runNgxdCLI(`g c p ${name}`);
48+
const path = `${TESTING_DIR}/components`;
49+
const name = 'gcp-template-style';
50+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
6051

61-
const ts = filesystem.read(`${name}/${name}.page.ts`);
52+
const ts = filesystem.read(`${path}/${name}/${name}.page.ts`);
6253

6354
expect(ts).toContain(`templateUrl: './${name}.page.html'`);
6455
expect(ts).toContain(`styleUrls: ['./${name}.page.scss']`);
65-
filesystem.remove(name);
56+
57+
filesystem.remove(TESTING_DIR);
58+
});
59+
60+
test('should contain "standalone: true" on component decorator by default', async () => {
61+
const path = `${TESTING_DIR}/components`;
62+
const name = 'gcp-standalone-true';
63+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
64+
65+
const ts = filesystem.read(`${path}/${name}/${name}.page.ts`);
66+
67+
expect(ts).toContain(`standalone: true`);
68+
69+
filesystem.remove(TESTING_DIR);
6670
});
6771
});

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

Lines changed: 34 additions & 29 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] => [Widget]', () => {
6-
const name = 'gwc';
6+
const TESTING_DIR = '__GWC_TEST__';
7+
const COMMAND = 'g c w';
78

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

1314
afterEach(() => {
1415
jest.clearAllTimers();
15-
filesystem.remove(`${name}`);
16+
filesystem.remove(TESTING_DIR);
1617
});
1718

1819
test('should generate a widget component on provided path', async () => {
19-
const path = 'sample-project/components';
20-
await runNgxdCLI(`g c w ${name} --path=${path}`);
20+
const path = `${TESTING_DIR}/components`;
21+
const name = 'sample-widget';
22+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
2123

22-
const html = filesystem.read(`${path}/${name}/${name}.component.html`);
23-
const scss = filesystem.read(`${path}/${name}/${name}.component.scss`);
24-
const ts = filesystem.read(`${path}/${name}/${name}.component.ts`);
25-
const widgetModule = filesystem.read(`${path}/${name}/${name}.widget.module.ts`);
24+
const html = filesystem.read(`${path}/${name}/${name}.widget.html`);
25+
const scss = filesystem.read(`${path}/${name}/${name}.widget.scss`);
26+
const ts = filesystem.read(`${path}/${name}/${name}.widget.ts`);
2627

2728
expect(html).toBeDefined();
2829
expect(scss).toBeDefined();
2930
expect(ts).toBeDefined();
30-
expect(widgetModule).toBeDefined();
3131

32-
filesystem.remove('sample-project');
32+
filesystem.remove(TESTING_DIR);
3333
});
3434

35-
test('should generate widget component with 4 files', async () => {
36-
await runNgxdCLI(`g c w ${name}`);
35+
test('should generate widget component html with default template <p>sample works</p>', async () => {
36+
const path = `${TESTING_DIR}/components`;
37+
const name = 'template-sample-widget';
38+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
3739

38-
const html = filesystem.read(`${name}/${name}.component.html`);
39-
const scss = filesystem.read(`${name}/${name}.component.scss`);
40-
const ts = filesystem.read(`${name}/${name}.component.ts`);
41-
const widgetModule = filesystem.read(`${name}/${name}.widget.module.ts`);
40+
const html = filesystem.read(`${path}/${name}/${name}.widget.html`);
4241

43-
expect(html).toBeDefined();
44-
expect(scss).toBeDefined();
45-
expect(ts).toBeDefined();
46-
expect(widgetModule).toBeDefined();
42+
expect(html).toContain(`<p>${name} works</p>`);
43+
44+
filesystem.remove(TESTING_DIR);
4745
});
4846

49-
test('should generate widget component html with default template <p>sample works</p>', async () => {
50-
await runNgxdCLI(`g c w ${name}`);
51-
const html = filesystem.read(`${name}/${name}.component.html`);
47+
test('should generate a widget component with correct templateUrl: and styleUrls ', async () => {
48+
const path = `${TESTING_DIR}/components`;
49+
const name = 'template-style-sample-widget';
50+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
5251

53-
expect(html).toContain(`<p>${name} works</p>`);
52+
const ts = filesystem.read(`${path}/${name}/${name}.widget.ts`);
53+
54+
expect(ts).toContain(`templateUrl: './${name}.widget.html'`);
55+
expect(ts).toContain(`styleUrls: ['./${name}.widget.scss']`);
56+
57+
filesystem.remove(TESTING_DIR);
5458
});
5559

56-
test('should generate a widget component with correct templateUrl: and styleUrls ', async () => {
57-
await runNgxdCLI(`g c w ${name}`);
60+
test('should contain "standalone: true" on component decorator by default', async () => {
61+
const path = `${TESTING_DIR}/components`;
62+
const name = 'standalone-sample-widget';
63+
await runNgxdCLI(`${COMMAND} ${name} --path ${path}`);
5864

59-
const ts = filesystem.read(`${name}/${name}.component.ts`);
65+
const ts = filesystem.read(`${path}/${name}/${name}.widget.ts`);
6066

61-
expect(ts).toContain(`templateUrl: './${name}.component.html'`);
62-
expect(ts).toContain(`styleUrls: ['./${name}.component.scss']`);
67+
expect(ts).toContain(`standalone: true`);
6368
});
6469
});

0 commit comments

Comments
 (0)