mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Merge pull request #32688 from overleaf/mj-chai-messages
[overleaf-editor-core] Use chai messages instead of try-catch in fuzzing tests GitOrigin-RevId: b6db81e2fdbaac730ddca2bfb555983685396b43
This commit is contained in:
committed by
Copybot
parent
bd604063e6
commit
c2c8b1d1f1
@@ -17,6 +17,10 @@ const { RetainOp, InsertOp, RemoveOp } = require('../../lib/operation/scan_op')
|
|||||||
const TrackingProps = require('../../lib/file_data/tracking_props')
|
const TrackingProps = require('../../lib/file_data/tracking_props')
|
||||||
const ClearTrackingProps = require('../../lib/file_data/clear_tracking_props')
|
const ClearTrackingProps = require('../../lib/file_data/clear_tracking_props')
|
||||||
|
|
||||||
|
function fuzzingErrorMessage(obj) {
|
||||||
|
return `Failed randomized test with input: ${JSON.stringify(obj)}`
|
||||||
|
}
|
||||||
|
|
||||||
describe('TextOperation', function () {
|
describe('TextOperation', function () {
|
||||||
const numTrials = 500
|
const numTrials = 500
|
||||||
|
|
||||||
@@ -145,18 +149,12 @@ 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)
|
||||||
try {
|
const fuzzingError = fuzzingErrorMessage({ str, comments, o: o.toJSON() })
|
||||||
expect(str.length).to.equal(o.baseLength)
|
expect(str.length).to.equal(o.baseLength, fuzzingError)
|
||||||
const file = new StringFileData(str, comments.comments)
|
const file = new StringFileData(str, comments.comments)
|
||||||
o.apply(file)
|
o.apply(file)
|
||||||
const result = file.getContent()
|
const result = file.getContent()
|
||||||
expect(result.length).to.equal(o.targetLength)
|
expect(result.length).to.equal(o.targetLength, fuzzingError)
|
||||||
} 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
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -166,15 +164,11 @@ 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)
|
||||||
try {
|
|
||||||
const roundTripOperation = TextOperation.fromJSON(operation.toJSON())
|
const roundTripOperation = TextOperation.fromJSON(operation.toJSON())
|
||||||
expect(operation.equals(roundTripOperation)).to.be.true
|
expect(operation.equals(roundTripOperation)).to.equal(
|
||||||
} catch (err) {
|
true,
|
||||||
if (err instanceof Error) {
|
fuzzingErrorMessage({ operation })
|
||||||
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
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -227,22 +221,20 @@ 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)
|
||||||
try {
|
|
||||||
const originalFile = new StringFileData(str, comments.comments)
|
const originalFile = new StringFileData(str, comments.comments)
|
||||||
const p = o.invert(originalFile)
|
const p = o.invert(originalFile)
|
||||||
expect(o.baseLength).to.equal(p.targetLength)
|
const fuzzingError = fuzzingErrorMessage({
|
||||||
expect(o.targetLength).to.equal(p.baseLength)
|
str,
|
||||||
|
comments,
|
||||||
|
o: o.toJSON(),
|
||||||
|
})
|
||||||
|
expect(o.baseLength).to.equal(p.targetLength, fuzzingError)
|
||||||
|
expect(o.targetLength).to.equal(p.baseLength, fuzzingError)
|
||||||
const file = new StringFileData(str, comments.comments)
|
const file = new StringFileData(str, comments.comments)
|
||||||
o.apply(file)
|
o.apply(file)
|
||||||
p.apply(file)
|
p.apply(file)
|
||||||
const result = file.toRaw()
|
const result = file.toRaw()
|
||||||
expect(result).to.deep.equal(originalFile.toRaw())
|
expect(result).to.deep.equal(originalFile.toRaw(), fuzzingError)
|
||||||
} 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
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -394,26 +386,33 @@ describe('TextOperation', function () {
|
|||||||
const str = random.string(20)
|
const str = random.string(20)
|
||||||
const comments = random.comments(6)
|
const comments = random.comments(6)
|
||||||
const a = randomOperation(str, comments.ids)
|
const a = randomOperation(str, comments.ids)
|
||||||
|
const fuzzingError = fuzzingErrorMessage({
|
||||||
|
str,
|
||||||
|
comments,
|
||||||
|
a: a.toJSON(),
|
||||||
|
})
|
||||||
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, fuzzingError)
|
||||||
const b = randomOperation(afterA.content, comments.ids)
|
const b = randomOperation(afterA.content, comments.ids)
|
||||||
try {
|
const fuzzingErrorWithB = fuzzingErrorMessage({
|
||||||
expect(afterA.content.length).to.equal(a.targetLength)
|
str,
|
||||||
|
comments,
|
||||||
|
a: a.toJSON(),
|
||||||
|
b: b.toJSON(),
|
||||||
|
})
|
||||||
b.apply(file)
|
b.apply(file)
|
||||||
const afterB = file.toRaw()
|
const afterB = file.toRaw()
|
||||||
expect(afterB.content.length).to.equal(b.targetLength)
|
expect(afterB.content.length).to.equal(
|
||||||
|
b.targetLength,
|
||||||
|
fuzzingErrorWithB
|
||||||
|
)
|
||||||
const ab = a.compose(b)
|
const ab = a.compose(b)
|
||||||
expect(ab.targetLength).to.equal(b.targetLength)
|
expect(ab.targetLength).to.equal(b.targetLength, fuzzingErrorWithB)
|
||||||
ab.apply(new StringFileData(str, comments.comments))
|
ab.apply(new StringFileData(str, comments.comments))
|
||||||
const afterAB = file.toRaw()
|
const afterAB = file.toRaw()
|
||||||
expect(afterAB).to.deep.equal(afterB)
|
expect(afterAB).to.deep.equal(afterB, fuzzingErrorWithB)
|
||||||
} 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
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -622,7 +621,6 @@ 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)
|
||||||
try {
|
|
||||||
const primes = TextOperation.transform(a, b)
|
const primes = TextOperation.transform(a, b)
|
||||||
const aPrime = primes[0]
|
const aPrime = primes[0]
|
||||||
const bPrime = primes[1]
|
const bPrime = primes[1]
|
||||||
@@ -632,14 +630,14 @@ describe('TextOperation', function () {
|
|||||||
const baFile = new StringFileData(str, comments.comments)
|
const baFile = new StringFileData(str, comments.comments)
|
||||||
abPrime.apply(abFile)
|
abPrime.apply(abFile)
|
||||||
baPrime.apply(baFile)
|
baPrime.apply(baFile)
|
||||||
expect(abPrime.equals(baPrime)).to.be.true
|
const fuzzingError = fuzzingErrorMessage({
|
||||||
expect(abFile.toRaw()).to.deep.equal(baFile.toRaw())
|
str,
|
||||||
} catch (err) {
|
comments,
|
||||||
if (err instanceof Error) {
|
a: a.toJSON(),
|
||||||
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}`
|
b: b.toJSON(),
|
||||||
}
|
})
|
||||||
throw err
|
expect(abPrime.equals(baPrime)).to.be.equal(true, fuzzingError)
|
||||||
}
|
expect(abFile.toRaw()).to.deep.equal(baFile.toRaw(), fuzzingError)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user