-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. -->
- Loading branch information
1 parent
dd9309f
commit 54cf5bb
Showing
14 changed files
with
256 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Source Code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Rust Cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Install Wasm Pack | ||
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh | ||
|
||
- name: Tests | ||
run: cargo test | ||
|
||
test_wasm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Source Code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Rust Cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- uses: browser-actions/setup-geckodriver@latest | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Install Just Command Runner | ||
uses: extractions/setup-just@v1 | ||
|
||
- name: Install Wasm Pack | ||
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh | ||
|
||
- name: Tests | ||
run: just test_ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ bin/ | |
pkg/ | ||
wasm-pack.log | ||
http-server | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use thiserror::Error; | ||
use wasm_bindgen::prelude::*; | ||
use wasm_bindgen::JsValue; | ||
|
||
pub type Result<T> = std::result::Result<T, MinceError>; | ||
|
||
#[wasm_bindgen] | ||
#[derive(Debug, Error)] | ||
pub enum MinceError { | ||
#[error("IO error")] | ||
Generic, | ||
#[error("Failed to read file into bytes")] | ||
FileRead, | ||
#[error("Failed to detect image format")] | ||
DetectImageFormat, | ||
#[error("Failed to decode image")] | ||
DecodeImage, | ||
#[error("Failed to encode image")] | ||
EncodeImage, | ||
} | ||
|
||
impl Into<JsValue> for MinceError { | ||
fn into(self) -> JsValue { | ||
JsValue::from_str(&self.to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
mod image; | ||
mod utils; | ||
|
||
use wasm_bindgen::prelude::*; | ||
pub mod error; | ||
pub mod image; | ||
pub mod utils; | ||
|
||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global | ||
// allocator. | ||
#[cfg(feature = "wee_alloc")] | ||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
// Use `js_namespace` here to bind `console.log(..)` instead of just | ||
// `log(..)` | ||
#[wasm_bindgen(js_namespace = console)] | ||
pub fn log(s: &str); | ||
pub mod console { | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
#[wasm_bindgen(js_namespace = console)] | ||
pub fn log(s: &str); | ||
|
||
#[wasm_bindgen(js_namespace = console)] | ||
pub fn error(s: &str); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![cfg(target_arch = "wasm32")] | ||
|
||
use js_sys::{Array, Uint8Array}; | ||
use wasm_bindgen_test::*; | ||
use web_sys::{File as JsFile, FilePropertyBag}; | ||
|
||
pub const JPEG_420_EFIX: &[u8; 768608] = include_bytes!("../assets/jpeg420exif.jpg"); | ||
|
||
pub fn read_file(bytes: &[u8], mime: &str) -> JsFile { | ||
// Prepare a Blob from the file bytes | ||
let uint8_array = Uint8Array::from(bytes); | ||
let sequence = Array::new(); | ||
sequence.push(&uint8_array.buffer()); | ||
|
||
let mut file_options = FilePropertyBag::new(); | ||
file_options.type_(mime); | ||
|
||
JsFile::new_with_blob_sequence_and_options(&sequence, "test", &file_options) | ||
.expect("Failed to create File from Blob") | ||
} | ||
|
||
wasm_bindgen_test_configure!(run_in_browser); | ||
|
||
#[wasm_bindgen_test] | ||
fn makes_file_from_bytes() { | ||
let file = read_file(JPEG_420_EFIX, "image/jpeg"); | ||
|
||
assert_eq!(file.size() as usize, 768608); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Test suite for the Web and headless browsers. | ||
#![cfg(target_arch = "wasm32")] | ||
|
||
mod utils; | ||
|
||
use std::assert_eq; | ||
|
||
use wasm_bindgen_test::*; | ||
|
||
use mince::image::Mince; | ||
|
||
use utils::{read_file, JPEG_420_EFIX}; | ||
|
||
wasm_bindgen_test_configure!(run_in_browser); | ||
|
||
#[wasm_bindgen_test] | ||
async fn reads_file_metadata() { | ||
let file = read_file(JPEG_420_EFIX, "image/jpeg"); | ||
let mince = Mince::from_file(file).await.unwrap(); | ||
let meta = mince.meta(); | ||
|
||
assert_eq!(meta.width, 2048); | ||
assert_eq!(meta.height, 1536); | ||
assert_eq!(meta.format, mince::image::Format::Jpeg); | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
async fn encodes_jpeg() { | ||
let file = read_file(JPEG_420_EFIX, "image/jpeg"); | ||
let mince = Mince::from_file(file).await.unwrap(); | ||
let output_file = mince.to_file().expect("Failed to encode image"); | ||
|
||
assert_eq!(output_file.name(), "mince_image.jpeg"); | ||
assert_eq!(output_file.type_(), "image/jpeg"); | ||
assert_eq!(output_file.size(), 2068725.); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"moz:firefoxOptions": { | ||
"prefs": { | ||
"media.navigator.streams.fake": true, | ||
"media.navigator.permission.disabled": true | ||
}, | ||
"args": [] | ||
} | ||
} |
File renamed without changes.