Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit 990b4d4

Browse files
committed
feat: add feature 'ignoreElements' to 'ScreenShooter'
1 parent a48d0c3 commit 990b4d4

7 files changed

Lines changed: 68 additions & 8 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
var lib = require('./lib');
4+
5+
module.exports = function queryIgnoreAreas(selector) {
6+
return typeof selector === 'string'
7+
? [lib.queryFirst(selector)]
8+
: lib.queryAll(selector.every);
9+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
var lib = require('./lib');
4+
5+
module.exports = function queryIgnoreAreas(selector) {
6+
return lib.queryAll(selector);
7+
};

lib/browser/client-scripts/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
var util = require('./util'),
55
rect = require('./rect'),
66
lib = require('./lib'),
7+
queryIgnoreAreas = require('./ignore-areas'),
78
Rect = rect.Rect;
89

910
if (typeof window === 'undefined') {
@@ -115,9 +116,7 @@ function getCaptureRect(selectors) {
115116
function findIgnoreAreas(selectors) {
116117
var result = [];
117118
util.each(selectors, function(selector) {
118-
var elements = typeof selector === 'string'
119-
? [lib.queryFirst(selector)]
120-
: lib.queryAll(selector.every);
119+
var elements = queryIgnoreAreas(selector);
121120

122121
util.each(elements, addIgnoreArea.bind(result));
123122
});

lib/client-bridge/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ exports.build = (browser, opts = {}) => {
2626
}, 'uglifyify');
2727

2828
const lib = opts.calibration && opts.calibration.needsCompatLib ? './lib.compat.js' : './lib.native.js';
29+
const ignoreAreas = opts.supportDeprecated ? './ignore-areas.deprecated.js' : './ignore-areas.js';
2930

3031
script.transform({
3132
aliases: {
32-
'./lib': {relative: lib}
33+
'./lib': {relative: lib},
34+
'./ignore-areas': {relative: ignoreAreas}
3335
},
3436
verbose: false
3537
}, 'aliasify');

lib/screen-shooter/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ module.exports = class ScreenShooter {
2828
: Promise.reject(e);
2929
}
3030

31+
viewport.ignoreAreas(page.ignoreAreas);
32+
3133
return viewport.crop(page.captureArea);
3234
}
3335

test/lib/client-bridge/index.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,48 @@ describe('clientBridge', () => {
6161
it('should transform client scripts using native library', () => {
6262
return clientBridge.build(null, {calibration: {needsCompatLib: false}})
6363
.then(() => {
64-
assert.calledWith(script.transform, {
64+
assert.calledWith(script.transform, sinon.match({
6565
aliases: {
6666
'./lib': {relative: './lib.native.js'}
6767
},
6868
verbose: false
69-
});
69+
}));
7070
});
7171
});
7272

7373
it('should transform client scripts using compat library', () => {
7474
return clientBridge.build(null, {calibration: {needsCompatLib: true}})
7575
.then(() => {
76-
assert.calledWith(script.transform, {
76+
assert.calledWith(script.transform, sinon.match({
7777
aliases: {
7878
'./lib': {relative: './lib.compat.js'}
7979
},
8080
verbose: false
81-
});
81+
}));
82+
});
83+
});
84+
85+
it('should transform client scripts NOT for deprecated mode', () => {
86+
return clientBridge.build(null, {supportDeprecated: false})
87+
.then(() => {
88+
assert.calledWith(script.transform, sinon.match({
89+
aliases: {
90+
'./ignore-areas': {relative: './ignore-areas.js'}
91+
},
92+
verbose: false
93+
}));
94+
});
95+
});
96+
97+
it('should transform client scripts for deprecated mode', () => {
98+
return clientBridge.build(null, {supportDeprecated: true})
99+
.then(() => {
100+
assert.calledWith(script.transform, sinon.match({
101+
aliases: {
102+
'./ignore-areas': {relative: './ignore-areas.deprecated.js'}
103+
},
104+
verbose: false
105+
}));
82106
});
83107
});
84108

test/lib/screen-shooter/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('screen-shooter', () => {
1010
beforeEach(() => {
1111
sandbox.spy(Viewport, 'create');
1212
sandbox.stub(Viewport.prototype, 'crop');
13+
sandbox.stub(Viewport.prototype, 'ignoreAreas');
1314
sandbox.spy(Viewport.prototype, 'extendBy');
1415
});
1516

@@ -46,6 +47,11 @@ describe('screen-shooter', () => {
4647
.then(() => assert.calledOnceWith(Viewport.prototype.crop, {foo: 'bar'}));
4748
});
4849

50+
it('should clear configured ignore areas', () => {
51+
return capture({ignoreAreas: {foo: 'bar'}})
52+
.then(() => assert.calledWith(Viewport.prototype.ignoreAreas, {foo: 'bar'}));
53+
});
54+
4955
it('should return croped image', () => {
5056
Viewport.prototype.crop.resolves({foo: 'bar'});
5157

@@ -136,6 +142,17 @@ describe('screen-shooter', () => {
136142
return capture(page)
137143
.then(() => assert.calledOnceWith(Viewport.prototype.crop, page.captureArea));
138144
});
145+
146+
it('should clear configured ignore areas', () => {
147+
return capture({ignoreAreas: {foo: 'bar'}})
148+
.then(() => assert.calledWith(Viewport.prototype.ignoreAreas, {foo: 'bar'}));
149+
});
150+
151+
it('should return cropped image', () => {
152+
Viewport.prototype.crop.resolves('foo bar');
153+
154+
return assert.becomes(capture(), 'foo bar');
155+
});
139156
});
140157
});
141158
});

0 commit comments

Comments
 (0)