caolan / caolan/nodeunit

Incomplete tests/setups/teardowns with RequireJS

オープン
#206 コメント 11 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
1.9k
フォーク
359
PR マージ指標
30日以内にマージされた PR はありません

説明

Here is my test (using grunt-contrib-nodeunit):

```
var requirejs = require('requirejs');

exports.test = function(test){
test.expect(1);
requirejs(['dist/test-hts'],function(obj){
test.ok(true, 'hello');
test.done();
});
};
```

For some reason, this doesn't work! It appears as though RequireJS doesn't play nice with node unit. I've been trying to get testing working for the better part of 3 days with no luck so far, even on the most simple of tests like above!

This happens when I run with vanilla nodeunit from the command line:

```
test.js

FAILURES: Undone tests (or their setups/teardowns):
- test

To fix this, make sure all tests call test.done()
```

If I move the `.done()` to the outside of the callback, it just skips the test all together and says that it expected 1 assertion but found none.

I have also tried it this way:

```
var requirejs = require('requirejs');
requirejs.config({
nodeRequire: require,
baseUrl: __dirname
});

requirejs(['../dist/test-hts'],function(obj){
console.log('loaded...');
exports.test = function(test){
test.expect(1);
test.ok(true, 'hello');
test.done();
};
});
```

It results in:

```
OK: 0 assertions (41ms)
```

Also, if I run this same file using node rather than nodeunit (just to check execution), I get the following output:

```
loaded...
```

So I know that the module is loading properly, just not with nodeunit!

Any help here would be great. I don't understand why nodeunit wouldn't work with such a well-known AMD tool like RequireJS. Thanks!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず、vanilla nodeunit と grunt-contrib-nodeunit のセットアップを使って、提供された test.js を再現します。RequireJS のコールバックが dist/test-hts を読み込む間に、nodeunit がどのようにテストを検出し、test.done() を処理するかを追跡します。例が未完了テストのエラーなしに完了し、期待されるアサーションを記録すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
testing-qa
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。