Skip to content

Commit cefb084

Browse files
authored
chore: add various rust tests (#104)
1 parent 73a11fa commit cefb084

File tree

14 files changed

+246
-165
lines changed

14 files changed

+246
-165
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88

99
env:
1010
NODE_VERSION: 22
11-
WRANGLER_VERSION: 3.99.0
1211
jobs:
1312
deploy:
1413
runs-on: ubuntu-latest
@@ -36,5 +35,4 @@ jobs:
3635
accountId: ${{ secrets.CF_ACCOUNT_ID }}
3736
command: "deploy --env production"
3837
environment: "production"
39-
wranglerVersion: ${{ env.WRANGLER_VERSION }}
4038

.github/workflows/workflow.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ jobs:
3030
- run: npm run build
3131
- run: npm run lint:js
3232
- run: npm run check-types
33-
- run: cargo clippy --all-targets --all-features
3433
- run: npm run test

Cargo.lock

Lines changed: 16 additions & 107 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ imageproc = { version = "0.25.0", default-features = false }
1818
# logging them with `console.error`. This is great for development, but requires
1919
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
2020
# code size when deploying.
21-
console_error_panic_hook = { version = "0.1.6", optional = true }
21+
console_error_panic_hook = { version = "0.1.7", optional = true }
2222

2323
[dependencies.image]
2424
# Make `image` more lightweight. We don't need every image format under the sun,
@@ -28,7 +28,6 @@ default-features = false
2828
features = ["png"]
2929

3030
[dev-dependencies]
31-
wasm-bindgen-test = "0.2"
3231
clippy = "0.0.302"
3332

3433
[profile.release]

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"lint": "npm run lint:js && npm run lint:rs && npm run check-types",
1515
"lint:js": "eslint \"**/*.{js,mjs,cjs,ts}\" \"**/*.json\"",
1616
"lint:js:fix": "npm run lint:js -- --fix",
17-
"lint:rs": "cargo fmt --all --check",
18-
"lint:rs:fix": "cargo fmt --all",
19-
"test": "vitest --run",
17+
"lint:rs": "cargo fmt --all --check && cargo clippy --all-targets --all-features",
18+
"lint:rs:fix": "cargo fmt --all && cargo clippy --all-targets --all-features --fix",
19+
"test": "vitest --run && cargo test",
2020
"test:dev": "vitest --watch"
2121
},
2222
"devDependencies": {

src/rust/lib.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use skin::*;
1111
use std::io::Cursor;
1212
use wasm_bindgen::prelude::*;
1313

14+
#[derive(Debug, PartialEq)]
1415
enum RenderType {
1516
Avatar,
1617
Helm,
@@ -104,3 +105,61 @@ pub fn get_rendered_image(
104105
Err(_err) => Err(js_sys::Error::new("Couldn't load skin.").into()),
105106
}
106107
}
108+
109+
#[cfg(test)]
110+
mod tests {
111+
use super::*;
112+
113+
#[test]
114+
fn test_what_to_render_type_avatar() {
115+
assert_eq!(
116+
what_to_render_type("avatar".to_string()),
117+
Some(RenderType::Avatar)
118+
);
119+
}
120+
121+
#[test]
122+
fn test_what_to_render_type_helm() {
123+
assert_eq!(
124+
what_to_render_type("helm".to_string()),
125+
Some(RenderType::Helm)
126+
);
127+
}
128+
129+
#[test]
130+
fn test_what_to_render_type_cube() {
131+
assert_eq!(
132+
what_to_render_type("cube".to_string()),
133+
Some(RenderType::Cube)
134+
);
135+
}
136+
137+
#[test]
138+
fn test_what_to_render_type_body() {
139+
assert_eq!(
140+
what_to_render_type("body".to_string()),
141+
Some(RenderType::Body)
142+
);
143+
}
144+
145+
#[test]
146+
fn test_what_to_render_type_bust() {
147+
assert_eq!(
148+
what_to_render_type("bust".to_string()),
149+
Some(RenderType::Bust)
150+
);
151+
}
152+
153+
#[test]
154+
fn test_what_to_render_type_cape() {
155+
assert_eq!(
156+
what_to_render_type("cape".to_string()),
157+
Some(RenderType::Cape)
158+
);
159+
}
160+
161+
#[test]
162+
fn test_what_to_render_type_invalid() {
163+
assert_eq!(what_to_render_type("invalid".to_string()), None);
164+
}
165+
}

0 commit comments

Comments
 (0)