Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce FitAddon tests #2483

Merged
merged 3 commits into from
Oct 18, 2019
Merged

Introduce FitAddon tests #2483

merged 3 commits into from
Oct 18, 2019

Conversation

leomoty
Copy link
Contributor

@leomoty leomoty commented Oct 18, 2019

Fixes #2167

I have a few questions:

  • Can I rely on the default #terminal-container size?
  • Is changing width good enough? should cover height as well?
  • I noticed that if I try something stupid, like having a 1x1 pixel #terminal-container the fit will propose a negative cols. Is this expected behavior?

I want to remove the duplicated code to a helper function before merging.

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that if I try something stupid, like having a 1x1 pixel #terminal-container the fit will propose a negative cols. Is this expected behavior?

I guess this is a bug, feel free to add a test for that and fix it (just prevent < 1x1 cell?)

await page.evaluate(`
window.fit = new FitAddon();
window.term.loadAddon(window.fit);
document.querySelector('#terminal-container').style.width='100%';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be better as an absolute px value in case #terminal-container's container changes its size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

assert.equal(await page.evaluate(`window.fit.proposeDimensions()`), undefined);
});

it('default propose fit', async function(): Promise<any> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move all tests relating to just proposeDimensions into describe('proposeDimensions', () => {, and all fit ones into the same but 'fit'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave the no terminal test outside?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The no terminal test just uses proposeDimensions so it can live in there

await page.evaluate(`
window.fit = new FitAddon();
window.term.loadAddon(window.fit);
document.querySelector('#terminal-container').style.width='100%';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again it might be safer to use px

@leomoty
Copy link
Contributor Author

leomoty commented Oct 18, 2019

How about this instead @Tyriar? it removes a bit of duplicated code, but we don't rely directly on the default width? I can revert otherwise.

I still need to add one test for the 1x1 case, will do after work.

Edit: 1008px is the equivalent of 100% in a 1024x768 screen (you have to account for margin, padding and so forth).

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks! Should be good to merge after the small width test.

@leomoty
Copy link
Contributor Author

leomoty commented Oct 18, 2019

I don't understand why the MacOS integration tests failed, I kept the same timeout that exists elsewhere?

Also, regarding the FitAddon, it doesn't need to be smaller than 1x1 to break:

    it('small width', async function(): Promise<any> {
      await openTerminal();
      await loadFit(1);
      console.log(await page.evaluate(`window.fit.proposeDimensions()`));
    });

returns:

{ cols: -2, rows: 26 }
    it('small width', async function(): Promise<any> {
      await openTerminal();
      await loadFit(1);
      await page.evaluate(`window.fit.fit()`);
      console.log(await page.evaluate(`window.term.cols`));
      console.log(await page.evaluate(`window.term.rows`));
    });

returns:

2
26

What is the desired result?

@leomoty
Copy link
Contributor Author

leomoty commented Oct 18, 2019

Checking the BufferService.ts, I would expect FitAddon to match MINIMUM_COLS and MINIMUM_ROWS defined there. Since that is what Terminal.resize() seems to do nonetheless.

@Tyriar
Copy link
Member

Tyriar commented Oct 18, 2019

@leomoty proposeDimensions should give back the same number as an actual resize would, you can just hardcode the constant into the fit addon as well, should be enough as changing the other constant will break the test.

@Tyriar
Copy link
Member

Tyriar commented Oct 18, 2019

I don't understand why the MacOS integration tests failed, I kept the same timeout that exists elsewhere?

Not sure, try narrow down which await is not returning? I'll requeue the build in case it's flakiness

@leomoty
Copy link
Contributor Author

leomoty commented Oct 18, 2019

I have updated the loadFit to allow both width/height (defaults are based from demo's style.css).

Also updated FitAddon to respect MINIMUM_COLS and MINIMUM_ROWS.

Mac OS is still flaky, but since I only have linux to test, I am not sure why.

@Tyriar
Copy link
Member

Tyriar commented Oct 18, 2019

Looks good, I'll look into the mac test now

@Tyriar
Copy link
Member

Tyriar commented Oct 18, 2019

I couldn't repro the flakiness on my mac, I pushed a change to avoid loading the page every time though which makes the tests take about 25% of the time. Hopefully the flakiness is fixed magically 🤞

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They passed 3 times so I guess the flakiness is gone 🤷‍♂

Thanks for this! 👍

@Tyriar Tyriar added this to the 4.2.0 milestone Oct 18, 2019
@Tyriar Tyriar merged commit 6311076 into xtermjs:master Oct 18, 2019
@leomoty leomoty deleted the fit-tests branch October 18, 2019 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create puppeteer tests for FitAddon
2 participants