Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit 4c26736

Browse files
committed
Merge pull request #285 from douglasduteil/test-remove-setTimeout-functions
test: remove setTimout functions
2 parents 669c504 + e86ac1e commit 4c26736

File tree

2 files changed

+210
-232
lines changed

2 files changed

+210
-232
lines changed

test/custom-loader.spec.js

Lines changed: 46 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,105 +8,92 @@ describe('Custom Loader', function () {
88
it('should support ES6 scripts', function (done) {
99
customLoader.import('test/loader/test')
1010
.then(function (m) {
11-
setTimeout(function () {
12-
expect(m.loader).to.be.equal('custom');
13-
done();
14-
});
15-
}, done)
11+
expect(m.loader).to.be.equal('custom');
12+
})
13+
.then(done, done)
1614
});
1715

1816
it('should support AMD scripts', function (done) {
1917
customLoader.import('test/loader/amd')
2018
.then(function (m) {
21-
setTimeout(function () {
22-
expect(m.format).to.be.equal('amd');
23-
done();
24-
});
25-
}, done)
19+
expect(m.format).to.be.equal('amd');
20+
})
21+
.then(done, done);
2622
});
2723
});
2824

29-
describe('special #locate path rule', function () {
25+
describe('special #locate path rule', function a() {
3026

3127
it('should support special loading rules', function (done) {
3228
customLoader.import('path/custom')
3329
.then(function (m) {
34-
setTimeout(function () {
35-
expect(m.path).to.be.ok();
36-
done();
37-
});
38-
}, done)
39-
});
30+
expect(m.path).to.be.ok();
31+
})
32+
.then(done, done);
33+
})
4034

4135
});
4236

4337
describe('errors', function () {
4438

45-
function dummyLoad(file, cb) {
46-
System.import(file)
47-
.then(function () {
48-
setTimeout(function () {
49-
expect(false, 'should not be successful').to.be.ok();
50-
cb();
51-
});
52-
})
53-
.catch(function (e) {
54-
setTimeout(function () {
55-
cb(e);
56-
});
57-
})
58-
;
39+
function supposeToFail() {
40+
expect(false, 'should not be successful').to.be.ok();
5941
}
6042

6143
it('should make the normalize throw', function (done) {
62-
dummyLoad('test/loader/error1-parent', function (e) {
63-
expect(e).to.be.match(/Error loading "error1" at \S+error1\.js\nError loading "error1" from "test\/loader\/error1-parent"/);
64-
done();
65-
});
44+
customLoader.import('test/loader/error1-parent')
45+
.then(supposeToFail, function (e) {
46+
expect(e).to.be.match(/Error loading "test\/loader\/error1-parent" at \S+error1-parent\.js/);
47+
})
48+
.then(done, done);
6649
});
6750

6851
it('should make the locate throw', function (done) {
69-
dummyLoad('test/loader/error2', function (e) {
70-
expect(e).to.be.match(/Error loading "test\/loader\/error2" at \S+test\/loader\/error2\.js/);
71-
done();
72-
});
52+
customLoader.import('test/loader/error2')
53+
.then(supposeToFail, function (e) {
54+
expect(e).to.be.match(/Error loading "test\/loader\/error2" at \S+test\/loader\/error2\.js/);
55+
})
56+
.then(done, done);
7357
});
7458

7559
it('should make the fetch throw', function (done) {
76-
dummyLoad('test/loader/error3', function (e) {
77-
expect(e).to.be.match(/Error loading "test\/loader\/error3" at \S+test\/loader\/error3\.js/);
78-
done();
79-
});
60+
customLoader.import('test/loader/error3')
61+
.then(supposeToFail, function (e) {
62+
expect(e).to.be.match(/Error loading "test\/loader\/error3" at \S+test\/loader\/error3\.js/);
63+
})
64+
.then(done, done);
8065
});
8166

8267
it('should make the translate throw', function (done) {
83-
dummyLoad('test/loader/error4', function (e) {
84-
expect(e).to.be.match(/Error loading "test\/loader\/error4" at \S+test\/loader\/error4\.js/);
85-
done();
86-
});
68+
customLoader.import('test/loader/error4')
69+
.then(supposeToFail, function (e) {
70+
expect(e).to.be.match(/Error loading "test\/loader\/error4" at \S+test\/loader\/error4\.js/);
71+
})
72+
.then(done, done);
8773
});
8874

8975
it('should make the instantiate throw', function (done) {
90-
dummyLoad('test/loader/error5', function (e) {
91-
expect(e).to.be.match(/Error loading "test\/loader\/error5" at \S+test\/loader\/error5\.js/);
92-
done();
93-
});
76+
customLoader.import('test/loader/error5')
77+
.then(supposeToFail, function (e) {
78+
expect(e).to.be.match(/Error loading "test\/loader\/error5" at \S+test\/loader\/error5\.js/);
79+
})
80+
.then(done, done);
9481
});
82+
9583
});
9684

9785
});
9886

9987
describe('#normalize', function () {
10088
it('should support async normalization', function (done) {
101-
customLoader.normalize('asdfasdf').then(function (normalized) {
102-
return customLoader.import(normalized)
103-
}).then(function (m) {
104-
setTimeout(function () {
89+
customLoader.normalize('asdfasdf')
90+
.then(function (normalized) {
91+
return customLoader.import(normalized);
92+
})
93+
.then(function (m) {
10594
expect(m.n).to.be.equal('n');
106-
done();
107-
});
108-
})
109-
.catch(done);
95+
})
96+
.then(done, done);
11097
});
11198
});
11299
});

0 commit comments

Comments
 (0)