caolan / caolan/nodeunit

Incomplete tests/setups/teardowns with RequireJS

Đang mở
#206 11 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
1.9k
Fork
359
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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!

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện test.js được cung cấp với vanilla nodeunit và cấu hình grunt-contrib-nodeunit. Theo dõi cách nodeunit phát hiện test và xử lý test.done() trong khi callback của RequireJS tải dist/test-hts. Được xem là hoàn tất khi ví dụ chạy xong mà không có lỗi do test chưa hoàn tất và ghi nhận assertion mong đợi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
testing-qa
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.