Skip to content

Commit 83f3a28

Browse files
committed
Fix tests
1 parent dfc8efc commit 83f3a28

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = (url, size, opts) => {
6767
return;
6868
}
6969

70-
if (/^WARN: /.test(data)) {
70+
if (data.startsWith('WARN: ')) {
7171
stream.emit('warning', data.replace(/^WARN: /, ''));
7272
stream.emit('warn', data.replace(/^WARN: /, '')); // TODO: deprecate this event in v5
7373
return;

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"esnext": false,
6060
"rules": {
6161
"import/no-extraneous-dependencies": 0,
62-
"import/no-unresolved": 0
62+
"import/no-unresolved": 0,
63+
"no-multi-assign": 0
6364
}
6465
}
6566
]

test.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ test('hide elements using the `hide` option', async t => {
4747
const fixture = path.join(__dirname, 'fixtures', 'test-hide-element.html');
4848
const stream = screenshotStream(fixture, '100x100', {hide: ['div']});
4949
const png = new PNG(await getStream.buffer(stream));
50-
png.decode(pixels => t.is(pixels[0], 255));
50+
const pixels = await rfpify(png.decode.bind(png))();
51+
t.is(pixels[0], 255);
5152
});
5253

5354
test('ignore multiline page errors', async t => {
@@ -93,7 +94,7 @@ test('have a `format` option', async t => {
9394
test('have a `css` option', async t => {
9495
const stream = screenshotStream('http://yeoman.io', '1024x768', {css: '.mobile-bar { background-color: red !important; }'});
9596
const png = new PNG(await getStream.buffer(stream));
96-
const pixels = await rfpify(png.decode.bind(png), Promise)();
97+
const pixels = await rfpify(png.decode.bind(png))();
9798
t.is(pixels[0], 255);
9899
t.is(pixels[1], 0);
99100
t.is(pixels[2], 0);
@@ -102,7 +103,7 @@ test('have a `css` option', async t => {
102103
test('have a `css` file', async t => {
103104
const stream = screenshotStream('http://yeoman.io', '1024x768', {css: 'fixtures/style.css'});
104105
const png = new PNG(await getStream.buffer(stream));
105-
const pixels = await rfpify(png.decode.bind(png), Promise)();
106+
const pixels = await rfpify(png.decode.bind(png))();
106107
t.is(pixels[0], 0);
107108
t.is(pixels[1], 128);
108109
t.is(pixels[2], 0);
@@ -111,7 +112,7 @@ test('have a `css` file', async t => {
111112
test('have a `script` option', async t => {
112113
const stream = screenshotStream('http://yeoman.io', '1024x768', {script: 'document.querySelector(\'.mobile-bar\').style.backgroundColor = \'red\';'});
113114
const png = new PNG(await getStream.buffer(stream));
114-
const pixels = await rfpify(png.decode.bind(png), Promise)();
115+
const pixels = await rfpify(png.decode.bind(png))();
115116
t.is(pixels[0], 255);
116117
t.is(pixels[1], 0);
117118
t.is(pixels[2], 0);
@@ -120,7 +121,7 @@ test('have a `script` option', async t => {
120121
test('have a `js` file', async t => {
121122
const stream = screenshotStream('http://yeoman.io', '1024x768', {script: 'fixtures/script.js'});
122123
const png = new PNG(await getStream.buffer(stream));
123-
const pixels = await rfpify(png.decode.bind(png), Promise)();
124+
const pixels = await rfpify(png.decode.bind(png))();
124125
t.is(pixels[0], 0);
125126
t.is(pixels[1], 128);
126127
t.is(pixels[2], 0);
@@ -133,7 +134,7 @@ test('send cookie', async t => {
133134
});
134135

135136
const png = new PNG(await getStream.buffer(stream));
136-
const pixels = await rfpify(png.decode.bind(png), Promise)();
137+
const pixels = await rfpify(png.decode.bind(png))();
137138

138139
t.is(pixels[0], 0);
139140
await s.close();
@@ -150,7 +151,7 @@ test('send cookie using an object', async t => {
150151
});
151152

152153
const png = new PNG(await getStream.buffer(stream));
153-
const pixels = await rfpify(png.decode.bind(png), Promise)();
154+
const pixels = await rfpify(png.decode.bind(png))();
154155

155156
t.is(pixels[0], 0);
156157
await s.close();
@@ -165,15 +166,15 @@ test('send headers', async t => {
165166
}
166167
});
167168

168-
t.is((await rfpify(s.once.bind(s), Promise)('/')).headers.foobar, 'unicorn');
169+
t.is((await rfpify(s.once.bind(s))('/')).headers.foobar, 'unicorn');
169170
await s.close();
170171
});
171172

172173
test('handle redirects', async t => {
173174
const s = await server();
174175
const stream = screenshotStream(`${s.url}/redirect`, '100x100');
175176
const png = new PNG(await getStream.buffer(stream));
176-
const pixels = await rfpify(png.decode.bind(png), Promise)();
177+
const pixels = await rfpify(png.decode.bind(png))();
177178
t.is(pixels[0], 0);
178179
await s.close();
179180
});
@@ -183,7 +184,7 @@ test('resource timeout', async t => {
183184
const stream = screenshotStream(s.url, '100x100', {timeout: 1});
184185

185186
await Promise.race([
186-
rfpify(s.once.bind(s), Promise)('/').then(() => t.fail('Expected resource timed out error')),
187+
rfpify(s.once.bind(s))('/').then(() => t.fail('Expected resource timed out error')),
187188
t.throws(getStream(stream), `Resource timed out #1 (Network timeout on resource.) → ${s.url}/`)
188189
]);
189190

0 commit comments

Comments
 (0)