Skip to content

Commit 53d1e64

Browse files
committed
adding support for unit testing on windows systems
modified: Readme.md new file: make.bat modified: test/integration/connection/test-unix-domain-socket.js
1 parent cc72863 commit 53d1e64

File tree

3 files changed

+66
-13
lines changed

3 files changed

+66
-13
lines changed

Readme.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,17 @@ Set the environment variables `MYSQL_DATABASE`, `MYSQL_HOST`, `MYSQL_PORT`, `MYS
879879
make test
880880
```
881881

882+
## Running unit tests on windows
883+
884+
* Edit the variables in the file ```make.bat``` according to your system and mysql-settings.
885+
* Make sure the database (e.g. 'test') you want to use exists and the user you entered has the proper rights to use the test database. (E.g. do not forget to execute the SQL-command ```FLUSH PRIVILEGES``` after you have created the user.)
886+
* In a DOS-box (or CMD-shell) in the folder of your application run ```npm install mysql --dev``` or in the mysql folder (```node_modules\mysql```), run ```npm install --dev```. (This will install additional developer-dependencies for node-mysql.)
887+
* Run ```npm test mysql``` in your applications folder or ```npm test``` in the mysql subfolder.
888+
* If you want to log the output into a file use ```npm test mysql > test.log``` or ```npm test > test.log```.
889+
882890
## Todo
883891

884892
* Prepared statements
885893
* setTimeout() for Connection / Query
886894
* Support for encodings other than UTF-8 / ASCII
887-
* API support for transactions, similar to [php](http://www.php.net/manual/en/mysqli.quickstart.transactions.php)
895+
* API support for transactions, similar to [php](http://www.php.net/manual/en/mysqli.quickstart.transactions.php)

make.bat

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@ECHO OFF
2+
REM Simple 'make' replacement for windows-based system, 'npm test' will now find
3+
REM 'make.bat' and sets the MYSQL_ enviroment variables according to this file
4+
5+
REM Edit the variables according to your system
6+
REM No spaces (' ') between variablenames, '=' and the values!
7+
8+
REM Host to test with default: localhost
9+
SET MYSQL_HOST=localhost
10+
11+
REM Default mysql port: 3306
12+
SET MYSQL_PORT=3306
13+
14+
REM For a standard installatons of Wampp using http://www.apachefriends.org/
15+
REM the default login is 'root' and no password, but any user should do, change
16+
REM the settings according to your installation
17+
SET MYSQL_USER=root
18+
SET MYSQL_PASSWORD=
19+
20+
REM make sure the database you are using exists and the above user has access to
21+
REM it. Normally every user has access to the database 'test'
22+
SET MYSQL_DATABASE=test
23+
24+
@ECHO ON
25+
node test/run.js
26+
@ECHO OFF
27+
ECHO **********************
28+
ECHO If the tests should fail, make sure you have SET the correct values for the enviroment variables in the file 'make.bat'
29+
ECHO **********************
Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
1+
/**
2+
* If on a windows system, there are no unix sockets.
3+
* So we skip this test and defaulting the asserts in the
4+
* process.on('exit', [...]) function to false, when we find the
5+
* enviroment variable 'windir' is set. I assume 'windir' will not be set on
6+
* *nix-systems.
7+
*/
18
var common = require('../../common');
29
var connection = common.createConnection({socketPath: common.fakeServerSocket});
310
var assert = require('assert');
411

512
var server = common.createFakeServer();
613
var didConnect = false;
7-
server.listen(common.fakeServerSocket, function(err) {
8-
if (err) throw err;
14+
if (!process.env.windir) {
15+
server.listen(common.fakeServerSocket, function(err) {
16+
if (err) throw err;
917

10-
connection.connect(function(err) {
18+
connection.connect(function(err) {
1119
if (err) throw err;
1220

1321
assert.equal(didConnect, false);
1422
didConnect = true;
1523

1624
connection.destroy();
1725
server.destroy();
26+
});
1827
});
19-
});
28+
}
2029

2130
var hadConnection = false;
22-
server.on('connection', function(connection) {
23-
connection.handshake();
31+
if (!process.env.windir) {
32+
server.on('connection', function(connection) {
33+
connection.handshake();
2434

25-
assert.equal(hadConnection, false);
26-
hadConnection = true;
27-
});
35+
assert.equal(hadConnection, false);
36+
hadConnection = true;
37+
});
38+
}
2839

2940
process.on('exit', function() {
30-
assert.equal(didConnect, true);
31-
assert.equal(hadConnection, true);
32-
});
41+
if (process.env.windir) {
42+
assert.equal(didConnect, false);
43+
assert.equal(hadConnection, false);
44+
} else {
45+
assert.equal(didConnect, true);
46+
assert.equal(hadConnection, true);
47+
}
48+
});

0 commit comments

Comments
 (0)