question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate definitions in test.fsproj?

See original GitHub issue

How to ?

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\src\ts2fable.fsproj" />
    <Compile Include="testCompileTests.fs" />
    <Compile Include="functionTests.fs" />
    <Compile Include="fsFileTests.fs" />
    <Compile Include="test.fs" />
  </ItemGroup>
  <Import Project="..\.paket\Paket.Restore.targets" />
</Project>
module ts2fable.testCompileTests

open Fable.Core
open Fable.Core.JsInterop

open ts2fable.Naming
open TypeScript
open TypeScript.Ts
open Node
open ts2fable.Read
open ts2fable.Write
open ts2fable.Transform
open ts2fable.Print
open System.Collections.Generic
open Node
open ts2fable.Keywords
let [<Global>] describe (msg: string) (f: unit->unit): unit = jsNative
let [<Global>] it (msg: string) (f: unit->unit): unit = jsNative

// use only to debug single test
let [<Emit("it.only($0,$1)")>] only (msg: string) (f: unit->unit): unit = jsNative
let [<Emit("this.timeout($0)")>] timeout (duration: int): unit = jsNative
let inline equal (expected: 'T) (actual: 'T): unit =
    Testing.Assert.AreEqual(expected, actual)

describe "" <| fun _ ->

    timeout 50000
    
    it "test compile tests" <| fun _ ->
        printfn "ts.version: %s" ts.version
        printfn "Node O_RDWR %A" Node.Fs.constants.O_RDWR // read/write should be 2
        printfn "NGHTTP2_STREAM_CLOSED %A" Node.Http2.constants.NGHTTP2_STREAM_CLOSED

        // used by ts2fable
        writeFile ["node_modules/typescript/lib/typescript.d.ts"] "test-compile/TypeScript.fs"
        writeFile ["node_modules/@types/node/index.d.ts"] "test-compile/Node.fs"
        writeFile ["node_modules/@types/yargs/index.d.ts"] "test-compile/Yargs.fs"

        // for test-compile
        writeFile ["node_modules/vscode/vscode.d.ts"] "test-compile/VSCode.fs"
        // writeFile ["node_modules/izitoast/dist/izitoast/izitoast.d.ts"] "test-compile/IziToast.fs"
        writeFile ["node_modules/izitoast/types/index.d.ts"] "test-compile/IziToast.fs"
        writeFile ["node_modules/electron/electron.d.ts"] "test-compile/Electron.fs"
        writeFile ["node_modules/@types/react/index.d.ts"] "test-compile/React.fs"
        writeFile ["node_modules/@types/mocha/index.d.ts"] "test-compile/Mocha.fs"
        writeFile ["node_modules/@types/chai/index.d.ts"] "test-compile/Chai.fs"
        writeFile ["node_modules/chalk/types/index.d.ts"] "test-compile/Chalk.fs"
        writeFile ["node_modules/monaco-editor/monaco.d.ts"] "test-compile/Monaco.fs"
        writeFile
            [   "node_modules/@types/google-protobuf/index.d.ts"
                "node_modules/@types/google-protobuf/google/protobuf/empty_pb.d.ts"
            ]
            "test-compile/Protobuf.fs"

        // files that have too many TODOs
        // writeFile ["node_modules/@types/jquery/index.d.ts"] "test-compile/JQuery.fs"
        // writeFile ["node_modules/typescript/lib/lib.es2015.promise.d.ts"] "test-compile/Promise.fs"

        printfn "done writing test-compile files"    
        equal true true

Why?

  • Easy debugging: Just run WatchTest task you can debug all codes
  • Dotnet build test-compile.fsproj more easily After test compile tests you can run specfic task to build test-compile.fsproj to see if there exists error
  • Isolate yargs cli

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
MangelMaximecommented, Mar 15, 2018

You can tell Fable to choose a free port by passing: --port free

1reaction
MangelMaximecommented, Mar 15, 2018

Oups, I made a typos in my previous message and it changed the meaning ^^What ever.

I agree, we should generate the bindings using the same entry as the end user. So calling, the ts2fable.fs tool via cli should be a good way to go.

We simply need to maintain a list of d.ts and output path:

[ "node_modules/typescript/lib/typescript.d.ts", "TypeScript.fs"
  "another.d.ts", "Output.fs" ]
|> List.map (fun (definitionFile, output) -> (definitionFile, "test-compile/output)
|> List.iter (fun (definitionFile, output) ->
  // Here call the ts2fable.js tool
  // I didn't check the ts2fable synthax so the next line is probably wrong
  ts2fable definitionFile output
)

This looks like something we do on the samples repo or even the fable-import. Like that we only have one entry point and everything is automated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit testing F# in .NET Core with dotnet test and MSTest
Learn unit test concepts for F# in .NET Core through an interactive experience building a sample solution step-by-step using dotnet test and ...
Read more >
TESTGUIDE.md - dotnet/fsharp
To run tests, from a command prompt, use variations such as the following, depending on which test suite and build configuration you want....
Read more >
How to build an F# project via a .fsproj file?
Any hints how to build a stand alone executable file from a F# file? I'm using the following .NET versions: dotnet --info .NET...
Read more >
XUnit with F
A top-level module definition; open statements to import XUnit; Test functions annotated with Fact or Theory. XUnit tests can be broken into 2 ......
Read more >
Creating F# solutions in VSCode from scratch
Put it in tests folder and call it MyForgeExpecto . Change the <TargetFramework> to netcoreapp2.0 in the MyForgeExpecto.fsproj file.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found