tingerrr / typst-test Goto Github PK
View Code? Open in Web Editor NEWA visual regression test runner for typst packages.
License: MIT License
A visual regression test runner for typst packages.
License: MIT License
Built from commit version: ce06d7e
Rust: 1.75.0
Platform: Windows 11 Home 22H2
Repository: https://github.com/fenjalien/metro/
Running typst-test run
works as expected apart from the diff images are not being generated in the diff folders. I've linked the repository I'm having the issue with.
Currently whenever a new test is created it is populated with "Hello World!". I then have to copy and paste in the package's import statement and other setup which is common to all tests I want to run.
I would like a way to change the default test on a per project basis.
When running multiple tests while not having any packages cached on the system, the multiple instances of Typst can accidentally clear directories for packages another instance has just created, leading to ghostwrites. See typst#2739
While this is technically a Typst issue, it arises mostly when running typst-test in its current form.
This will be resolved with the coming rework, which will ship its own Typst world implementation.
By extracting the core implementation of test scaffolding and test running, other projects such as typst-lsp and typst-preview could benefit from it without needing to interface with the bare bones binary interface.
Typst-preview already supports a special presentation mode for polylux, it's not too far-fetched to assume they could be interested in a special test-watching mode. Likewise, typst-lsp could allow discovering and running tests easily.
Allow users to run custom actions between test stages.
On compelling use case for this is being able to test typstfmt (see #3). This avoids pulling it in as a dependency or even tying it to a command line option of typst-test at all.
With sufficiently flexible custom actions, typstfmt could generate the references from the unaltered test script and the output from the altered version, failing if the formatting introduce a visual regression.
Add some kind of mechanism to mark tests which do not have references and are meant only to be compiled.
Just omitting the references could be enough, an option on new
and edit
could be added to select if a test should be compared or not.
I encountered the same issue as in #19.
When running a test, I get the message:
typst-test ran into an unexpected error, this is most likely a bug
Please consider reporting this at https://github.com/tingerrr/typst-test/issues/new
Error:unexpected character '\n' after patch version number
Here is what I did:
cargo install typst-test --git https://github.com/tingerrr/typst-test
typst-test init
typst-test add test-1
typst-test run test1
The installation command gives the following warning:
Compiling typst-test v0.1.0 (/Users/xxx/.cargo/git/checkouts/typst-test-af24935a6e1ceb4c/97b1839/crates/typst-test)
warning: variants `RootNotFound` and `InitNeeded` are never constructed
--> crates/typst-test/src/project/mod.rs:398:5
|
396 | pub enum Error {
| ----- variants in this enum
397 | #[error("project not found: {0:?}")]
398 | RootNotFound(PathBuf),
| ^^^^^^^^^^^^
...
404 | InitNeeded,
| ^^^^^^^^^^
|
= note: `Error` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
= note: `#[warn(dead_code)]` on by default
warning: `typst-test` (bin "typst-test") generated 1 warning
I ran the commands in several of my packages and even downloaded some other packages and always got the same error message.
I tried the ci-semi-stabel
branch with no luck. The ci-semi-stable
tag works for me, though.
I propose changing the folder structure, such that each test file lives in its own folder. A test folder contains a Typst file (e.g. "test.typ") plus the reference image.
CeTZ currently uses its own test script, which structures the tests as given above, but we would like to use typst-test
.
CeTZ's tests are recognized by recursively scanning the tests/
directory for test.typ
files and, if found, use the folder of those files as test-cases. This allows nesting/grouping tests by topic by just putting them in common parent directories.
When generating a diff image, the following things could be improved:
Looks really nice!
Maybe it could be use to test formatters as well!
Given a formatter and a test file
It could happily live next to typstfmt when I get up to it but I think it might be better suited in typst-test
for example the number of mismatched pixels.
This would be very helpful in the case when tests fail due to extremely minor changes. Especially PNG rendering is sometimes subject to minute differences even when PDF/SVG output is not (at least visually) affected.
Thanks for this project - I've been using it for some months now and it is amazing :)
Error:
$ typst-test update
typst-test ran into an unexpected error, this is most likely a bug
Please consider reporting this at https://github.com/tingerrr/typst-test/issues/new
typst.toml
[package]
name = "mypackage"
version = "0.0.2"
entrypoint = "lib.typ"
authors = ["Keyneston"]
repository = "https://github.com/keyneston/mypackage"
license = "MIT"
The typst-test program executes sufficiently rapidly that power users may benefit from a --watch
flag that runs the test suite when it detects a change in any project files.
It may be more involved than just adding a flag, however, as people are likely to want to exclude or include specific files or filetypes, so a configuration service may also be needed (which is a lot of bloat)
To avoid repository bloat, don't save images and instead store some kind of symbolic reference to another storage and a way to retrieve this reference from the given storage.
An external store comes with some security, performance and usability issues, but may be worth it in the long run.
The main motivation for this is that images are not meant to be stored as is in a git repository. Solutions such as Git LFS on GitHub are horrendously overpriced for FOSS repositories. Another issue with storing images in a git repository is that they are often optimized to account for aforementioned bloat. This optimization can take quite long even on updates which introduce only a minor change to the reference, as comparison is not perceptual, but exact.
See more on a related discussion on the Typst community discord here.
By adding typst as a dependency, test output generation and comparison could be done entirely in memory. This seems like a sensible thing to do, here are some of the pros and cons:
Pros
Cons
The current implementation is a little brittle, this has a lot of downsides:
?
, other times it's swallowed and simply printed to stdoutThe core should be reworked into a solid foundation on which new features can be built. At this stage, the project is still fairly small, and a rewrite is feasible.
I want to achieve the following goals with the rewrite:
With a folder structure like test/higher/lower/test.typ
and no test.typ
in higher/
. Using the add
command removes everything in higher/
.
The change introduced in 97b1839 was rather hasty and caused even simple mismatches to be ignored.
A user could initialize a project, remove the d
in the default example test, run the tests and observe a pass. The metrics chosen for the relaxed comparison were not good enough and need to be opt in.
ci-semis-table
has since been rolled back to the previous commit.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.