iamturns.com | My personal website powered by Gatsby | Blog library
kandi X-RAY | iamturns.com Summary
kandi X-RAY | iamturns.com Summary
This is the code that powers my personal blog.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- schema - article object
- Sets up the content - image attributes of the content - image tag .
- Create an organization organization .
- Set the Content Headers
- Apply style to the image .
- Get pages from a graphql query .
- Create a schema author author
- Calculate the slug of a node .
- Create a new page from a node
- Creates an Image object .
iamturns.com Key Features
iamturns.com Examples and Code Snippets
Community Discussions
Trending Discussions on iamturns.com
QUESTION
tldr; I want to convert my JS project to TS one file at a time while being able to run Mocha tests without a build step.
I utilize a lot of Babel transforms (class props, jsx, ...) in my current javascript code, which Mocha handles at run-time by registering the babel loader (basically mocha --require @babel/register
). This means running a single test is fast and requires no build step for the entire project.
I followed a guide on getting started with TypeScript using the (relatively) new babel plugin from Microsoft: @babel/preset-typescript
. This worked fine for the basic case: converting app.js to app.ts.
What it didn't cover was how to do a step-wise transition. For me, fixing 3978 typescript errors (actual count after doing the
) is a bit overwhelming and would stall development for two weeks. Just getting my 200 LOC helpers lib to compile nicely with the definitions from find
...react-redux
took well over an hour.
While doing git mv app.{j,t}s
worked fine, doing it to any other file was a disaster. Existing Mocha tests quickly crashed on being unable to find the right files, even when registering Babel and adding suitable extensions:
mocha --extension js,jsx,ts,tsx --require @babel/register
Typically if doing git mv Logger.{j,t}s
I'd get Error: Cannot find module './lib/logging/Logger'
.
Is there a way of getting Mocha's module loader to recognize typescript files and transparently run them through Babel?
...ANSWER
Answered 2019-Nov-13 at 17:19Here is how I got this working in our mixed javascript/typescript frankenstein codebase. mocha just transpiles the code before it executes our tests. This makes it happen all in a single step instead of two separate steps. This is my config below. You could replace mocha opts with just adding these as cli flags.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install iamturns.com
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page