Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Sync features with Node 9 #24

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
language: node_js
node_js:
- '0.8'
- '0.10'
- 'stable'
- '8'
- '6'
- '4'
- '0.12'
- '0.10'
script:
- 'npm test'
# Run browser tests on one node version.
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && [[ $(node -v) =~ ^v8.*$ ]] && npm run test:browsers'
env:
global:
- secure: AdUubswCR68/eGD+WWjwTHgFbelwQGnNo81j1IOaUxKw+zgFPzSnFEEtDw7z98pWgg7p9DpCnyzzSnSllP40wq6AG19OwyUJjSLoZK57fp+r8zwTQwWiSqUgMu2YSMmKJPIO/aoSGpRQXT+L1nRrHoUJXgFodyIZgz40qzJeZjc=
Expand Down
25 changes: 25 additions & 0 deletions internal/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var colorRegExp = /\u001b\[\d\d?m/g;

function removeColors(str) {
return str.replace(colorRegExp, '');
}

function getConstructorOf(obj) {
while (obj) {
var descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor');
if (descriptor !== undefined &&
typeof descriptor.value === 'function' &&
descriptor.value.name !== '') {
return descriptor.value;
}

obj = Object.getPrototypeOf(obj);
}

return null;
}

module.exports = {
removeColors: removeColors,
getConstructorOf: getConstructorOf
};
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
"support"
],
"scripts": {
"test": "node test/node/*.js && zuul test/browser/*.js"
"test": "node test/node/index.js",
"test:browsers": "zuul test/browser/*.js"
},
"dependencies": {
"inherits": "2.0.1"
"inherits": "2.0.1",
"is-typed-array": "^1.0.4"
},
"license": "MIT",
"devDependencies": {
"zuul": "~1.0.9"
"tape": "^4.9.0",
"zuul": "^1.0.10"
},
"browser": {
"./support/isBuffer.js": "./support/isBufferBrowser.js"
Expand Down
75 changes: 47 additions & 28 deletions test/node/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,68 +19,87 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
var assert = require('assert');
var util = require('../../');

if (process.argv[2] === 'child')
child();
var modeArgv = process.argv[2]
var sectionArgv = process.argv[3]

if (modeArgv === 'child')
child(sectionArgv);
else
parent();

function parent() {
test('foo,tud,bar', true);
test('foo,tud', true);
test('tud,bar', true);
test('tud', true);
test('foo,bar', false);
test('', false);
test('foo,tud,bar', true, 'tud');
test('foo,tud', true, 'tud');
test('tud,bar', true, 'tud');
test('tud', true, 'tud');
test('foo,bar', false, 'tud');
test('', false, 'tud');

test('###', true, '###');
test('hi:)', true, 'hi:)');
test('f$oo', true, 'f$oo');
test('f$oo', false, 'f.oo');
test('no-bar-at-all', false, 'bar');

test('test-abc', true, 'test-abc');
test('test-a', false, 'test-abc');
test('test-*', true, 'test-abc');
test('test-*c', true, 'test-abc');
test('test-*abc', true, 'test-abc');
test('abc-test', true, 'abc-test');
test('a*-test', true, 'abc-test');
test('*-test', true, 'abc-test');
}

function test(environ, shouldWrite) {
function test(environ, shouldWrite, section) {
var expectErr = '';
if (shouldWrite) {
expectErr = 'TUD %PID%: this { is: \'a\' } /debugging/\n' +
'TUD %PID%: number=1234 string=asdf obj={"foo":"bar"}\n';
}
var expectOut = 'ok\n';
var didTest = false;

var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [__filename, 'child'], {
env: { NODE_DEBUG: environ }
process.env.NODE_DEBUG = environ;
var child = spawn(process.execPath, [__filename, 'child', section], {
env: process.env
});

expectErr = expectErr.split('%PID%').join(child.pid);
if (shouldWrite) {
expectErr =
section.toUpperCase() + ' ' + child.pid + ': this { is: \'a\' } /debugging/\n' +
section.toUpperCase() + ' ' + child.pid + ': num=1 str=a obj={"foo":"bar"}\n';
}

var err = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', function(c) {
child.stderr.on('data', function (c) {
err += c;
});

var out = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', function(c) {
child.stdout.on('data', function (c) {
out += c;
});

child.on('close', function(c) {
var didTest = false;
child.on('close', function (c) {
assert(!c);
assert.equal(err, expectErr);
assert.equal(out, expectOut);
assert.strictEqual(err, expectErr);
assert.strictEqual(out, expectOut);
didTest = true;
console.log('ok %j %j', environ, shouldWrite);
});

process.on('exit', function() {
process.on('exit', function () {
assert(didTest);
});
}


function child() {
var debug = util.debuglog('tud');
function child(section) {
var util = require('../../util');
var debug = util.debuglog(section);
debug('this', { is: 'a' }, /debugging/);
debug('number=%d string=%s obj=%j', 1234, 'asdf', { foo: 'bar' });
debug('num=%d str=%s obj=%j', 1, 'a', { foo: 'bar' });
console.log('ok');
}
7 changes: 7 additions & 0 deletions test/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var spawn = require('child_process').spawnSync;

spawn(process.argv[0], [ require.resolve('./debug') ], { stdio: 'inherit' });
spawn(process.argv[0], [ require.resolve('./format') ], { stdio: 'inherit' });
spawn(process.argv[0], [ require.resolve('./inspect') ], { stdio: 'inherit' });
spawn(process.argv[0], [ require.resolve('./log') ], { stdio: 'inherit' });
spawn(process.argv[0], [ require.resolve('./promisify') ], { stdio: 'inherit' });
Loading