From 29810c6cd1924e08126bd18d759b80abfd1c199c Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Thu, 3 Aug 2017 12:24:56 -0400 Subject: [PATCH 1/2] Attempt to fix flaky test re: blinking cursor As shown in #15122, this test sometimes fails in CI with the following error: TextEditorComponent rendering it blinks cursors when the editor is focused and the cursors are not moving Expected '0' to be '1'. at it (C:\projects\atom\spec\text-editor-component-spec.js:414:49) Expected '0' to be '1'. at it (C:\projects\atom\spec\text-editor-component-spec.js:415:49) I *think* this might be a case of overspecification in the test's assertions. Prior to this commit, the test expected the blinking cursor to *start* in the visible state, and then transition to the invisible state. When we see the failure above, I suspect that the cursor has already transitioned from the visible state to the invisible state by the time the assertion runs. Since the test aims to verify that the cursor blinks, it seems like we should focus on the blinking, and not worry about the *initial* state of the cursor. This commit removes the assertions that verify the initial state of the cursor, and instead asserts that the cursor toggles between the visible and the invisible state. --- spec/text-editor-component-spec.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 1ed7d6657..b12ec23bb 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -411,26 +411,28 @@ describe('TextEditorComponent', () => { await component.getNextUpdatePromise() const [cursor1, cursor2] = element.querySelectorAll('.cursor') - expect(getComputedStyle(cursor1).opacity).toBe('1') - expect(getComputedStyle(cursor2).opacity).toBe('1') - - await conditionPromise(() => - getComputedStyle(cursor1).opacity === '0' && getComputedStyle(cursor2).opacity === '0' - ) - await conditionPromise(() => getComputedStyle(cursor1).opacity === '1' && getComputedStyle(cursor2).opacity === '1' ) - await conditionPromise(() => getComputedStyle(cursor1).opacity === '0' && getComputedStyle(cursor2).opacity === '0' ) + await conditionPromise(() => + getComputedStyle(cursor1).opacity === '1' && getComputedStyle(cursor2).opacity === '1' + ) editor.moveRight() await component.getNextUpdatePromise() - expect(getComputedStyle(cursor1).opacity).toBe('1') - expect(getComputedStyle(cursor2).opacity).toBe('1') + await conditionPromise(() => + getComputedStyle(cursor1).opacity === '0' && getComputedStyle(cursor2).opacity === '0' + ) + await conditionPromise(() => + getComputedStyle(cursor1).opacity === '1' && getComputedStyle(cursor2).opacity === '1' + ) + await conditionPromise(() => + getComputedStyle(cursor1).opacity === '0' && getComputedStyle(cursor2).opacity === '0' + ) }) it('gives cursors at the end of lines the width of an "x" character', async () => { From 15a055b6cd118baaa0f4f3cd01107500aa73e78b Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Thu, 3 Aug 2017 17:36:59 -0400 Subject: [PATCH 2/2] Revert some of the changes from 29810c6cd1 xref: https://github.com/atom/atom/pull/15154#discussion_r131270263 --- spec/text-editor-component-spec.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index b12ec23bb..481602871 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -424,15 +424,8 @@ describe('TextEditorComponent', () => { editor.moveRight() await component.getNextUpdatePromise() - await conditionPromise(() => - getComputedStyle(cursor1).opacity === '0' && getComputedStyle(cursor2).opacity === '0' - ) - await conditionPromise(() => - getComputedStyle(cursor1).opacity === '1' && getComputedStyle(cursor2).opacity === '1' - ) - await conditionPromise(() => - getComputedStyle(cursor1).opacity === '0' && getComputedStyle(cursor2).opacity === '0' - ) + expect(getComputedStyle(cursor1).opacity).toBe('1') + expect(getComputedStyle(cursor2).opacity).toBe('1') }) it('gives cursors at the end of lines the width of an "x" character', async () => {