Skip to content
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

test(tools): validate js-beautify #868

Merged
merged 1 commit into from
Mar 23, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ jobs:
run: ( ( which jq ) || ( ( which apt-get && sudo apt-get install -y jq ) ) || ( echo "Unable to install tool" ) )
- name: jqfmt
run: ( ( which jqfmt ) || ( ( which go && go install github.com/noperator/jqfmt/cmd/jqfmt@latest ) ) || ( echo "Unable to install tool" ) )
- name: js-beautify
run: ( ( which js-beautify ) || ( ( which npm && npm i -g js-beautify ) ) || ( echo "Unable to install tool" ) )
- name: jsonlint
run: ( ( which jsonlint ) || ( ( which npm && npm i -g jsonlint ) ) || ( echo "Unable to install tool" ) )
- name: jsonpp
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. Dates are d

#### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.8.2...HEAD)

- test(tools): validate jsonlint [`#867`](https://github.com/hougesen/mdsf/pull/867)
- test(tools): validate vhdl-style-guide [`#866`](https://github.com/hougesen/mdsf/pull/866)
- refactor: add empty tests array if not set [`#865`](https://github.com/hougesen/mdsf/pull/865)
- test(tools): add test for misspell [`#864`](https://github.com/hougesen/mdsf/pull/864)
Expand Down
30 changes: 30 additions & 0 deletions mdsf/src/tools/js_beautify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,33 @@ pub const COMMANDS: [CommandType; 7] = [
];

pub const IS_STDIN: bool = false;

#[cfg(test)]
mod test_js_beautify {
#[test_with::executable(js-beautify || npx || pnpm || deno || bunx)]
fn test_js_beautify_javascript_151bf21bc63609e8() {
let input = r#"function add (a,b){return a +b }"#;

let output = r#"function add(a, b) {
return a + b
}"#;

let file_ext = crate::fttype::get_file_extension("javascript");

let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");

let result = crate::tools::Tooling::JsBeautify
.format_snippet(
snippet.path(),
crate::testing::DEFAULT_TEST_FORMATTER_TIMEOUT,
crate::testing::DEFAULT_TEST_DEBUG_ENABLED,
&crate::config::MdsfConfigRunners::all(),
)
.expect("it to be successful")
.1
.expect("it to be some");

assert_eq!(result, output);
}
}
8 changes: 7 additions & 1 deletion tools/js-beautify/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
"commands": {
"": {
"arguments": ["-r", "--type", "js", "-f", "$PATH"],
"tests": []
"tests": [
{
"language": "javascript",
"test_input": "function add (a,b){return a +b }",
"test_output": "function add(a, b) {\n return a + b\n}"
}
]
}
},
"description": "A JavaScript formatter",
Expand Down
Loading