diff --git a/test_module/__test__/object.spec.ts b/test_module/__test__/object.spec.ts index 865113e5..2cce191f 100644 --- a/test_module/__test__/object.spec.ts +++ b/test_module/__test__/object.spec.ts @@ -236,7 +236,7 @@ test('is promise', (t) => { t.true(bindings.testIsPromise(Promise.reject().catch(() => {}))) t.true( bindings.testIsPromise( - new Promise((resolve) => { + new Promise((resolve) => { resolve() }), ), diff --git a/test_module/__test__/serde/ser.spec.ts b/test_module/__test__/serde/ser.spec.ts index 24d46fa0..e71c1a8b 100644 --- a/test_module/__test__/serde/ser.spec.ts +++ b/test_module/__test__/serde/ser.spec.ts @@ -12,6 +12,7 @@ const testFunc = [ 'make_buff', 'make_obj', 'make_map', + 'make_bytes_struct', ] if (napiVersion >= 6) { @@ -24,3 +25,10 @@ for (const func of testFunc) { t.snapshot(bindings[func]()) }) } + +test('serialize make_bytes_struct', (t) => { + t.deepEqual(bindings.make_bytes_struct(), { + code: Buffer.from([0, 1, 2, 3]), + map: 'source map', + }) +}) diff --git a/test_module/__test__/serde/ser.spec.ts.md b/test_module/__test__/serde/ser.spec.ts.md index 4c389086..1b511474 100644 --- a/test_module/__test__/serde/ser.spec.ts.md +++ b/test_module/__test__/serde/ser.spec.ts.md @@ -72,6 +72,17 @@ Generated by [AVA](https://avajs.dev). c: 3, } +## serialize make_bytes_struct from bindings + +> Snapshot 1 + + { + code: Buffer @Uint8Array [ + 00010203 + ], + map: 'source map', + } + ## serialize make_object from bindings > Snapshot 1 diff --git a/test_module/__test__/serde/ser.spec.ts.snap b/test_module/__test__/serde/ser.spec.ts.snap index 4bba6d53..66afca61 100644 Binary files a/test_module/__test__/serde/ser.spec.ts.snap and b/test_module/__test__/serde/ser.spec.ts.snap differ diff --git a/test_module/src/serde.rs b/test_module/src/serde.rs index 5ef08954..a6b4e13b 100644 --- a/test_module/src/serde.rs +++ b/test_module/src/serde.rs @@ -44,6 +44,13 @@ struct AnObjectTwo { r: i128, } +#[derive(Serialize, Debug, Deserialize)] +struct BytesObject<'a> { + #[serde(with = "serde_bytes")] + code: &'a [u8], + map: String, +} + macro_rules! make_test { ($name:ident, $val:expr) => { #[js_function] @@ -104,6 +111,13 @@ const NUMBER_BYTES: &[u8] = &[255u8, 254, 253]; make_test!(make_buff, { serde_bytes::Bytes::new(NUMBER_BYTES) }); +make_test!(make_bytes_struct, { + BytesObject { + code: &[0, 1, 2, 3], + map: "source map".to_owned(), + } +}); + macro_rules! make_expect { ($name:ident, $val:expr, $val_type:ty) => { #[js_function(1)] @@ -189,6 +203,7 @@ pub fn register_js(exports: &mut JsObject) -> Result<()> { exports.create_named_method("make_obj", make_obj)?; exports.create_named_method("make_object", make_object)?; exports.create_named_method("make_map", make_map)?; + exports.create_named_method("make_bytes_struct", make_bytes_struct)?; exports.create_named_method("expect_hello_world", expect_hello_world)?; exports.create_named_method("expect_obj", expect_obj)?;