diff --git a/.travis.yml b/.travis.yml index 1731554af..8d3b3e3d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ services: before_install: - mysql -e "create database IF NOT EXISTS test;" -uroot + - echo "USE mysql;\nUPDATE user SET password=PASSWORD('Password12!') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root env: - GCLOUD_PROJECT=0 CXX=g++-4.8 diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..007408175 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,40 @@ +# Test against this version of Node.js +environment: + matrix: + # node.js + # Testing against LTS/Current, 0.12 intentionally omitted to reduce maintenance burden + - nodejs_version: "4" + - nodejs_version: "6" + +services: + - mongodb + - mysql + +# Install scripts. (runs after repo cloning) +install: + # Get the latest stable version of Node.js or io.js + - ps: Install-Product node $env:nodejs_version + # Install the Redis + - nuget install redis-64 -excludeversion + - redis-64\tools\redis-server.exe --service-install + - redis-64\tools\redis-server.exe --service-start + # install modules + - npm install + # Skip grpc due to https://github.com/nodejs/node/issues/4932 + - ps: ForEach ($fix in Get-ChildItem -Directory test/hooks/fixtures/*) { if ($fix -notmatch 'grpc*') { cd $fix; npm install --silent } } + - ps: cd ..\..\..\.. + # set GCLOUD_PROJECT + - SET GCLOUD_PROJECT=0 + +before_test: + - SET PATH=C:\Program Files\MySql\MySQL Server 5.7\bin;%PATH% + - mysqladmin --host=localhost --user=root --password=Password12! create test + +# Post-install test scripts. +test_script: + # run tests + - ps: node_modules/.bin/mocha test test\hooks --timeout 4000 --R + - ps: ForEach ($test in Get-ChildItem test/standalone/test-*.js) { if ($test -notmatch 'grpc*') { node_modules/.bin/mocha $test --timeout 4000 --R; if ($lastexitcode -ne 0) { exit 1 } } } + +# Don't actually build using MSBuild +build: off diff --git a/lib/hooks/index.js b/lib/hooks/index.js index c3898fa4d..85e3bf0ed 100644 --- a/lib/hooks/index.js +++ b/lib/hooks/index.js @@ -97,7 +97,9 @@ function findModuleVersion(modulePath, load) { function checkLoadedModules(logger) { for (var moduleName in toInstrument) { - var regex = new RegExp('node_modules' + path.sep + moduleName + path.sep); + // \\ is benign on unix and escapes \\ on windows + var regex = new RegExp('node_modules\\' + path.sep + moduleName + + '\\' + path.sep); for (var file in require.cache) { if (file.match(regex)) { logger.error(moduleName + ' tracing might not work as ' + file + diff --git a/test/hooks/test-trace-express.js b/test/hooks/test-trace-express.js index 140eda450..74939a7d5 100644 --- a/test/hooks/test-trace-express.js +++ b/test/hooks/test-trace-express.js @@ -22,8 +22,22 @@ var common = require('./common.js'); var express = require('./fixtures/express4'); var server; +var write; describe('test-trace-express', function() { + before(function() { + // Mute stderr to satiate appveyor + write = process.stderr.write; + process.stderr.write = function(c, e, cb) { + assert.equal(c, 1729); + if (cb) { + cb(); + } + }; + }); + after(function() { + process.stderr.write = write; + }); afterEach(function() { common.cleanTraces(); server.close(); diff --git a/test/hooks/test-trace-mysql.js b/test/hooks/test-trace-mysql.js index a540ca92a..234daa950 100644 --- a/test/hooks/test-trace-mysql.js +++ b/test/hooks/test-trace-mysql.js @@ -23,8 +23,8 @@ var mysql = require('./fixtures/mysql2'); var pool = mysql.createPool({ host : 'localhost', - user : 'travis', - password : '', + user : 'root', + password : 'Password12!', database : 'test' }); var connection; diff --git a/test/hooks/test-trace-restify.js b/test/hooks/test-trace-restify.js index 7d7a46b5b..af553ae68 100644 --- a/test/hooks/test-trace-restify.js +++ b/test/hooks/test-trace-restify.js @@ -25,11 +25,25 @@ var versions = { }; var server; +var write; Object.keys(versions).forEach(function(version) { var restify = versions[version]; describe(version, function() { + before(function() { + // Mute stderr to satiate appveyor + write = process.stderr.write; + process.stderr.write = function(c, e, cb) { + assert(c.indexOf('DeprecationWarning') !== -1); + if (cb) { + cb(); + } + }; + }); + after(function() { + process.stderr.write = write; + }); afterEach(function() { common.cleanTraces(); server.close(); diff --git a/test/standalone/test-hooks-no-project-num.js b/test/standalone/test-hooks-no-project-num.js index 0c1ebd81b..998f36d59 100644 --- a/test/standalone/test-hooks-no-project-num.js +++ b/test/standalone/test-hooks-no-project-num.js @@ -18,8 +18,22 @@ delete process.env.GCLOUD_PROJECT; var assert = require('assert'); +var write; describe('should not break without project num', function() { + before(function() { + // Mute stderr to satiate appveyor + write = process.stderr.write; + process.stderr.write = function(c, e, cb) { + assert(c.indexOf('DeprecationWarning') !== -1); + if (cb) { + cb(); + } + }; + }); + after(function() { + process.stderr.write = write; + }); it('mongo', function(done) { var agent = require('../..').start(); var mongoose = require('../hooks/fixtures/mongoose4'); @@ -123,8 +137,8 @@ describe('should not break without project num', function() { var mysql = require('../hooks/fixtures/mysql2'); var pool = mysql.createPool({ host : 'localhost', - user : 'travis', - password : '', + user : 'root', + password : 'Password12!', database : 'test' }); pool.getConnection(function(err, conn) { diff --git a/test/standalone/test-hooks-sample-warning.js b/test/standalone/test-hooks-sample-warning.js index 76dc944af..861eb0b83 100644 --- a/test/standalone/test-hooks-sample-warning.js +++ b/test/standalone/test-hooks-sample-warning.js @@ -116,8 +116,8 @@ describe('express + dbs', function() { app.get('/', function (req, res) { var pool = mysql.createPool({ host : 'localhost', - user : 'travis', - password : '', + user : 'root', + password : 'Password12!', database : 'test' }); http.get('http://www.google.com/', function() { diff --git a/test/standalone/test-mysql-pool.js b/test/standalone/test-mysql-pool.js index 99fb2bc39..e730fb49c 100644 --- a/test/standalone/test-mysql-pool.js +++ b/test/standalone/test-mysql-pool.js @@ -31,8 +31,8 @@ if (semver.satisfies(process.version, '>=4')) { register: require('../hooks/fixtures/hapi-plugin-mysql3'), options: { host : 'localhost', - user : 'travis', - password : '', + user : 'root', + password : 'Password12!', database : 'test' } }, function (err) { diff --git a/test/test-util.js b/test/test-util.js index 99d05d54a..09cbbe1f2 100644 --- a/test/test-util.js +++ b/test/test-util.js @@ -18,6 +18,7 @@ var assert = require('assert'); var util = require('../lib/util.js'); +var path = require('path'); var o = { a: 5, @@ -46,14 +47,23 @@ describe('util.stringifyPrefix', function() { describe('util.packageNameFromPath', function() { it('should work for standard packages', function() { - var path = './appengine-sails/node_modules/testmodule/index.js'; - assert.equal(util.packageNameFromPath(path), + var p = path.join('.', + 'appengine-sails', + 'node_modules', + 'testmodule', + 'index.js'); + assert.equal(util.packageNameFromPath(p), 'testmodule'); }); it('should work for namespaced packages', function() { - var path = './appengine-sails/node_modules/@google/cloud-trace/index.js'; - assert.equal(util.packageNameFromPath(path), - '@google/cloud-trace'); + var p = path.join('.', + 'appengine-sails', + 'node_modules', + '@google', + 'cloud-trace', + 'index.js'); + assert.equal(util.packageNameFromPath(p), + path.join('@google','cloud-trace')); }); });