espower-typescript

power-assert instrumentor for TypeScript

MIT 31 个版本
安装
npm install espower-typescript
yarn add espower-typescript
pnpm add espower-typescript
bun add espower-typescript
README

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

版本列表
10.0.1 2022-08-01
10.0.0 2021-01-28
9.0.2 2019-03-19
9.0.1 2018-09-09
9.0.0-beta.0 2018-06-24
9.0.0 2018-06-24
8.1.4 2018-06-24
8.1.3 2018-02-01
8.1.2 2017-10-31
8.1.1-rc.0 2017-08-18
8.1.1 2017-09-01
8.1.0 2017-08-07
8.0.2 2017-07-02
8.0.1 2017-07-02
8.0.0 2017-02-23
7.0.1 2017-02-23
7.0.0 2016-12-11
6.1.0 2016-12-11
6.0.2 2016-12-11
6.0.1 2016-10-24
6.0.0 2016-10-24
5.0.1 2016-02-28
5.0.0 2016-02-24
4.1.0 2016-02-18
4.0.1 2016-02-16
4.0.0 2016-02-03
3.0.0 2015-11-07
2.0.0 2015-11-05
1.0.0 2015-08-10
0.1.1 2015-06-18
0.1.0 2015-05-11