mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
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:
@@ -145,11 +145,18 @@ describe('TextOperation', function () {
|
|||||||
const str = random.string(50)
|
const str = random.string(50)
|
||||||
const comments = random.comments(6)
|
const comments = random.comments(6)
|
||||||
const o = randomOperation(str, comments.ids)
|
const o = randomOperation(str, comments.ids)
|
||||||
expect(str.length).to.equal(o.baseLength)
|
try {
|
||||||
const file = new StringFileData(str, comments.comments)
|
expect(str.length).to.equal(o.baseLength)
|
||||||
o.apply(file)
|
const file = new StringFileData(str, comments.comments)
|
||||||
const result = file.getContent()
|
o.apply(file)
|
||||||
expect(result.length).to.equal(o.targetLength)
|
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 doc = random.string(50)
|
||||||
const comments = random.comments(2)
|
const comments = random.comments(2)
|
||||||
const operation = randomOperation(doc, comments.ids)
|
const operation = randomOperation(doc, comments.ids)
|
||||||
const roundTripOperation = TextOperation.fromJSON(operation.toJSON())
|
try {
|
||||||
expect(operation.equals(roundTripOperation)).to.be.true
|
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,15 +227,22 @@ describe('TextOperation', function () {
|
|||||||
const str = random.string(50)
|
const str = random.string(50)
|
||||||
const comments = random.comments(6)
|
const comments = random.comments(6)
|
||||||
const o = randomOperation(str, comments.ids)
|
const o = randomOperation(str, comments.ids)
|
||||||
const originalFile = new StringFileData(str, comments.comments)
|
try {
|
||||||
const p = o.invert(originalFile)
|
const originalFile = new StringFileData(str, comments.comments)
|
||||||
expect(o.baseLength).to.equal(p.targetLength)
|
const p = o.invert(originalFile)
|
||||||
expect(o.targetLength).to.equal(p.baseLength)
|
expect(o.baseLength).to.equal(p.targetLength)
|
||||||
const file = new StringFileData(str, comments.comments)
|
expect(o.targetLength).to.equal(p.baseLength)
|
||||||
o.apply(file)
|
const file = new StringFileData(str, comments.comments)
|
||||||
p.apply(file)
|
o.apply(file)
|
||||||
const result = file.toRaw()
|
p.apply(file)
|
||||||
expect(result).to.deep.equal(originalFile.toRaw())
|
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,16 +397,23 @@ describe('TextOperation', function () {
|
|||||||
const file = new StringFileData(str, comments.comments)
|
const file = new StringFileData(str, comments.comments)
|
||||||
a.apply(file)
|
a.apply(file)
|
||||||
const afterA = file.toRaw()
|
const afterA = file.toRaw()
|
||||||
expect(afterA.content.length).to.equal(a.targetLength)
|
|
||||||
const b = randomOperation(afterA.content, comments.ids)
|
const b = randomOperation(afterA.content, comments.ids)
|
||||||
b.apply(file)
|
try {
|
||||||
const afterB = file.toRaw()
|
expect(afterA.content.length).to.equal(a.targetLength)
|
||||||
expect(afterB.content.length).to.equal(b.targetLength)
|
b.apply(file)
|
||||||
const ab = a.compose(b)
|
const afterB = file.toRaw()
|
||||||
expect(ab.targetLength).to.equal(b.targetLength)
|
expect(afterB.content.length).to.equal(b.targetLength)
|
||||||
ab.apply(new StringFileData(str, comments.comments))
|
const ab = a.compose(b)
|
||||||
const afterAB = file.toRaw()
|
expect(ab.targetLength).to.equal(b.targetLength)
|
||||||
expect(afterAB).to.deep.equal(afterB)
|
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,17 +622,24 @@ describe('TextOperation', function () {
|
|||||||
const comments = random.comments(6)
|
const comments = random.comments(6)
|
||||||
const a = randomOperation(str, comments.ids)
|
const a = randomOperation(str, comments.ids)
|
||||||
const b = randomOperation(str, comments.ids)
|
const b = randomOperation(str, comments.ids)
|
||||||
const primes = TextOperation.transform(a, b)
|
try {
|
||||||
const aPrime = primes[0]
|
const primes = TextOperation.transform(a, b)
|
||||||
const bPrime = primes[1]
|
const aPrime = primes[0]
|
||||||
const abPrime = a.compose(bPrime)
|
const bPrime = primes[1]
|
||||||
const baPrime = b.compose(aPrime)
|
const abPrime = a.compose(bPrime)
|
||||||
const abFile = new StringFileData(str, comments.comments)
|
const baPrime = b.compose(aPrime)
|
||||||
const baFile = new StringFileData(str, comments.comments)
|
const abFile = new StringFileData(str, comments.comments)
|
||||||
abPrime.apply(abFile)
|
const baFile = new StringFileData(str, comments.comments)
|
||||||
baPrime.apply(baFile)
|
abPrime.apply(abFile)
|
||||||
expect(abPrime.equals(baPrime)).to.be.true
|
baPrime.apply(baFile)
|
||||||
expect(abFile.toRaw()).to.deep.equal(baFile.toRaw())
|
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
|
||||||
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user