File tree Expand file tree Collapse file tree
src/Cardano/Wasm/Internal/Api
test/cardano-wasm-golden/Test/Golden/Cardano/Wasm Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,26 @@ module Main where
22
33import Cardano.Wasm.Internal.Api.Info (apiInfo )
44import Cardano.Wasm.Internal.Api.InfoToTypeScript (apiInfoToTypeScriptFile )
5- import Cardano.Wasm.Internal.Api.TypeScriptDefs (printTypeScriptFile )
5+ import Cardano.Wasm.Internal.Api.TypeScriptDefs (writeTypeScriptToDir )
6+
7+ import Options.Applicative
8+
9+ newtype CmdArgs
10+ = CmdArgs { outputDir :: String }
11+
12+ parser :: Parser CmdArgs
13+ parser =
14+ CmdArgs
15+ <$> strOption
16+ ( mconcat
17+ [ long " output-dir"
18+ , short ' o'
19+ , metavar " OUTPUT_DIR"
20+ , help " Output directory for the TypeScript declaration files (it must exist)"
21+ ]
22+ )
623
724main :: IO ()
8- main = printTypeScriptFile (apiInfoToTypeScriptFile apiInfo)
25+ main = do
26+ cmdArgs <- execParser (info (parser <**> helper) fullDesc)
27+ writeTypeScriptToDir (outputDir cmdArgs) (apiInfoToTypeScriptFile apiInfo)
Original file line number Diff line number Diff line change @@ -63,7 +63,9 @@ executable cardano-wasm
6363 cardano-strict-containers,
6464 containers,
6565 exceptions,
66+ filepath,
6667 microlens,
68+ optparse-applicative,
6769 text,
6870
6971 if arch(wasm32)
@@ -80,6 +82,7 @@ test-suite cardano-wasm-golden
8082 if !arch(wasm32)
8183 import : project-config
8284 build-depends :
85+ filepath,
8386 hedgehog >= 1.1 ,
8487 hedgehog-extras ^>= 0.8 ,
8588 tasty,
Original file line number Diff line number Diff line change @@ -207,4 +207,3 @@ declare interface CardanoApi {
207207 */
208208 restoreTestnetPaymentWalletFromSigningKeyBech32 ( networkMagic : number , signingKeyBech32 : string ) : Promise < Wallet > ;
209209}
210-
Original file line number Diff line number Diff line change @@ -16,12 +16,15 @@ module Cardano.Wasm.Internal.Api.TypeScriptDefs where
1616import Data.List.NonEmpty qualified as LNE
1717import Data.Text.Lazy qualified as TL
1818import Data.Text.Lazy.Builder qualified as TLB
19+ import Data.Text.Lazy.IO qualified as TL
20+ import System.FilePath ((</>) )
1921
20- -- | Prints the TypeScript declaration file to stdout .
21- printTypeScriptFile :: TypeScriptFile -> IO ()
22- printTypeScriptFile tsFile = do
22+ -- | Output the TypeScript declaration files to the specified directory .
23+ writeTypeScriptToDir :: FilePath -> TypeScriptFile -> IO ()
24+ writeTypeScriptToDir dir tsFile = do
2325 let content = buildTypeScriptFile tsFile
24- putStrLn $ TL. unpack $ TLB. toLazyText content
26+ filePath = dir </> typeScriptFileName tsFile
27+ TL. writeFile filePath (TLB. toLazyText content)
2528
2629-- | Creates a builder for a JavaScript-style multiline comment
2730-- with the specified indentation level (in spaces) and each line
Original file line number Diff line number Diff line change 11module Test.Golden.Cardano.Wasm.TypeScript where
22
3+ import Control.Monad (forM_ )
4+ import Control.Monad.IO.Class qualified as H
5+ import System.FilePath ((</>) )
6+
37import Hedgehog as H
8+ import Hedgehog.Extras (workspace )
49import Hedgehog.Extras qualified as H
510
611hprop_cardano_wasm_typescript_declarations_match_generated :: Property
712hprop_cardano_wasm_typescript_declarations_match_generated =
813 H. propertyOnce $ do
9- result <- H. execFlex " cardano-wasm" " CARDANO_WASM" []
10- H. diffVsGoldenFile result " lib-wrapper/cardano-api.d.ts"
14+ workspace " cardano-wasm-ts-decls" $ \ workDir -> do
15+ dir <- H. createDirectoryIfMissing (workDir </> " lib-wrapper" )
16+ _ <- H. execFlex " cardano-wasm" " CARDANO_WASM" [" --output-dir" , dir]
17+ forFilesInDir dir $ \ file -> do
18+ H. annotate (dir </> file)
19+ H. diffFileVsGoldenFile (dir </> file) (" lib-wrapper" </> file)
20+
21+ forFilesInDir :: (H. MonadTest m , H. MonadIO m ) => FilePath -> (FilePath -> m () ) -> m ()
22+ forFilesInDir dir action = do
23+ files <- H. listDirectory dir
24+ forM_ files $ \ file -> do
25+ let fullPath = dir </> file
26+ H. assertFileExists fullPath
27+ action file
You can’t perform that action at this time.
0 commit comments