mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-08 08:07:32 +03:00
Make randomized presenter spec failures easier to reproduce
This commit is contained in:
parent
5bb3095ffa
commit
1ae25ed85d
@ -1763,17 +1763,28 @@ describe "TextEditorPresenter", ->
|
|||||||
expect(presenter.state.height).toBe editor.getScreenLineCount() * 20
|
expect(presenter.state.height).toBe editor.getScreenLineCount() * 20
|
||||||
|
|
||||||
describe "when the model and view measurements are mutated randomly", ->
|
describe "when the model and view measurements are mutated randomly", ->
|
||||||
[editor, buffer, presenter, presenterParams] = []
|
[editor, buffer, presenterParams, presenter, statements] = []
|
||||||
|
|
||||||
it "correctly maintains the presenter state", ->
|
it "correctly maintains the presenter state", ->
|
||||||
_.times 10, ->
|
_.times 20, ->
|
||||||
waits(0)
|
waits(0)
|
||||||
|
|
||||||
runs ->
|
runs ->
|
||||||
|
performSetup()
|
||||||
|
_.times 20, ->
|
||||||
|
performRandomAction (statement) -> statements.push(statement)
|
||||||
|
expectValidState()
|
||||||
|
performTeardown()
|
||||||
|
|
||||||
|
xit "works correctly for a particular stream of random actions", ->
|
||||||
|
performSetup()
|
||||||
|
# paste output from failing spec here
|
||||||
|
expectValidState()
|
||||||
|
performTeardown()
|
||||||
|
|
||||||
|
performSetup = ->
|
||||||
buffer = new TextBuffer
|
buffer = new TextBuffer
|
||||||
editor = new TextEditor({buffer})
|
editor = new TextEditor({buffer})
|
||||||
editor.setEditorWidthInChars(80)
|
editor.setEditorWidthInChars(80)
|
||||||
|
|
||||||
presenterParams =
|
presenterParams =
|
||||||
model: editor
|
model: editor
|
||||||
height: 50
|
height: 50
|
||||||
@ -1783,14 +1794,16 @@ describe "TextEditorPresenter", ->
|
|||||||
lineHeight: 10
|
lineHeight: 10
|
||||||
baseCharacterWidth: 10
|
baseCharacterWidth: 10
|
||||||
lineOverdrawMargin: 1
|
lineOverdrawMargin: 1
|
||||||
|
horizontalScrollbarHeight: 5
|
||||||
|
verticalScrollbarWidth: 5
|
||||||
presenter = new TextEditorPresenter(presenterParams)
|
presenter = new TextEditorPresenter(presenterParams)
|
||||||
referencePresenter = new TextEditorPresenter(presenterParams)
|
statements = []
|
||||||
expect(presenter.state).toEqual referencePresenter.state
|
|
||||||
|
|
||||||
actions = []
|
performTeardown = ->
|
||||||
_.times 30, ->
|
buffer.destroy()
|
||||||
performRandomAction (action) -> actions.push(action)
|
|
||||||
|
expectValidState = ->
|
||||||
|
presenterParams.scrollTop = presenter.scrollTop
|
||||||
actualState = presenter.state
|
actualState = presenter.state
|
||||||
expectedState = new TextEditorPresenter(presenterParams).state
|
expectedState = new TextEditorPresenter(presenterParams).state
|
||||||
delete actualState.content.scrollingVertically
|
delete actualState.content.scrollingVertically
|
||||||
@ -1803,14 +1816,15 @@ describe "TextEditorPresenter", ->
|
|||||||
console.log "Uncomment code below this line to see a JSON diff"
|
console.log "Uncomment code below this line to see a JSON diff"
|
||||||
# {diff} = require 'json-diff' # !!! Run `npm install json-diff` in your `atom/` repository
|
# {diff} = require 'json-diff' # !!! Run `npm install json-diff` in your `atom/` repository
|
||||||
# console.log "Difference:", diff(actualState, expectedState)
|
# console.log "Difference:", diff(actualState, expectedState)
|
||||||
console.log ""
|
if statements.length > 0
|
||||||
console.log "Actions:"
|
console.log """
|
||||||
console.log action for action in actions
|
=====================================================
|
||||||
console.log ""
|
Paste this code into the disabled spec in this file (and enable it) to repeat this failure:
|
||||||
console.log "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
|
|
||||||
throw new Error("Unexpected presenter state after random mutation. Check console output for details.")
|
|
||||||
|
|
||||||
buffer.destroy()
|
#{statements.join('\n')}
|
||||||
|
=====================================================
|
||||||
|
"""
|
||||||
|
throw new Error("Unexpected presenter state after random mutation. Check console output for details.")
|
||||||
|
|
||||||
performRandomAction = (log) ->
|
performRandomAction = (log) ->
|
||||||
getRandomElement([
|
getRandomElement([
|
||||||
@ -1826,11 +1840,7 @@ describe "TextEditorPresenter", ->
|
|||||||
changeScrollTop = (log) ->
|
changeScrollTop = (log) ->
|
||||||
scrollHeight = presenterParams.lineHeight * editor.getScreenLineCount()
|
scrollHeight = presenterParams.lineHeight * editor.getScreenLineCount()
|
||||||
newScrollTop = Math.max(0, _.random(0, scrollHeight - presenterParams.height))
|
newScrollTop = Math.max(0, _.random(0, scrollHeight - presenterParams.height))
|
||||||
log """
|
log "presenter.setScrollTop(#{newScrollTop})"
|
||||||
presenterParams.scrollTop = #{newScrollTop}
|
|
||||||
presenter.setScrollTop(#{newScrollTop})
|
|
||||||
"""
|
|
||||||
presenterParams.scrollTop = newScrollTop
|
|
||||||
presenter.setScrollTop(newScrollTop)
|
presenter.setScrollTop(newScrollTop)
|
||||||
|
|
||||||
changeScrollLeft = (log) ->
|
changeScrollLeft = (log) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user