Posts

Showing posts from March, 2022

set up jest for your typescript project and how to import txt files in your unit tests

Image
  Getting Started These instructions will get you setup to use  ts-jest  in your project. For more detailed documentation, please check  online documentation . using npm using yarn Prerequisites npm i -D jest typescript yarn add --dev jest typescript Installing npm i -D ts-jest @types/jest yarn add --dev ts-jest @types/jest Creating config npx ts-jest config:init yarn ts-jest config:init Running tests npm t  or  npx jest yarn test  or  yarn jest to import txt file as string, via jest-raw-loader /** @type { import('ts-jest/dist/types').InitialOptionsTsJest } */ module . exports = { preset : ' ts-jest ' , testEnvironment : ' node ' , " transform " : { " \\ .txt$ " : " jest-raw-loader " } }; or follow https://nextjs.org/docs/testing if you are using next.js https://www.npmjs.com/package/jest-raw-loader https://github.com/kulshekhar/ts-jest https://jestjs.io/zh-Hans/docs/getting-started https://jestjs.io/docs/configu

Import txt files as string into your next.js App

Image
 import file from './xxx.txt' Webpack 5 has 'Asset Modules' to allow you to import assets without configuring loaders now. Next.js use Webpack 5 internally, so we can use 'source assets' to import txt files as strings. Two steps to let you be able to import a txt file as a string. custom Webpack config for next.js config . module . rules . push ({ test : / \. txt $ / i , type : ' asset/source ' }) declare txt as a module for typescript Wildcard module declarations can be used to cover these cases. declare module ' *.txt ' { const content : string ; export default content ; } example import t1 from ' ./1.txt ' console . log ( t1 ) output event - compiled successfully 离开罪之路的人蒙祝福, 他不去随从恶人的计谋, 他不会站在罪人的道路上, 也不去坐好讥笑人的座位, 他喜爱的是耶和华律法, 昼夜默诵的也是他律法。 The full commit to enabling import txt files in your next.js app references

How to Use SODA for REST with OAuth Client Credentials in your Node.js/Web App to CRUD Oracle Autonomous Database?

Image
Use SODA for REST with OAuth Client Credentials in your Node.js or Web application to CRUD Oracle Autonomous Database