Merge pull request #32528 from overleaf/lg-fix-randomised-test-debuggability

[overleaf-editor-core] Log failing inputs in randomised tests

GitOrigin-RevId: 0bc86e9e30935428208fc01c2a4a45f3b19ee837
This commit is contained in:
Lucie Germain
2026-03-31 08:07:48 +00:00
committed by Copybot
parent 8a67258461
commit a8861b2583
@@ -145,11 +145,18 @@ describe('TextOperation', function () {
const str = random.string(50)
const comments = random.comments(6)
const o = randomOperation(str, comments.ids)
try {
expect(str.length).to.equal(o.baseLength)
const file = new StringFileData(str, comments.comments)
o.apply(file)
const result = file.getContent()
expect(result.length).to.equal(o.targetLength)
} catch (err) {
if (err instanceof Error) {
err.message = `Failing inputs:\n str: ${JSON.stringify(str)}\n comments: ${JSON.stringify(comments)}\n o: ${JSON.stringify(o.toJSON())}\n\n${err.message}`
}
throw err
}
})
)
@@ -159,8 +166,15 @@ describe('TextOperation', function () {
const doc = random.string(50)
const comments = random.comments(2)
const operation = randomOperation(doc, comments.ids)
try {
const roundTripOperation = TextOperation.fromJSON(operation.toJSON())
expect(operation.equals(roundTripOperation)).to.be.true
} catch (err) {
if (err instanceof Error) {
err.message = `Failing inputs:\n doc: ${JSON.stringify(doc)}\n comments: ${JSON.stringify(comments)}\n operation: ${JSON.stringify(operation.toJSON())}\n\n${err.message}`
}
throw err
}
})
)
@@ -213,6 +227,7 @@ describe('TextOperation', function () {
const str = random.string(50)
const comments = random.comments(6)
const o = randomOperation(str, comments.ids)
try {
const originalFile = new StringFileData(str, comments.comments)
const p = o.invert(originalFile)
expect(o.baseLength).to.equal(p.targetLength)
@@ -222,6 +237,12 @@ describe('TextOperation', function () {
p.apply(file)
const result = file.toRaw()
expect(result).to.deep.equal(originalFile.toRaw())
} catch (err) {
if (err instanceof Error) {
err.message = `Failing inputs:\n str: ${JSON.stringify(str)}\n comments: ${JSON.stringify(comments)}\n o: ${JSON.stringify(o.toJSON())}\n\n${err.message}`
}
throw err
}
})
)
@@ -376,8 +397,9 @@ describe('TextOperation', function () {
const file = new StringFileData(str, comments.comments)
a.apply(file)
const afterA = file.toRaw()
expect(afterA.content.length).to.equal(a.targetLength)
const b = randomOperation(afterA.content, comments.ids)
try {
expect(afterA.content.length).to.equal(a.targetLength)
b.apply(file)
const afterB = file.toRaw()
expect(afterB.content.length).to.equal(b.targetLength)
@@ -386,6 +408,12 @@ describe('TextOperation', function () {
ab.apply(new StringFileData(str, comments.comments))
const afterAB = file.toRaw()
expect(afterAB).to.deep.equal(afterB)
} catch (err) {
if (err instanceof Error) {
err.message = `Failing inputs:\n str: ${JSON.stringify(str)}\n comments: ${JSON.stringify(comments)}\n a: ${JSON.stringify(a.toJSON())}\n b: ${JSON.stringify(b.toJSON())}\n\n${err.message}`
}
throw err
}
})
)
@@ -594,6 +622,7 @@ describe('TextOperation', function () {
const comments = random.comments(6)
const a = randomOperation(str, comments.ids)
const b = randomOperation(str, comments.ids)
try {
const primes = TextOperation.transform(a, b)
const aPrime = primes[0]
const bPrime = primes[1]
@@ -605,6 +634,12 @@ describe('TextOperation', function () {
baPrime.apply(baFile)
expect(abPrime.equals(baPrime)).to.be.true
expect(abFile.toRaw()).to.deep.equal(baFile.toRaw())
} catch (err) {
if (err instanceof Error) {
err.message = `Failing inputs:\n str: ${JSON.stringify(str)}\n comments: ${JSON.stringify(comments)}\n a: ${JSON.stringify(a.toJSON())}\n b: ${JSON.stringify(b.toJSON())}\n\n${err.message}`
}
throw err
}
})
)