21 releases

0.9.5 Sep 8, 2023
0.9.4 Jul 30, 2023
0.9.2 Oct 29, 2022
0.9.1 Apr 18, 2022
0.1.0 Jan 15, 2020

#90 in Value formatting

Download history 32/week @ 2023-11-27 28/week @ 2023-12-04 22/week @ 2023-12-11 26/week @ 2023-12-18 28/week @ 2023-12-25 25/week @ 2024-01-01 123/week @ 2024-01-08 40/week @ 2024-01-15 22/week @ 2024-01-22 14/week @ 2024-01-29 44/week @ 2024-02-05 59/week @ 2024-02-12 108/week @ 2024-02-19 96/week @ 2024-02-26 45/week @ 2024-03-04 27/week @ 2024-03-11

287 downloads per month
Used in 12 crates

MIT license

47KB
1.5K SLoC

JavaScript 583 SLoC // 0.1% comments Rust 536 SLoC // 0.0% comments TypeScript 136 SLoC

dprint-development

Crate for helping to test Rust dprint plugins.

Test Specs

This crate provides a helper function for running test specs defined in text files (for the API, see functions) in the documentation).

This allows you to write tests in the following format (example with TypeScript):

== description goes here ==
const    u    =     2;

[expect]
const u = 2;

For a real world example, see dprint-plugin-typescript/tests.

Changing File Name

By default, the file name used is the one provided to ParseSpecOptions, but you can change the default file name used on a per test spec file basis by adding for example the following to the top of the file:

-- file.tsx --

Configuration

To change the configuration, use the following at the top of the file and below the file name if provided:

~~ indentWidth: 2, useTabs: true ~~

Test Spec Description Helpers

You may change how all the tests are run by adding certain words to a test description:

  • (only) - Only runs this test.
  • (skip) - Skips running this test.
  • (skip-format-twice) - Skips formatting the output again to ensure it stays the same—only formats once.
  • (trace) - Only runs this test and outputs the IR graph to an HTML file to view in a web browser. Must be run with cargo test --features tracing

For example, adding (only) to the description will only run the first test in this example:

== test 1 (only) ==
const    u    =     2;

[expect]
const u = 2;

== test 2 ==
console.log(  10 )

[expect]
console.log(10);

Only Running Tests In A File

To only run tests in a single file, temporarily change the file name to add _Only at the end before the extension. For example, CatchClause_All_Only.txt.

Overwriting Failures

Sometimes a change may cause large test failures (ex. changing default space indentation from 4 spaces to 2 spaces). If you don't want to update all the tests manually, you can specify fix_failures: true to RunSpecsOptions when calling run_specs.

Dependencies

~2–11MB
~89K SLoC