Skip to content

Commit

Permalink
chore(test-fixture): correct rebuild script string suffix substitution (
Browse files Browse the repository at this point in the history
#11339)

We replace the randomly generated suffix in scenarios when we rebuild
the test fixture to prevent git conflicts. The regex wasn't quite right.
The number is randomly generated between 0 and 10 million but the regex
required at least 6 digits. There was therefore cases where the
generated number was less than 6 digits and did not get replaced.
  • Loading branch information
Josh-Walker-GM committed Aug 22, 2024
1 parent 1e9076c commit 5f9ab5b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tasks/test-project/codemods/scenarioValueSuffix.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
const stringWithSuffixRegex = /String\d+$/

export default (file, api) => {
const j = api.jscodeshift
const root = j(file.source)

const endsWith6DigitsRE = /String.*\d{6,}$/

// Replaces the randomly generated value with consistent ones

// Replaces the randomly generated value with a consistent one
return root
.find(j.Literal, { type: 'StringLiteral' })
.forEach((obj) => {
const stringValue = obj.value.value
if (endsWith6DigitsRE.test(stringValue)) {
if (stringWithSuffixRegex.test(stringValue)) {
obj.value.value = `String${obj.value.loc.start.line}`
}
})
Expand Down

0 comments on commit 5f9ab5b

Please sign in to comment.