()
| 8 | |
| 9 | #[test] |
| 10 | fn index() -> io::Result<()> { |
| 11 | let mut collection = TypeCollection::default(); |
| 12 | collection.make_branded::<policies::PolicyId>(); |
| 13 | |
| 14 | let settings = TypeScriptGeneratorSettings::default(); |
| 15 | let mut generator = TypeScriptGenerator::new(&settings, &collection); |
| 16 | |
| 17 | generator.add_import_declaration( |
| 18 | "@blockprotocol/type-system-rs/types", |
| 19 | [ |
| 20 | "ActorId", |
| 21 | "ActorType", |
| 22 | "ActorGroupId", |
| 23 | "BaseUrl", |
| 24 | "EntityUuid", |
| 25 | "OntologyTypeVersion", |
| 26 | "RoleId", |
| 27 | "WebId", |
| 28 | ], |
| 29 | ); |
| 30 | generator.add_import_declaration("@blockprotocol/type-system-rs", ["VersionedUrl"]); |
| 31 | |
| 32 | for (type_id, _, type_definition) in collection.iter() { |
| 33 | if type_definition |
| 34 | .module |
| 35 | .starts_with("hash_graph_authorization") |
| 36 | { |
| 37 | generator.add_type_declaration_by_id(type_id); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | insta::with_settings!({ |
| 42 | description => "Generated TS types", |
| 43 | omit_expression => true, |
| 44 | snapshot_path => "../types", |
| 45 | prepend_module_to_snapshot => false, |
| 46 | }, { |
| 47 | insta::assert_binary_snapshot!( |
| 48 | ".d.ts", |
| 49 | format!("// This file was generated from `{}`\n\n{}", file!(), generator.write()).into_bytes() |
| 50 | ); |
| 51 | }); |
| 52 | |
| 53 | // We require a `.js` file as otherwise `tsc` won't find the `.d.ts` file |
| 54 | let _: fs::File = fs::File::options() |
| 55 | .create(true) |
| 56 | .write(true) |
| 57 | .truncate(true) |
| 58 | .open( |
| 59 | Path::new(env!("CARGO_MANIFEST_DIR")) |
| 60 | .join("types") |
| 61 | .join("index.snap.js"), |
| 62 | )?; |
| 63 | |
| 64 | Ok(()) |
| 65 | } |
nothing calls this directly
no test coverage detected