fix(react): skip adding comma to config when adding remote to host if… (#20620)
This commit is contained in:
parent
332b0120df
commit
d55843cecf
@ -89,6 +89,41 @@ describe('addRemoteToConfig', () => {
|
||||
|
||||
expect(result).toEqual(sourceCode);
|
||||
});
|
||||
|
||||
it('should not add comma if the existing array has a trailing comma', async () => {
|
||||
const sourceCode = stripIndents`
|
||||
module.exports = {
|
||||
name: 'shell',
|
||||
remotes: [
|
||||
'app1',
|
||||
'app2',
|
||||
]
|
||||
};
|
||||
`;
|
||||
|
||||
const source = ts.createSourceFile(
|
||||
'/module-federation.config.js',
|
||||
sourceCode,
|
||||
ts.ScriptTarget.Latest,
|
||||
true
|
||||
);
|
||||
|
||||
const result = applyChangesToString(
|
||||
sourceCode,
|
||||
addRemoteToConfig(source, 'new-app')
|
||||
);
|
||||
|
||||
expect(result).toEqual(stripIndents`
|
||||
module.exports = {
|
||||
name: 'shell',
|
||||
remotes: [
|
||||
'app1',
|
||||
'app2',
|
||||
'new-app',
|
||||
]
|
||||
};
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addRemoteDefinition', () => {
|
||||
|
||||
@ -37,7 +37,7 @@ export function addRemoteToConfig(
|
||||
const lastElement =
|
||||
arrayExpression.elements[arrayExpression.elements.length - 1];
|
||||
return [
|
||||
lastElement
|
||||
lastElement && !arrayExpression.elements.hasTrailingComma
|
||||
? {
|
||||
type: ChangeType.Insert,
|
||||
index: lastElement.end,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user