Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use espower-typescript on non-testing code #73

Open
qsona opened this issue Jan 26, 2021 · 4 comments
Open

Use espower-typescript on non-testing code #73

qsona opened this issue Jan 26, 2021 · 4 comments

Comments

@qsona
Copy link

qsona commented Jan 26, 2021

Hello,

I'd like to use power-assert on non-testing code (I mean it's normal server-side code) of TypeScript + Node.js. I couldn't find a proper way to do that (an example included in README of this project is using mocha) and am also very newbie about power-assert technology, so I randomly tried by myself and found a way.

Could you please review it? I'd like to contribute by creating a good example or adding usage to README so that other people who have same purpose can easily use this library.

Here's the example (somewhat working but maybe not ideal). Is it an intended or acceptable way?

https://github.com/qsona/power-assert-typescript-node-seed/pull/1/files

  • running code with ts-node --require tsnodeconfig.ts
  • run require('espower-typescript') and call it with pattern option in tsnodeconfig.ts
@twada
Copy link
Member

twada commented Jan 27, 2021

@qsona Thank you and it looks good to me. Would you contribute to us?

@teppeis
Copy link
Contributor

teppeis commented Jan 27, 2021

@qsona At first glance, it looks like working, but internally, ts-node has been registered twice.
Because espower-typescript registers ts-node internally.

tsNodeRegister(tsNodeOptions);

TypeScript compiles one file twice, but in the second compilation, it does not change the JS code, so it looks like working as a result.

  1. TS source -> JS source
  2. JS source -> JS source (no changes in your sample code)

I do not know if it will not cause some problems when compiled multiple times in other cases.
So I think it's better to bootstrap with node instead of ts-node.

$ cp tsnodeconfig.ts tsnodeconfig.js
$ node --require ./tsnodeconfig.js src/index.ts

@teppeis
Copy link
Contributor

teppeis commented Jan 27, 2021

If you want to bootstrap with your own ts-node like #66, you can add an option to not register the ts-node inside espower-typescript. PR welcome.

@twada
Copy link
Member

twada commented Jan 27, 2021

@teppeis Oh thank you for your clarification!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants