Skip to content

[rustdoc] [GUI tests] Make theme switching closer to reality #123624

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

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ ENV PATH="$NODE_FOLDER:${PATH}"

COPY host-x86_64/x86_64-gnu-tools/browser-ui-test.version /tmp/

# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
# to create a new folder. For reference:
# https://github.com/puppeteer/puppeteer/issues/375
#
# We also specify the version in case we need to update it to go around cache limitations.
#
# The `browser-ui-test.version` file is also used by bootstrap to emit warnings in case
# the local version of the package is different than the one used by the CI.
RUN npm install -g browser-ui-test@$(head -n 1 /tmp/browser-ui-test.version) --unsafe-perm=true

ENV RUST_CONFIGURE_ARGS \
--build=x86_64-unknown-linux-gnu \
--save-toolstates=/tmp/toolstate/toolstates.json \
Expand All @@ -100,6 +90,14 @@ COPY host-x86_64/dist-x86_64-linux/build-gccjit.sh /scripts/

RUN /scripts/build-gccjit.sh /scripts

# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
# to create a new folder. For reference:
# https://github.com/puppeteer/puppeteer/issues/375
#
# We also specify the version in case we need to update it to go around cache limitations.
#
# The `browser-ui-test.version` file is also used by bootstrap to emit warnings in case
# the local version of the package is different than the one used by the CI.
ENV SCRIPT /tmp/checktools.sh ../x.py && \
NODE_PATH=`npm root -g` python3 ../x.py test tests/rustdoc-gui --stage 2 \
--test-args "'--no-sandbox --jobs 1'"
npm install browser-ui-test@$(head -n 1 /tmp/browser-ui-test.version) --unsafe-perm=true && \
python3 ../x.py test tests/rustdoc-gui --stage 2 --test-args "'--no-sandbox --jobs 1'"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.17.1
0.17.2
16 changes: 9 additions & 7 deletions tests/rustdoc-gui/docblock-code-block-line-number.goml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
include: "utils.goml"
go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"

// Otherwise, we can't check text color
show-text: true

// We check that without this setting, there is no line number displayed.
assert-false: "pre.example-line-numbers"

// We set the setting to show the line numbers on code examples.
set-local-storage: {"rustdoc-line-numbers": "true"}
reload:
// We wait for the line numbers to be added into the DOM by the JS...
wait-for: "pre.example-line-numbers"

// Otherwise, we can't check text color
show-text: true

// Let's now check some CSS properties...
define-function: (
"check-colors",
[theme, color],
block {
// We now set the setting to show the line numbers on code examples.
set-local-storage: {"rustdoc-line-numbers": "true"}
// Page will be reloaded in "switch-theme".
call-function: ("switch-theme", {"theme": |theme|})
// We wait for the line numbers to be added into the DOM by the JS...
wait-for: "pre.example-line-numbers"
// If the test didn't fail, it means that it was found!
assert-css: (
"pre.example-line-numbers",
Expand Down
3 changes: 3 additions & 0 deletions tests/rustdoc-gui/scrape-examples-toggle.goml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define-function: (
[theme, toggle_line_color, toggle_line_hover_color],
block {
call-function: ("switch-theme", {"theme": |theme|})
reload:

// Clicking "More examples..." will open additional examples
assert-attribute-false: (".more-examples-toggle", {"open": ""})
Expand All @@ -21,6 +22,8 @@ define-function: (
".toggle-line:hover .toggle-line-inner",
{"background-color": |toggle_line_hover_color|},
)
// We put the toggle in the original state.
click: ".more-examples-toggle"
// Moving cursor away from the toggle line to prevent disrupting next test.
move-cursor-to: ".search-input"
},
Expand Down
15 changes: 6 additions & 9 deletions tests/rustdoc-gui/search-result-color.goml
Original file line number Diff line number Diff line change
Expand Up @@ -210,24 +210,21 @@ call-function: ("check-search-color", {

// Check the alias.
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
// If the text isn't displayed, the browser doesn't compute color style correctly...
show-text: true

write-into: (".search-input", "thisisanalias")
// To be SURE that the search will be run.
press-key: 'Enter'
// Waiting for the search results to appear...
wait-for: "#search-tabs"

define-function: (
"check-alias",
[theme, alias, grey],
block {
call-function: ("switch-theme", {"theme": |theme|})
write-into: (".search-input", "thisisanalias")
// To be SURE that the search will be run.
press-key: 'Enter'
// Waiting for the search results to appear...
wait-for: "#search-tabs"
// Checking that the colors for the alias element are the ones expected.
assert-css: (".result-name .path .alias", {"color": |alias|})
assert-css: (".result-name .path .alias > .grey", {"color": |grey|})
// Leave the search results to prevent reloading with an already filled search input.
press-key: "Escape"
},
)

Expand Down
7 changes: 6 additions & 1 deletion tests/rustdoc-gui/settings.goml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ wait-for: "#alternative-display #search"
assert: "#main-content.hidden"

// Now let's check the content of the settings menu.
call-function: ("switch-theme", {"theme": "dark"})
// If we are on the settings page, the menu doesn't work the same so we set
// the theme manually.
set-local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
// We reload the page so the local storage settings are being used.
reload:

click: "#settings-menu"
wait-for: "#settings"

Expand Down
13 changes: 10 additions & 3 deletions tests/rustdoc-gui/utils.goml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ define-function: (
[theme],
block {
// Set the theme.
set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}
// We reload the page so the local storage settings are being used.
reload:
// Open the settings menu.
click: "#settings-menu"
// Wait for the popover to appear...
wait-for: "#settings"
// Change the setting.
click: "#theme-"+ |theme|
// Close the popover.
click: "#settings-menu"
// Ensure that the local storage was correctly updated.
assert-local-storage: {"rustdoc-theme": |theme|}
},
)
Loading