Skip to content

Commit 7c886d1

Browse files
daeyeonyichoi
authored andcommitted
Add tests for process.chdir and net.connect (#950)
IoT.js-DCO-1.0-Signed-off-by: Daeyeon Jeong [email protected]
1 parent b531629 commit 7c886d1

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

test/run_pass/test_net_connect.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
var assert = require('assert');
17+
var net = require('net');
18+
var host = '127.0.0.1';
19+
var port = 5696;
20+
var msg = 'Hello IoT.js';
21+
22+
var server = net.createServer({
23+
allowHalfOpen: true,
24+
},
25+
function(socket) {
26+
server.close();
27+
}
28+
);
29+
30+
server.listen(port);
31+
32+
server.on('connection', function(socket) {
33+
var data = '';
34+
socket.on('data', function(chuck) {
35+
data += chuck;
36+
});
37+
socket.on('end', function() {
38+
socket.end(data);
39+
});
40+
});
41+
42+
var socket = net.connect(port, host, function() {
43+
var data = '';
44+
socket.on('data', function(chuck) {
45+
data += chuck;
46+
});
47+
48+
socket.on('end', function() {
49+
assert.equal(data, msg);
50+
});
51+
52+
socket.end(msg);
53+
});

test/run_pass/test_process_chdir.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
var assert = require('assert');
16+
17+
var currentPath = process.cwd();
18+
19+
try {
20+
process.chdir('/');
21+
} catch (err) {
22+
console.log('invalid path');
23+
}
24+
25+
assert.equal(process.cwd(), '/');
26+
27+
process.chdir(currentPath);

test/testsets.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
{ "name": "test_net_8.js" },
5555
{ "name": "test_net_9.js" },
5656
{ "name": "test_net_10.js" },
57+
{ "name": "test_net_connect.js", "timeout": 10 },
5758
{ "name": "test_net_headers.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" },
5859
{ "name": "test_net_http_get.js", "timeout": 20, "skip": ["nuttx"], "reason": "not implemented for nuttx" },
5960
{ "name": "test_net_http_response_twice.js", "timeout": 10, "skip": ["nuttx"], "reason": "not implemented for nuttx" },
@@ -66,6 +67,7 @@
6667
{ "name": "test_net_httpserver_timeout.js", "timeout": 10, "skip": ["nuttx"], "reason": "not implemented for nuttx" },
6768
{ "name": "test_net_httpserver.js", "timeout": 20, "skip": ["nuttx"], "reason": "not implemented for nuttx" },
6869
{ "name": "test_process.js" },
70+
{ "name": "test_process_chdir.js" },
6971
{ "name": "test_process_cwd.js", "skip": ["all"], "reason": "this test had @STDOUT=COMMAND[pwd], but there's no way to check out current directory path with js driver. So it skips temporarily." },
7072
{ "name": "test_process_exit.js", "skip": ["all"], "reason": "driver can not run with test which checks out process.exit events" },
7173
{ "name": "test_process_experimental_off.js", "skip": ["experimental"], "reason": "needed if testing stablity is set with stable" },

0 commit comments

Comments
 (0)