Skip to content

feat: Styleguide regression tests#1639

Merged
bmingles merged 32 commits intodeephaven:mainfrom
bmingles:1634-styleguide-regression-test
Nov 16, 2023
Merged

feat: Styleguide regression tests#1639
bmingles merged 32 commits intodeephaven:mainfrom
bmingles:1634-styleguide-regression-test

Conversation

@bmingles
Copy link
Copy Markdown
Contributor

@bmingles bmingles commented Nov 13, 2023

  • Enabled styleguide in production builds
  • Added a base set of e2e regression snapshot tests on the styleguide
  • Changed router basename to be based on document.baseURI

#1634

@bmingles bmingles linked an issue Nov 13, 2023 that may be closed by this pull request
@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 13, 2023

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (93eebff) 46.62% compared to head (2c59f87) 46.65%.
Report is 2 commits behind head on main.

Files Patch % Lines
...ackages/code-studio/src/styleguide/SamplesMenu.tsx 57.14% 3 Missing ⚠️
packages/code-studio/src/main/AppRouter.tsx 0.00% 2 Missing ⚠️
packages/code-studio/src/styleguide/utils.ts 91.30% 2 Missing ⚠️
packages/chart/src/MockChartModel.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1639      +/-   ##
==========================================
+ Coverage   46.62%   46.65%   +0.03%     
==========================================
  Files         592      593       +1     
  Lines       36430    36464      +34     
  Branches     9124     9133       +9     
==========================================
+ Hits        16984    17012      +28     
- Misses      19394    19400       +6     
  Partials       52       52              
Flag Coverage Δ
unit 46.65% <82.97%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bmingles bmingles requested a review from mofojed November 14, 2023 00:16
@bmingles bmingles force-pushed the 1634-styleguide-regression-test branch from 36b9f0b to 2abd376 Compare November 14, 2023 14:48
Copy link
Copy Markdown
Member

@mofojed mofojed left a comment

Choose a reason for hiding this comment

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

Overall looks good, some minor things to change (updating readme for style guide, making sure menu button/up arrow don't appear in screenshots).


/** Displays a basic random chart */
class MockChartModel extends ChartModel {
static random: () => number = Math.random.bind(Math);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We do only use one instance of MockChartModel at a time, but these static functions (such as makeRandomData should probably take the random function as input. Kind of weird to re-assign static class function and then use it in constructor, but it is also just used for mocks so not the biggest deal.

Comment thread packages/code-studio/src/styleguide/utils.ts Outdated
Comment thread packages/code-studio/src/styleguide/utils.ts Outdated
Comment on lines -22 to -23
// Proxy styleguide here instead of as a route in our app router
// That way, it is not included in the production build
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need to update the README.md in packages/code-studio to fix the link to the styleguide; right now it just has http://localhost:4000/styleguide, should be http://localhost:4000/ide/styleguide

Also noting that this does not affect bundle size since you're using code splitting to only load the style guide when we go to that route (I think...), however this also means that anybody can open up the styleguide. Which I guess is a good thing if we want people to develop their own themes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FWIW, @dsmmcken is not a fan of surfacing the styleguide to users. I don't think it would be hard to conditionally show it based on an env var + vite config

function AppRouter(): ReactElement {
return (
<Router basename={basename}>
<Router basename={baseURI}>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewing the ReactRouter documentation:

A properly formatted basename should have a leading slash, but no trailing slash.

Right now, all of our BASE_URL's defined do have a trailing slash (./, /ide/). I don't think this manifests any issues, and some of our code that uses the baseURI expects a trailing slash there... so I wouldn't bother changing anything right now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, I missed that baseURI can have a trailing slash. I must have tested on a route that didn't

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How about new URL(document.baseURI).pathname.replace(/\/$/, '')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure, that'd be fine. May as well match what the docs expect.

Digging in the code, it doesn't really matter, the basename prop just gets passed through to createBrowserHistory, which actually removes the trailing slash: https://github.com/remix-run/history/blob/6104a6a2e40ae17a47a297621afff9a6cb184bfc/modules/createBrowserHistory.js#L51
Side note their code for removing the trailing slash is just:

export function stripTrailingSlash(path) {
  return path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path;
}

Comment thread tests/styleguide.spec.ts Outdated
Comment thread tests/styleguide.spec.ts-snapshots/alerts-firefox-linux.png
Comment thread tests/utils.ts
@bmingles bmingles force-pushed the 1634-styleguide-regression-test branch from 48baa4d to cc7fc41 Compare November 15, 2023 22:38
@bmingles bmingles requested a review from mofojed November 15, 2023 23:34
Comment thread tests/utils.ts
Comment on lines +40 to +50

// eslint-disable-next-line no-restricted-syntax
for (const launcher of launchers) {
// eslint-disable-next-line no-await-in-loop
const browser = await launcher.launch();

// eslint-disable-next-line no-console
console.log('Browser:', browser.browserType().name(), browser.version());

browser.close();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Take a look at the description of this rule: https://eslint.org/docs/latest/rules/no-await-in-loop

However, performing an await as part of each operation is an indication that the program is not taking full advantage of the parallelization benefits of async/await.
Usually, the code should be refactored to create all the promises at once, then get access to the results using Promise.all(). Otherwise, each successive operation will not start until the previous one has completed.

I think that applies in this case - we should be able to launch all the browsers in parallel and it should be faster (I think?).

In any case, I'd write this something like this instead of disabling the warnings:

Suggested change
// eslint-disable-next-line no-restricted-syntax
for (const launcher of launchers) {
// eslint-disable-next-line no-await-in-loop
const browser = await launcher.launch();
// eslint-disable-next-line no-console
console.log('Browser:', browser.browserType().name(), browser.version());
browser.close();
}
await Promise.all(
launchers.map(async launcher => {
const browser = await launcher.launch();
// eslint-disable-next-line no-console
console.log('Browser:', browser.browserType().name(), browser.version());
return browser.close();
})
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll try this in my next PR to avoid having to wait for the e2e tests on this one

@bmingles bmingles merged commit 561ff22 into deephaven:main Nov 16, 2023
@bmingles bmingles deleted the 1634-styleguide-regression-test branch November 16, 2023 14:59
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Theming - Inline svgs need to support dynamic css prop colors

3 participants