Skip to content

Commit 4de5407

Browse files
committed
Refactor, fail tests immediatelly, don't run into timeout
1 parent 02c736c commit 4de5407

File tree

3 files changed

+45
-40
lines changed

3 files changed

+45
-40
lines changed

test/.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"beforeEach": true,
1212
"afterEach": true,
1313
"expect": true,
14+
"fail": true,
1415
"spyOn": true,
1516

1617
"require": true,

test/specs/IntegrationSpec.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ describe("Integration test", function () {
4444
expect(result.image).toEqualImage(referenceImg, 2);
4545

4646
expect(canvas).toEqualImage(referenceImg, 2);
47-
// expect(canvas).toImageDiffEqual(referenceImg, 10);
48-
49-
done();
50-
});
47+
}).catch(function (err) {
48+
expect(err).toBe(null);
49+
fail();
50+
}).finally(done);
5151
});
5252
});
5353

@@ -66,10 +66,10 @@ describe("Integration test", function () {
6666
expect(result.image).toEqualImage(referenceImg, 2);
6767

6868
expect(canvas).toEqualImage(referenceImg, 2);
69-
// expect(canvas).toImageDiffEqual(referenceImg, 70);
70-
71-
done();
72-
});
69+
}).catch(function (err) {
70+
expect(err).toBe(null);
71+
fail();
72+
}).finally(done);
7373
});
7474
});
7575

@@ -89,10 +89,10 @@ describe("Integration test", function () {
8989
expect(result.image).toEqualImage(referenceImg, 2);
9090

9191
expect(canvas).toEqualImage(referenceImg, 2);
92-
// expect(canvas).toImageDiffEqual(referenceImg, 90);
93-
94-
done();
95-
});
92+
}).catch(function (err) {
93+
expect(err).toBe(null);
94+
fail();
95+
}).finally(done);
9696
});
9797

9898
ifNotInWebkitIt("should render a URL without canvas", function (done) {
@@ -112,10 +112,10 @@ describe("Integration test", function () {
112112

113113
forceImageSizeForPlatformCompatibility(result.image);
114114
expect(result.image).toEqualImage(referenceImg, 2);
115-
// expect(result.image).toImageDiffEqual(referenceImg, 90);
116-
117-
done();
118-
});
115+
}).catch(function (err) {
116+
expect(err).toBe(null);
117+
fail();
118+
}).finally(done);
119119
});
120120

121121
// This fails in Firefox probably due to https://bugzilla.mozilla.org/show_bug.cgi?id=942138
@@ -129,12 +129,10 @@ describe("Integration test", function () {
129129

130130
// This fails if SpecRunner is opened locally in Firefox. Open over a local webserver helps here.
131131
expect(doc.querySelector('body').innerHTML.trim()).toEqual('这是中文');
132-
133-
done();
134-
}, function (err) {
135-
expect(err).toBe(undefined);
136-
done();
137-
});
132+
}).catch(function (err) {
133+
expect(err).toBe(null);
134+
fail();
135+
}).finally(done);
138136
});
139137

140138
ifNotInWebKitAndNotLocalRunnerIt("should work around Firefox bug with `null` style properties", function (done) {
@@ -151,24 +149,27 @@ describe("Integration test", function () {
151149
.then(function (result) {
152150
forceImageSizeForPlatformCompatibility(result.image);
153151
expect(result.image).toEqualImage(referenceImg, 2);
154-
155-
done();
156-
});
152+
}).catch(function (err) {
153+
expect(err).toBe(null);
154+
fail();
155+
}).finally(done);
157156
});
158157

159158
ifNotInPhantomJsIt("should report a source error on invalid input from HTML", function (done) {
160159
rasterizeHTML.drawHTML("<html><weird:element></html>", {cache: 'none'}).then(null, function (error) {
161160
expect(error.message).toEqual("Invalid source");
162-
163-
done();
164-
});
161+
}).catch(function (err) {
162+
expect(err).toBe(null);
163+
fail();
164+
}).finally(done);
165165
});
166166

167167
ifNotInPhantomJsIt("should report a source error on invalid input from URL", function (done) {
168168
rasterizeHTML.drawURL(testHelper.fixturesPath + "invalidInput.html", {cache: 'none'}).then(null, function (error) {
169169
expect(error.message).toEqual("Invalid source");
170-
171-
done();
172-
});
170+
}).catch(function (err) {
171+
expect(err).toBe(null);
172+
fail();
173+
}).finally(done);
173174
});
174175
});

test/specs/Svg2ImageSpec.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ describe("Svg to Image", function () {
3838
} catch (err) {
3939
expect(err.message).toBeNull();
4040
}
41-
42-
done();
43-
});
41+
}).catch(function (err) {
42+
expect(err).toBe(null);
43+
fail();
44+
}).finally(done);
4445
};
4546
});
4647

@@ -69,9 +70,10 @@ describe("Svg to Image", function () {
6970
} catch (err) {
7071
expect(err).toBeNull();
7172
}
72-
73-
done();
74-
});
73+
}).catch(function (err) {
74+
expect(err).toBe(null);
75+
fail();
76+
}).finally(done);
7577
};
7678
});
7779

@@ -99,9 +101,10 @@ describe("Svg to Image", function () {
99101
svg2image.renderSvg(anSvg, null).then(function (image) {
100102
expect(image.onerror).toBeNull();
101103
expect(image.onload).toBeNull();
102-
103-
done();
104-
});
104+
}).catch(function (err) {
105+
expect(err).toBe(null);
106+
fail();
107+
}).finally(done);
105108
});
106109
});
107110
});

0 commit comments

Comments
 (0)