Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ElNounch committed May 10, 2015
1 parent 5489cb3 commit d1284a0
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 141 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/headlessIE.exe binary
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
bin
npm-debug.log
node_modules
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
!bin/headlessIE.exe
.gitattributes
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# headlessIE
# headless-ie

[![Build status](https://ci.appveyor.com/api/projects/status/ek0a74lvpflmsy8j?svg=true)](https://ci.appveyor.com/project/ElNounch/headlessie)
[![Build status](https://ci.appveyor.com/api/projects/status/ek0a74lvpflmsy8j/branch/master?svg=true)](https://ci.appveyor.com/project/ElNounch/headlessie)

Windows only.

Expand All @@ -9,7 +9,7 @@ Encapsulate [headlessIE-cs](https://github.com/ElNounch/headlessIE-cs), providin
# methods

``` js
var headlessIE = require('headlessIE')
var headlessIE = require('headless-ie')
...
headlessIE.command( function( err, reported_path ) {
proc = child_process.spawn( reported_path, [ 'http://localhost:8000/entrance' ] )
Expand All @@ -18,16 +18,16 @@ headlessIE.command( function( err, reported_path ) {
## command(callback)
Return full path to (provided) browser's executable.
Provide full path to (included) browser's executable, by calling your `callback(error,command)`.
## version(callback)
Return local Internet Explorer version number.
Provide local Internet Explorer version number, by calling your `callback(error,version)`.
# install
```
npm install --save-opts headlessIE
npm install --save-opts headless-ie
```
# license
Expand Down
8 changes: 3 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ version: 1.0.0-{build}
#matrix:
# fast_finish: true

# Download source using zip interface of GitHub
shallow_clone: true

environment:
matrix:
# Test against thus versions of Node.js
- nodejs_version: 0.8
- nodejs_version: 0.10
- nodejs_version: 0.12
- nodejs_version: 0.10
- nodejs_version: 0.8
# io.js
- nodejs_version: 1

Expand All @@ -22,6 +19,7 @@ install:
- ps: Install-Product node $env:nodejs_version
# Update npm itself
- npm install -g npm
- set PATH=%APPDATA%\npm;%APPVEYOR_BUILD_FOLDER%\node_modules\.bin;%PATH%
# Install modules
- npm install

Expand Down
Binary file added bin/headlessIE.exe
Binary file not shown.
67 changes: 0 additions & 67 deletions headlessIE-cs/headlessIE.cs

This file was deleted.

51 changes: 26 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
var path = require('path')
var fs = require('fs')
var child_process = require('child_process')
var asap = require('asap')
var asyncify = require('dezalgo')

var fullPath = path.join(__dirname, '/bin/headlessIE.exe')

function asapify( cb ) {
var th = this
return function () {
asap( cb.apply( th, arguments ) )
}
}
var versionsRE = /HeadlessIE ((?:\d+)(?:\.(?:\d+)){0,3}) \(Internet Explorer ((?:\d+)(?:\.(?:\d+)){0,3})\)/g
var fullPath = path.join( __dirname, '/bin/headlessIE.exe' )

exports.command = function command(callback) {
asapify(callback)

callback( undefined, fullPath )
var cb = asyncify(callback)

fs.exists( fullPath, function exeExistCommand( present ) {
if( present ) {
cb( undefined, fullPath )
} else {
cb( 'missing headlessIE executable from package', undefined )
}
})
}

exports.version = function version(callback) {
asapify(callback)
var cb = asyncify(callback)

try {
var vers = ''
var proc = child_process.spawn( fullPath, [ '--version' ] )

proc.stdout.on( 'data', function (data) {
vers += data
})

proc.on('close', function (code) {
if( ( code == 0 ) && ( /^(\d+)(\.(\d+)){0,3}/.test( vers ) ) ) {
callback( undefined, vers )
fs.exists( fullPath, function exeExistVersion( present ) {
if( present ) {
var proc = child_process.execFile( fullPath, [ '--version' ], function VersionRunner( err, stdout ) {
matches = versionsRE.exec( stdout )
if( matches ) {
cb( undefined, matches[2] )
} else {
cb( 'Wrong program return to --version argument', undefined )
}
})
} else {
callback( "Wrong program return to --version argument", undefined )
cb( 'missing headlessIE executable from package', undefined )
}
})
} catch( e ) {
callback( "Unable to launch program", undefined )
cb( 'Unable to launch program', undefined )
}
}
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
{
"name": "headlessIE",
"private": true,
"name": "headless-ie",
"version": "1.0.0",
"description": "Headless Internet Explorer",
"os": "win32",
"main": "index.js",
"scripts": {
"prepublish": "if not exist bin mkdir bin && csc /out:bin\\headlessIE.exe /t:exe headlessIE-cs\\headlessIE.cs",
"test": "tape test/*.js"
"test": "tape test/*.js | tap-spec"
},
"keywords": [
"headless",
"ie",
"browser-launcher"
"ie"
],
"repository": {
"type": "git",
Expand All @@ -27,9 +24,11 @@
"license": "MIT",
"devDependencies": {
"express": "~4.12.0",
"mkdirp": "^0.5.0",
"tap-spec": "^3.0.0",
"tape": "~4.0.0"
},
"dependencies": {
"asap": "^2.0.3"
"dezalgo": "^1.0.1"
}
}
94 changes: 65 additions & 29 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,36 @@ function createRandomLocalAddress() {
}

test('return values test', function (t) {
t.plan(5)
t.plan(2)

headlessIE.version( function(err,reported_version) {
t.ok( typeof err === 'undefined', 'no error while looking for version' )
t.ok( typeof reported_version === 'string', 'version returned a string : "' + reported_version + '"' )
t.test('version', function(tV) {
tV.plan(1)
headlessIE.version( function(err,reported_version) {
if( err ) {
tV.fail( 'problem while looking for version : ' + err )
} else {
tV.ok( typeof reported_version === 'string', 'version returned a string : "' + reported_version + '"' )
}
})
})

headlessIE.command( function(err,reported_path) {
t.ok( typeof err === 'undefined', 'no error while looking for command' )
var stat = fs.statSync( reported_path )
t.ok( stat, 'path exist...')
t.ok( stat.isFile(), '... and is a file')
t.test('command', function(tC) {
headlessIE.command( function( err, reported_cmd ) {
if( err ) {
tC.fail( 'problem while looking for path : ' + err )
tC.end()
} else {
fs.stat( reported_cmd, function( err, stat ) {
tC.ok( stat, 'path exist...' )
tC.ok( stat.isFile(), '... and is a file' )
tC.end()
})
}
})
})
})

test('functionnal test', { timeout: 20000 }, function (t) {
t.plan(5)
test('functionnal test', { timeout: 30000 }, function (t) {
var app = express()
var server
var proc
Expand All @@ -37,34 +50,57 @@ test('functionnal test', { timeout: 20000 }, function (t) {
var local_addr = createRandomLocalAddress()

app.get('/entrance', function (req, res) {
res.send('<html><head><script>location.href="/javascript_passed"</script><body></body></html>')
t.pass('entrance page accessed')
res.setHeader( 'Connection', 'close' )
res.setHeader( 'Content-Type', 'text/html' )
res.send( '<html><head><script>location.href="/javascript_passed"</script><body></body></html>' )
res.end()
t.pass( 'entrance page accessed' )
})
app.get('/javascript_passed', function (req, res) {
res.send('Job done !')
t.pass('javascript worked')
job_done = true
clearTimeout( timer )
proc.kill()
server.close()
res.setHeader( 'Connection', 'close' )
res.setHeader( 'Content-Type', 'text/plain' )
res.send( 'Job done !' )
res.end()
t.pass( 'javascript worked' )
job_done = true
clearTimeout( timer )
proc.kill()//'SIGHUP')
server.close()
})

server = app.listen(8000, local_addr)

timer = setTimeout( function onTimeOut() {
proc.kill()
proc.kill('SIGHUP')
server.close()
}, 15000)
}, 25000)

headlessIE.command( function(err,reported_path) {
t.ok( typeof err === 'undefined', 'no error while looking for command' )
proc = child_process.spawn( reported_path, [ 'http://' + local_addr + ':8000/entrance' ] )
if( err ) {
t.fail( 'problem while looking for path : ' + err )
clearTimeout( timer )
server.close()
t.end()
} else {
proc = child_process.spawn( reported_path, [ 'http://' + local_addr + ':8000/entrance' ] )

proc.on('exit', function onIEExit( code, signal ) {
if( job_done ) {
t.ok( code === null, 'exit code is correct')
t.ok( signal === 'SIGTERM', 'killed by signal')
}
})
proc.stdout.on( 'data', function onStdout( data ) {
t.comment( 'console message : ' + data )
})

proc.stderr.on( 'data', function onStderr( data ) {
t.comment( 'error message : ' + data )
})

proc.on('exit', function onIEExit( code, signal ) {
if( job_done ) {
t.ok( code === null, 'exit code is correct' )
t.ok( signal === 'SIGTERM', 'killed by signal' )
} else {
t.fail( 'unexpected browser quit' )
}
t.end()
})
}
})
})

0 comments on commit d1284a0

Please sign in to comment.