|
| 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