1. espower-typescript
power-assert instrumentor for TypeScript
espower-typescript
Package: espower-typescript
Created by: power-assert-js
Last modified: Mon, 01 Aug 2022 16:18:51 GMT
Version: 10.0.1
License: MIT
Downloads: 19,749
Repository: https://github.com/power-assert-js/espower-typescript

Install

npm install espower-typescript
yarn add espower-typescript

espower-typescript

power-assert instrumentor for TypeScript

npm version
Node.js Version Support
TypeScript Version Support
build status
Dependency Status
monthly downloads
License

TypeScript versions

espower-typescript v10.x is compatible with TypeScript v2.7+

Usage (zero-config mode)

Install

 $ npm install -D espower-typescript power-assert mocha typescript @types/node @types/mocha

Create a test file (intensionally failed)

 // test/test.ts
import assert = require('assert');

describe('Array#join', () => {
  it('joins all elements into a string with separator', () => {
    assert(['a', 'b', 'c'].join(':') === 'a:b:c:');
  });
});

Run test

 $ ./node_modules/.bin/mocha --require espower-typescript/guess "test/**/*.ts"

Output

  1) Array#join
       joins all elements into a string with separator:

      AssertionError [ERR_ASSERTION]:   # test.ts:6

  assert(['a','b','c'].join(':') === 'a:b:c:')
         |             |         |
         ["a","b","c"] "a:b:c"   false

CAUTION: don't use import assert from 'assert'

Just use old style import assert = require('assert') for assert module.
This is limitation.

Configure

If your tests are not in test directory

You can set test directory in your package.json

 {
    "name": "your-module",
    "description": "Your module",
    "version": "0.0.1",
    "directories": {
        "test": "spec/"
    },
...
}

Then, run mocha with --require espower-typescript/guess

 $ ./node_modules/.bin/mocha --require espower-typescript/guess "spec/**/*.ts"

Note: 'espower-typescript/guess' is inspired by intelli-espower-loader

ts-node and tsconfig.json

espower-typescript uses ts-node internally.
It loads your tsconfig.json automatically.

Disable type check (transpile only)

Use TS_NODE_TRANSPILE_ONLY env of ts-node

 $ TS_NODE_TRANSPILE_ONLY=1 ./node_modules/.bin/mocha --require espower-typescript/guess "test/**/*.ts"

JSX/React

.tsx files are supported.

allowJs

If allowJs: true in your tsconfig.json, assertions in test/**/*.(js|jsx) are empowered.

License

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin