fix: 🐛 newline being removed for existing import & fix transform errors for a11y ignores codemod (#3183)

* fix: 🐛 newline being removed for existing import & fix errors

* fix: 🐛 avoid testName being undefined
This commit is contained in:
Lisbet Alvarez authored and GitHub committed 2026-06-04 17:00:56 -07:00
1 parent fa51973e6d
commit 4d7ce40469
1 file changed
+20 -9
+20 -9
View File
@@ -90,10 +90,10 @@ export default function transformer(file, api) {
} else { } else {
// if an array is provided and it's argument is a literal (number, boolean, string) then this is used for the test name // if an array is provided and it's argument is a literal (number, boolean, string) then this is used for the test name
// otherwise if it's an object the index in the array is what is used for the test name // otherwise if it's an object the index in the array is what is used for the test name
eachTestNames = testArguments[1].elements.map((element, i) => element.type.endsWith('Literal') ? element.value : i); eachTestNames = testArguments[1].elements?.map((element, i) => element.type.endsWith('Literal') ? element.value : i);
} }
testName = eachTestNames.map(eachTestName => `${testName} [${eachTestName}]`); testName = eachTestNames?.map(eachTestName => `${testName} [${eachTestName}]`) ?? [];
} else { } else {
testName = [testName]; testName = [testName];
} }
@@ -270,16 +270,27 @@ export default function transformer(file, api) {
} }
}; };
const existingEmberA11yImport = f.find(j.ImportDeclaration, {
source: {
value: 'ember-a11y-testing/test-support',
},
});
tests.forEach(testHandler); tests.forEach(testHandler);
testsEach.forEach(testHandler); testsEach.forEach(testHandler);
const code = f.toSource(); const code = f.toSource();
// the codemod will insert a newline between existing import statements,
// this regex removes the extra new line
// if (existingEmberA11yImport.length > 0) {
return code.replace( return code;
/(?<newline>\n)(import .*ember-a11y-testing\/test-support.*)/g, } else {
'$2', // the codemod will insert a newline between existing import statements,
); // this regex removes the extra new line
return code.replace(
/(?<newline>\n)(import .*ember-a11y-testing\/test-support.*)/g,
'$2',
);
}
} }