diff --git a/.gitignore b/.gitignore index a3e97a0..2e1f869 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ ipch/ *.sln.cache *.suo -*.user \ No newline at end of file +*.user +log.out +*.js.logs \ No newline at end of file diff --git a/test/functional/scripts/setup.bat b/test/functional/scripts/setup.bat new file mode 100644 index 0000000..beed979 --- /dev/null +++ b/test/functional/scripts/setup.bat @@ -0,0 +1,58 @@ +@echo off + +set appcmd=%systemroot%\system32\inetsrv\appcmd.exe +set apppool=iisnodetest +set site=iisnodetest +set port=31415 +set node=%systemdrive%\node\node.exe +set www= +for /F %%I in ('dir /b /s %~dp0..\test.bat') do set www=%%~dI%%~pIwww +if "%log%" equ "" set log="%~dp0log.out" + +if not exist %node% ( + echo FAILED. The node.exe was not found at %node%. Download a copy from http://nodejs.org. + exit /b -1 +) + +if not exist %appcmd% ( + echo FAILED. The appcmd.exe IIS management tool was not found at %appcmd%. Make sure you have both IIS7 as well as IIS7 Management Tools installed. + exit /b -1 +) + +%appcmd% delete site %site% >> %log% +if %ERRORLEVEL% neq 0 if %ERRORLEVEL% neq 1168 ( + echo FAILED. Cannot delete site %site%. + exit /b -1 +) + +%appcmd% delete apppool %apppool% >> %log% +if %ERRORLEVEL% neq 0 if %ERRORLEVEL% neq 1168 ( + echo FAILED. Cannot delete application pool %apppool%. + exit /b -1 +) + +%appcmd% add apppool /name:%apppool% >> %log% +if %ERRORLEVEL% neq 0 ( + echo FAILED. Cannot create application pool %apppool%. + exit /b -1 +) + +%appcmd% add site /name:%site% /physicalPath:"%www%" /bindings:http/*:%port%: >> %log% +if %ERRORLEVEL% neq 0 ( + echo FAILED. Cannot create site %site%. + exit /b -1 +) + +%appcmd% set site %site% /[path='/'].applicationPool:%apppool% >> %log% +if %ERRORLEVEL% neq 0 ( + echo FAILED. Cannot configure site %site%. + exit /b -1 +) + +%appcmd% start site %site% >> %log% +if %ERRORLEVEL% neq 0 ( + echo FAILED. Cannot start site %site%. + exit /b -1 +) + +exit /b 0 \ No newline at end of file diff --git a/test/functional/test.bat b/test/functional/test.bat new file mode 100644 index 0000000..8938f2b --- /dev/null +++ b/test/functional/test.bat @@ -0,0 +1,74 @@ +@echo off +setlocal + +set log="%~dp0log.out" + +date /T +time /T +date /T > %log% +time /T >> %log% + +call %~dp0scripts\setup.bat +if %ERRORLEVEL% neq 0 exit /b -1 + +set testFilter=* +if "%1" neq "" set testFilter=%1 + +dir /b %~dp0tests\%testFilter%.* 2> nul > nul +if %ERRORLEVEL% neq 0 ( + echo No tests names match the filter %testFilter%. + exit /b -1 +) + +set success=0 +set failure=0 + +for /f %%I in ('dir /b /a-d %~dp0tests\%testFilter%.*') do call :run_one %%I %%~xI + +echo Total passed: %success% +echo Total failed: %failure% +echo ------------------------ >> %log% +echo Total passed: %success% >> %log% +echo Total failed: %failure% >> %log% + +date /T +time /T +date /T >> %log% +time /T >> %log% + +if %failure% neq 0 exit /b -1 + +exit /b 0 + +:run_one + +echo Running: %1... +echo ------------------------ Running %1 >> %log% +if "%2" equ ".js" ( + call :run_node_test %1 +) else ( + call "%~dp0tests\%1" >> %log% 2>>&1 +) + +if %ERRORLEVEL% equ 0 ( + set /A success=success+1 + echo Passed: %1 + echo Passed: %1 >> %log% +) else ( + set /A failure=failure+1 + echo Failed: %1 + echo Failed: %1 >> %log% +) + +exit /b 0 + +:run_node_test + +%node% "%~dp0tests\%1" >> %log% 2>"%~dp0tests\%1.err" +type "%~dp0tests\%1.err" >> %log% +for /F %%A IN ('dir /s /b "%~dp0tests\%1.err"') do set size=%%~zA +del /q "%~dp0tests\%1.err" +if "%size%" neq "0" exit /b -1 +exit /b 0 + +endlocal \ No newline at end of file diff --git a/test/functional/tests/100_helloworld.js b/test/functional/tests/100_helloworld.js new file mode 100644 index 0000000..01b3a2a --- /dev/null +++ b/test/functional/tests/100_helloworld.js @@ -0,0 +1,3 @@ +var iisnodeassert = require("iisnodeassert"); + +iisnodeassert.get("/100_helloworld/hello.js", 200, "Hello, world!"); \ No newline at end of file diff --git a/test/functional/tests/node_modules/iisnodeassert.js b/test/functional/tests/node_modules/iisnodeassert.js new file mode 100644 index 0000000..be69a1d --- /dev/null +++ b/test/functional/tests/node_modules/iisnodeassert.js @@ -0,0 +1,47 @@ +var http = require("http"); +var assert = require("assert"); + +process.on('uncaughtException', function (err) { + console.error(err); + console.stdout.flush(); + console.stderr.flush(); + process.kill(process.pid); +}); + +exports.get = function (path, expectedStatusCode, expectedBody) { + var options = { + host: "localhost", + port: 31415, + method: "GET", + path: path, + }; + + console.log("request options: " + JSON.stringify(options)); + + var request = http.request(options, function(res) { + console.log("response status: " + res.statusCode); + console.log("response headers: " + JSON.stringify(res.headers)); + + assert.equal(res.statusCode, expectedStatusCode, "response status code matches the expected response status code"); + + res.setEncoding("utf8"); + var body = ""; + res.on("data", function(chunk) { + console.log("response body chunk: " + chunk); + body += chunk; + }); + res.on("end", function() { + console.log("end of response"); + + assert.equal(body, expectedBody, "response body matches the expected response body"); + }); + }); + + request.on("error", function (e) { + console.log("problem with request: " + e.message); + + assert.ok(false, "response finished successfully"); + }); + + request.end(); +} \ No newline at end of file diff --git a/test/functional/www/100_helloworld/hello.js b/test/functional/www/100_helloworld/hello.js new file mode 100644 index 0000000..0d1726b --- /dev/null +++ b/test/functional/www/100_helloworld/hello.js @@ -0,0 +1,6 @@ +var http = require('http'); + +http.createServer(function (req, res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end('Hello, world!'); +}).listen(process.env.PORT); \ No newline at end of file diff --git a/test/functional/www/100_helloworld/web.config b/test/functional/www/100_helloworld/web.config new file mode 100644 index 0000000..ae902f5 --- /dev/null +++ b/test/functional/www/100_helloworld/web.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/functional/www/ping.txt b/test/functional/www/ping.txt new file mode 100644 index 0000000..ed53c21 --- /dev/null +++ b/test/functional/www/ping.txt @@ -0,0 +1 @@ +pong \ No newline at end of file