Skip to content

Commit 3266772

Browse files
committed
test(cli): guard duplicate component name inputs
closes #1390
1 parent bac99a0 commit 3266772

5 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NgModule } from "@angular/core";
2+
import { ButtonComponent as CurrentButtonComponent } from "./current/button.component";
3+
import { ButtonComponent as LegacyButtonComponent } from "./legacy/button.component";
4+
5+
@NgModule({
6+
declarations: [CurrentButtonComponent, LegacyButtonComponent],
7+
})
8+
export class AppModule {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Component, Input } from "@angular/core";
2+
3+
@Component({
4+
selector: "current-button",
5+
template: "<button>{{label}}</button>",
6+
})
7+
export class ButtonComponent {
8+
@Input() label!: string;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Component, Input } from "@angular/core";
2+
3+
@Component({
4+
selector: "legacy-button",
5+
template: "<button>{{legacyLabel}}</button>",
6+
})
7+
export class ButtonComponent {
8+
@Input() legacyLabel!: string;
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2017",
4+
"module": "commonjs"
5+
},
6+
"include": ["src/**/*"]
7+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { expect } from 'chai';
2+
import { temporaryDir, shell, read } from '../helpers';
3+
4+
const tmp = temporaryDir();
5+
6+
describe('CLI issue #1390 - duplicate component class names', () => {
7+
const distFolder = tmp.name + '-issue-1390';
8+
let documentationJson;
9+
10+
before(done => {
11+
tmp.create(distFolder);
12+
13+
const command = shell('node', [
14+
'./bin/index-cli.js',
15+
'-p',
16+
'./test/fixtures/issue1390-duplicate-component-name/tsconfig.json',
17+
'--silent',
18+
'-e',
19+
'json',
20+
'-d',
21+
distFolder
22+
]);
23+
24+
if (command.stderr.toString() !== '') {
25+
console.error(`shell error: ${command.stderr.toString()}`);
26+
done('error');
27+
return;
28+
}
29+
30+
documentationJson = JSON.parse(read(`${distFolder}/documentation.json`));
31+
done();
32+
});
33+
34+
after(() => tmp.clean(distFolder));
35+
36+
it('should keep both duplicate component classes in exported json', () => {
37+
const components = documentationJson.components.filter(
38+
comp => comp.name === 'ButtonComponent'
39+
);
40+
expect(components).to.have.length(2);
41+
});
42+
43+
it('should not merge inputs between duplicate class names with different selectors', () => {
44+
const components = documentationJson.components.filter(
45+
comp => comp.name === 'ButtonComponent'
46+
);
47+
const currentComponent = components.find(
48+
comp => comp.selector === 'current-button'
49+
);
50+
const legacyComponent = components.find(
51+
comp => comp.selector === 'legacy-button'
52+
);
53+
54+
expect(currentComponent).to.not.be.undefined;
55+
expect(legacyComponent).to.not.be.undefined;
56+
57+
const currentInputs = currentComponent.inputsClass.map(input => input.name);
58+
const legacyInputs = legacyComponent.inputsClass.map(input => input.name);
59+
60+
expect(currentInputs).to.include('label');
61+
expect(currentInputs).to.not.include('legacyLabel');
62+
expect(legacyInputs).to.include('legacyLabel');
63+
expect(legacyInputs).to.not.include('label');
64+
});
65+
});

0 commit comments

Comments
 (0)