Skip to content

Commit 24ed91d

Browse files
committed
Jasmine migration in progress.
1 parent facc34f commit 24ed91d

File tree

6 files changed

+171
-237
lines changed

6 files changed

+171
-237
lines changed

package-lock.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"prebuild-install": "^2.1.1"
4444
},
4545
"devDependencies": {
46+
"jasmine": "^3.0.0",
4647
"prebuild": "v6.1.0",
4748
"tape": "^3.5.0",
4849
"targetpractice": "0.0.7"

test/bitmap.js

+49-84
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,56 @@
1-
var test = require('tape');
21
var robot = require('..');
32

4-
var params =
5-
{
6-
'width': 'number',
7-
'height': 'number',
8-
'byteWidth': 'number',
9-
'bitsPerPixel': 'number',
10-
'bytesPerPixel': 'number',
11-
'image': 'object'
12-
};
13-
14-
test('Get a bitmap.', function(t)
15-
{
16-
t.plan(1);
17-
t.ok(robot.screen.capture(), 'got a bitmap.');
18-
});
19-
20-
test('Get a bitmap and check the parameters.', function(t)
21-
{
22-
t.plan(6);
23-
var img = robot.screen.capture();
24-
25-
for (var x in params)
26-
{
27-
t.equal(typeof img[x], params[x], 'make sure ' + x + ' is a ' + params[x] + '.');
28-
}
29-
});
30-
31-
test('Get a bitmap of a specific size.', function(t)
32-
{
33-
var size = 10;
34-
t.plan(2);
35-
var img = robot.screen.capture(0, 0, size, size);
36-
37-
// Support for higher density screens.
38-
var multi = img.width / size;
39-
var size = size * multi;
40-
t.equals(img.height, size, 'make sure image is expected height.');
41-
t.equals(img.width, size, 'make sure image is expected width.');
42-
});
43-
44-
test('Get a bitmap and make sure the colorAt works as expected.', function(t)
45-
{
46-
t.plan(7);
47-
var img = robot.screen.capture();
48-
var hex = img.colorAt(0, 0);
49-
50-
t.ok(/^[0-9A-F]{6}$/i.test(hex), "colorAt returned valid hex.");
51-
52-
var screenSize = robot.getScreenSize();
53-
var width = screenSize.width;
54-
var height = screenSize.height;
55-
56-
// Support for higher density screens.
57-
var multi = img.width / width;
58-
width = width * multi;
59-
height = height * multi;
60-
61-
t.throws(function()
3+
describe('Bitmap', () => {
4+
var params = {
5+
'width': 'number',
6+
'height': 'number',
7+
'byteWidth': 'number',
8+
'bitsPerPixel': 'number',
9+
'bytesPerPixel': 'number',
10+
'image': 'object'
11+
};
12+
13+
it('Get a bitmap and check the parameters.', function() {
14+
var img = robot.screen.capture();
15+
16+
for (var x in params)
17+
{
18+
expect(typeof img[x]).toEqual(params[x]);
19+
}
20+
});
21+
22+
it('Get a bitmap of a specific size.', function()
6223
{
63-
img.colorAt(0, height);
64-
}, /are outside the bitmap/, 'colorAt (0, screen.height) threw an error.');
24+
var size = 10;
25+
var img = robot.screen.capture(0, 0, size, size);
6526

66-
t.doesNotThrow(function()
67-
{
68-
img.colorAt(0, height-1);
69-
}, /are outside the bitmap/, 'colorAt (0, screen.height-1) did not throw an error.');
70-
71-
t.throws(function()
72-
{
73-
img.colorAt(width, 0);
74-
}, /are outside the bitmap/, 'colorAt (screen.width, 0) threw an error.');
75-
76-
t.doesNotThrow(function()
77-
{
78-
img.colorAt(width-1, 0);
79-
}, /are outside the bitmap/, 'colorAt (screen.width-1, 0) did not throw an error.');
80-
81-
t.throws(function()
82-
{
83-
img.colorAt(9999999999999, 0);
84-
}, /are outside the bitmap/, 'colorAt (9999999999999, 0) threw an error.');
27+
// Support for higher density screens.
28+
var multi = img.width / size;
29+
var size = size * multi;
30+
expect(img.height).toEqual(size);
31+
expect(img.width).toEqual(size);
32+
});
8533

86-
// Regression test for https://github.com/octalmage/robotjs/commit/c41f38217fd73f59e6ca63015b51565cd1e7cfb7
87-
t.throws(function()
34+
it('Get a bitmap and make sure the colorAt works as expected.', function()
8835
{
89-
img.colorAt(0, 9999999999999);
90-
}, /are outside the bitmap/, 'colorAt (0, 9999999999999) threw an error.');
36+
var img = robot.screen.capture();
37+
var hex = img.colorAt(0, 0);
38+
39+
// t.ok(.it(hex), "colorAt returned valid hex.");
40+
expect(hex).toMatch(/^[0-9A-F]{6}$/i);
41+
42+
var screenSize = robot.getScreenSize();
43+
var width = screenSize.width;
44+
var height = screenSize.height;
45+
46+
// Support for higher density screens.
47+
var multi = img.width / width;
48+
width = width * multi;
49+
height = height * multi;
50+
expect(() => img.colorAt(0, height)).toThrowError(/are outside the bitmap/);
51+
expect(() => img.colorAt(0, height-1)).not.toThrow();
52+
expect(() => img.colorAt(width, 0)).toThrowError(/are outside the bitmap/);
53+
expect(() => img.colorAt(9999999999999, 0)).toThrowError(/are outside the bitmap/);
54+
expect(() => img.colorAt(0, 9999999999999)).toThrowError(/are outside the bitmap/);
55+
});
9156
});

test/integration/mouse.js

+53-80
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,82 @@
11
/* jshint esversion: 6 */
2-
var test = require('tape');
32
var robot = require('../..');
43
var targetpractice = require('targetpractice/index.js');
54
var os = require('os');
6-
var elements;
75

86
robot.setMouseDelay(100);
97

10-
test('Test clicking.', { timeout: 10000 }, function(t)
11-
{
12-
t.plan(2);
8+
let target, elements;
139

14-
// Start the UI.
15-
var target = targetpractice.start();
10+
describe('Integration/Mouse', () => {
11+
beforeEach(done => {
12+
target = targetpractice.start();
13+
target.once('elements', message => {
14+
elements = message;
15+
done();
16+
});
17+
});
18+
19+
afterEach(() => {
20+
targetpractice.stop();
21+
target = null;
22+
});
23+
24+
it('clicks', done => {
25+
// Alright we got a click event, did we click the button we wanted?
26+
target.once('click', function(e)
27+
{
28+
expect(e.id).toEqual('button_1');
29+
expect(e.type).toEqual('click');
30+
done();
31+
});
1632

17-
// Wait for the list of elements.
18-
target.once('elements', function(elements)
19-
{
2033
// For this test we want a button.
2134
var button_1 = elements.button_1;
22-
2335
// Click it!
2436
robot.moveMouse(button_1.x, button_1.y);
2537
robot.mouseClick();
2638
});
2739

28-
// Alright we got a click event, did we click the button we wanted?
29-
target.once('click', function(e)
30-
{
31-
t.equal(e.id, "button_1", 'Confirm button_1 was clicked.');
32-
t.equal(e.type, "click", 'Confirm event was a click.');
33-
});
34-
35-
// Close the UI.
36-
t.once('end', function()
37-
{
38-
targetpractice.stop();
39-
});
40-
});
41-
42-
test('Test typing.', { timeout: 10000 }, function(t)
43-
{
44-
t.plan(2);
45-
46-
var target = targetpractice.start();
47-
var stringToType = "hello world";
40+
it('types', done => {
41+
const stringToType = 'hello world';
42+
// Currently Target Practice waits for the "user" to finish typing before sending the event.
43+
target.once('type', element => {
44+
expect(element.id).toEqual('input_1');
45+
expect(element.text).toEqual(stringToType);
46+
done();
47+
});
4848

49-
target.on('elements', function(elements)
50-
{
51-
var input_1 = elements.input_1;
49+
const input_1 = elements.input_1;
5250
robot.moveMouse(input_1.x, input_1.y);
5351
robot.mouseClick();
5452
robot.typeString(stringToType);
5553
});
5654

57-
// Currently Target Practice waits for the "user" to finish typing before sending the event.
58-
target.once('type', function(element)
59-
{
60-
t.equal(element.id, "input_1", 'Confirm input_1 was used.');
61-
t.equal(element.text, stringToType, `Confirm that ${stringToType} was typed.`);
62-
});
63-
64-
t.once('end', function()
65-
{
66-
targetpractice.stop();
67-
});
68-
});
69-
70-
test('Test scrolling.', { timeout: 10000 }, function(t)
71-
{
72-
t.plan(2);
55+
it('scrolls', done => {
56+
target.once('scroll', element => {
57+
/**
58+
* TODO: This is gross! The scroll distance is different for each OS. I want
59+
* to look into this further, but at least these numbers are consistent.
60+
*/
61+
let expectedScroll;
62+
switch(os.platform()) {
63+
case 'linux':
64+
expectedScroll = 180;
65+
break;
66+
case 'win32':
67+
expectedScroll = 8;
68+
break;
69+
default:
70+
expectedScroll = 10;
71+
}
72+
expect(element.id).toEqual('textarea_1');
73+
expect(element.scroll_y).toEqual(expectedScroll);
74+
done();
75+
});
7376

74-
var target = targetpractice.start();
75-
76-
target.once('elements', function(elements)
77-
{
7877
var textarea_1 = elements.textarea_1;
7978
robot.moveMouse(textarea_1.x, textarea_1.y);
8079
robot.mouseClick();
8180
robot.scrollMouse(0, -10);
8281
});
83-
84-
target.once('scroll', function(element)
85-
{
86-
/**
87-
* TODO: This is gross! The scroll distance is different for each OS. I want
88-
* to look into this further, but at least these numbers are consistent.
89-
*/
90-
let expectedScroll;
91-
switch(os.platform()) {
92-
case 'linux':
93-
expectedScroll = 180;
94-
break;
95-
case 'win32':
96-
expectedScroll = 8;
97-
break;
98-
default:
99-
expectedScroll = 10;
100-
}
101-
t.equal(element.id, 'textarea_1', 'Confirm textarea_1 was used.');
102-
t.equal(element.scroll_y, expectedScroll, 'Confirm scroll to 10.');
103-
});
104-
105-
t.once('end', function()
106-
{
107-
targetpractice.stop();
108-
});
10982
});

test/integration/screen.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,25 @@
22
var test = require('tape');
33
var robot = require('../..');
44
var targetpractice = require('targetpractice/index.js');
5-
var elements;
5+
let elements, target;
66

7-
robot.setMouseDelay(100);
8-
9-
test('Test reading the Screen.', { timeout: 10000 }, function(t)
10-
{
11-
t.plan(1);
7+
describe('Integration/Screen', () => {
8+
beforeEach(done => {
9+
target = targetpractice.start();
10+
target.once('elements', message => {
11+
elements = message;
12+
done();
13+
});
14+
});
1215

13-
// Start the UI.
14-
var target = targetpractice.start();
16+
afterEach(() => {
17+
targetpractice.stop();
18+
target = null;
19+
});
1520

16-
// Wait for the list of elements.
17-
target.once('elements', function(elements)
18-
{
21+
it('reads a pixel color', () => {
1922
var color_1 = elements.color_1;
2023
const color = robot.getPixelColor(color_1.x, color_1.y);
21-
t.equal(color, 'c0ff33', 'Color is what we expected.');
22-
});
23-
24-
// Close the UI.
25-
t.once('end', function()
26-
{
27-
targetpractice.stop();
24+
expect(color).toEqual('c0ff33');
2825
});
2926
});

0 commit comments

Comments
 (0)