How to resolve Node.js ES6 (ESM) Modules with the TypeScript Compiler (TSC). TSC doesn’t emit the correct file-ext

This is a confusing design choice in TypeScript. In the short term you can work around it by specifying the output file: in main.ts specify the .js extension and path: import { testText } from ‘./module1.js’; alert(testText); This will pick up module.ts correctly, but output with the .js extension included. Note that you also need … Read more

Relationship between event loop,libuv and v8 engine

The event loop is, first and foremost, a high-level concept that’s a fundamental part of the JavaScript programming model. Practically, every V8 embedder needs to implement an event loop. V8 provides a default implementation, which embedders can replace or extend. I don’t understand the question. (I guess the answer is “yes”, but what’s the difference … Read more

Jest mocking: TypeError: axios.get.mockResolvedValue is not a function

Jest has clearly addressed how to mock a module in this link https://jestjs.io/docs/en/manual-mocks#mocking-node-modules. It has an important note as following: Note: In order to mock properly, Jest needs jest.mock(‘moduleName’) to be in the same scope as the require/import statement. On the other hand, Most of use cases jest.mock is supposed to be called at the … Read more

Can I somehow build webassembly code *without* the emscripten “glue”?

You can use emscripten to generate fairly minimal code output. Consider the following trivial file adder.c: int adder (int a, int b) { return a + b; } Compile it like this (requires a fairly recent emscripten): emcc -O2 -s WASM=1 -s SIDE_MODULE=1 -o adder.wasm To see what it generated, disassemble it to wast textual … Read more

What is exactly the importLoaders option of css-loader in Webpack 4?

After more searching it turned out that I’m not the only one confused about how to use this option correctly. Issues from the GitHub repo of css-loader: https://github.com/webpack-contrib/css-loader/issues/765 Also see @guidobouman excellent explanation here: https://github.com/webpack-contrib/css-loader/issues/228#issuecomment-312885975 So this answers my question (quoted literally): importLoaders only has effect on unresolved @imports. So when using postCSS with nextCSS … Read more

Jest – Mock a constant property from a module for a specific test

File that exports a constant value that I want to mock: // utils/deviceTypeUtils file import DeviceInfo from ‘react-native-device-info’; export const isTablet = DeviceInfo.isTablet(); In my test file, I use this code to mock the constant isTablet: // file: deviceTypeUtils.spec const DeviceTypeUtilsMock = jest.requireMock(‘../utils/deviceTypeUtils’); jest.mock(‘../utils/deviceTypeUtils’, () => ({ isTablet: false, })); describe(‘mock const example’, () => … Read more

Property ‘innerText’ does not exist on type ‘Element’

You can fix it like this: const data = await page.$eval(selector, node => (node as HTMLElement).innerText); or: const data = await page.$eval(selector, node => (<HTMLElement>node).innerText); UPDATE: So, after some exchange on Github, it’s clear why the syntax from this question does not work. It actually defines anonymous generic function. <HTMLElement>(node: HTMLElement) => node.innerText Clearer example … Read more