Best strategy for Typescript with Electron?


#1

I want to migrate everything in Electron to using Typescript.

All renderer code, all main code, and also mocha tests and spectron e2e tests.

So far I’ve written a webpack that works well so I have a proof of concept working.

The main problem I have now is unit testing and spectron and making it work well in my IDE.

My thinking was to have webpack auto-generate a -bundle for each test unit, then run these units via mocha.

That works but it’s a real pain having so many -bundle files all over my disk.

mocha-webpack kind of works there so it’s not the end of the world but it’s not perfect either.

Then spectron magnifies the problem because there are three javascript files I have to webpack there.

What about babel-register? It’s not webpack but it might be easier to work with.

Thoughts?


#2

I’m not sure why you would want to write your Mocha tests in TypeScript as well, but have you considered using ts-node to run your test script?


#3

The same reason I want to write Typescript elsewhere… type safety and all the benefits of typescript.


#4

I know one project that uses Mocha tests in TypeScript, maybe you can learn a thing or two from its setup


#5

I’m using TypeScript in Electron successfully with ts-node, except for when I load a program inside of a <webview> element (GitHub issue). Otherwise, using new BrowserWindow seems to work just fine: the entry point will set up ts-node, then the entry point can import the first TypeScript file.