LoginSignup
1
0

More than 5 years have passed since last update.

typescript + karma + mocha + power-assert + browserify メモ

Last updated at Posted at 2016-01-10

なんか選択肢がたくさんあって壮大にハマったのでメモしておきます。
完成形はこれ

TL;DR

結論としてbrowserifyでいく場合は
karma-browserify + tsify + espowerify
でいくのがいいのではと。

karma.conf.jsはこんな感じで書きました。

module.exports = function(config) {
  config.set({
    basePath: '',

    frameworks: ['mocha', 'browserify'],

    files: [
      'test/**/*.ts'
    ],

    exclude: [
    ],

    preprocessors: {
      '**/*.ts': ['browserify']
    },

    browserify: {
      debug: true,
      plugin: [ 'tsify' ],
      transform: ['espowerify'],
      extensions: ['.ts', '.js']
    },

    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    singleRun: false,
    concurrency: Infinity
  })
}

あと現在は以下の記事の対応しないとpower-assertの詳細情報がでません。
泣きそうになってたので大変助かりました。
http://qiita.com/wadahiro/items/5d8a81252f2105112339

これ以下は雑なメモです。

雑なメモ

とりあえずnpm initしとく

$ npm init

ライブラリ

$ npm i karma typescript power-assert karma-browserify tsify espowerify -D

karma設定

$ npm install -g karma-cli
$ karma init
Which testing framework do you want to use ?
Press tab to list possible options. Enter to move to the next question.
> mocha

Do you want to use Require.js ?
This will add Require.js plugin.
Press tab to list possible options. Enter to move to the next question.
> no

Do you want to capture any browsers automatically ?
Press tab to list possible options. Enter empty string to move to the next question.
> PhantomJS
> 

What is the location of your source and test files ?
You can use glob patterns, eg. "js/*.js" or "test/**/*Spec.js".
Enter empty string to move to the next question.
> 

Should any of the files included by the previous patterns be excluded ?
You can use glob patterns, eg. "**/*.swp".
Enter empty string to move to the next question.
> 

Do you want Karma to watch all the files and run the tests on change ?
Press tab to list possible options.
> yes

tsconfig.jsonの生成

$ tsc --init 

編集してこんな感じに

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": true
    },
    "exclude": [
        "node_modules"
    ]
}

型定義ファイル

$ tsd init
$ tsd install mocha power-assert --save
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0