Skip to content

Commit

Permalink
Add a test case against the focus loss issue
Browse files Browse the repository at this point in the history
Tested that it fails on main reproducing the issue:

```
    - Expected  - 0
    + Received  + 8

      from time import sleep
      input()
      print('before sleep')
      sleep(0.1)
      print('after sleep')
    +
    +
    + x
    +
    +
    +
    +
    +
```
  • Loading branch information
krassowski committed Dec 1, 2023
1 parent 77476a7 commit e2d1d7b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions galata/test/jupyterlab/outputarea-stdin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ test.use({
locale: 'en-US'
});

const loopedInput = `\
from time import sleep
input()
print('before sleep')
sleep(0.1)
print('after sleep')`;

test.describe('Stdin for ipdb', () => {
test.beforeEach(async ({ page }) => {
await page.notebook.createNew();
Expand Down Expand Up @@ -82,4 +89,39 @@ test.describe('Stdin for ipdb', () => {
alphabet + alphabet.toUpperCase() + digits
);
});

test('Subsequent execution in short succession', async ({ page }) => {
await page.notebook.setCell(0, 'code', loopedInput);
// Run the selected (only) cell without proceeding and without waiting
// for it to complete (as it should stay waiting for input).
await page.keyboard.press('Control+Enter');

// Wait for first input
await page.waitForSelector('.jp-Stdin-input');

// Note: this test does not wait for subsequent inputs on purpose

await page.getByText('before sleep').waitFor();

// Press enter five times (should do nothing)
for (let j = 0; j < 5; j++) {
await page.keyboard.press('Enter');
}
// Press a key which should go to the input
await page.keyboard.press('x');

await page.getByText('after sleep').waitFor();

// Press enter five times (should submit and then do nothing)
for (let j = 0; j < 5; j++) {
await page.keyboard.press('Enter');
}

const cellInput = await page.notebook.getCellInput(0);
const editor = await cellInput.$('.cm-content');
const contentAfter = await editor.evaluate((e: any) =>
e.cmView.view.state.doc.toString()
);
expect(contentAfter).toBe(loopedInput);
});
});

0 comments on commit e2d1d7b

Please sign in to comment.