1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-06 17:46:16 +02:00
comprehensive-rust/tests/src/slide-size.test.ts
michael-kerscher 53f7660e9b
Evaluate slide size and block if they grow above a certain treshold (with exemption mechanism) (#2693)
This enables a test for the width and height of slides (excluding some
special cases completely).
The mechanism has an exemption mechanism to temporarily exempt slides
from the rules.
Even exempted slides are checked for the rule violation and once the
slides are compliant they must be removed from the exemption list to
avoid future regression (the check fails in the CI if compliant slides
are exempted!)

This also provides a good opportunity to always have an up-to-date list
of overlong slides in
[slide-exemptions.list.ts](tests/src/slides/slide-exemptions.list.ts)
that can be worked on.

The slide list is always autogenerated in the CI environment. If you want to
enable this for your local dev environment it has to be created manually.
This avoids a time consuming local test if it is not necessary.

On the CLI it can be locally used with `npm run test --
--spec=src/slide-size.test.ts` (after creating the list with
`./src/slides/create-slide.list.sh ../book/html/`).
The CI environment specifies the env var `TEST_BOOK_DIR` that is used to
specifiy the html directory so it can create the list of slides
on-the-fly, check against hardcoded exemptions and evaluate.

This is a new solution for #1464 within the new test framework. This is
related to #2234 and makes the mdbook-slide-evaluator from #2258
obsolete and should be removed as this is a not so powerful nor flexible
framework.
2025-03-18 12:50:46 +01:00

54 lines
1.7 KiB
TypeScript

import { describe, it } from "mocha";
import { $, expect, browser } from "@wdio/globals";
import { slides } from "./slides/slides.list";
import { exemptions } from "./slides/slide-exemptions.list";
// these are empirically determined values in 16:9 ratio
const MAX_HEIGHT = 1333;
const MAX_WIDTH = 750;
describe("Slide", () => {
for (const slide of slides) {
if (exemptions.includes(slide)) {
// This slide is exempted and violated rules before.
// It is expected to still do this and if not it should be removed from exemptions.
// This acts as a regression check
it(
" " +
slide +
" is on the exemption list but should be removed from slide-exemptions.list.ts",
async () => {
await browser.url("/" + slide);
const main_element = $("#content > main");
const main_element_size = await main_element.getSize();
console.info("slide " + slide + " is on the exemption list");
// one of them (height, width) should fail
expect(
main_element_size.height >= MAX_HEIGHT ||
main_element_size.width > MAX_WIDTH,
).toBe(true);
},
);
} else {
it(
" " +
slide +
" should not be higher than " +
MAX_HEIGHT +
" pixels or wider than " +
MAX_WIDTH +
" pixels",
async () => {
await browser.url("/" + slide);
const main_element = $("#content > main");
const main_element_size = await main_element.getSize();
expect(
main_element_size.height < MAX_HEIGHT &&
main_element_size.width <= MAX_WIDTH,
).toBe(true);
},
);
}
}
});