![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /proc/self/root/usr/local/lib/node_modules/forever/node_modules/pkginfo/test/ |
Upload File : |
/* * pkginfo-test.js: Tests for the pkginfo module. * * (C) 2011, Charlie Robbins * */ var assert = require('assert'), exec = require('child_process').exec, fs = require('fs'), path = require('path'), vows = require('vows'), pkginfo = require('../lib/pkginfo'); function assertProperties (source, target) { assert.lengthOf(source, target.length + 1); target.forEach(function (prop) { assert.isTrue(!!~source.indexOf(prop)); }); } function compareWithExample(targetPath) { var examplePaths = ['package.json']; if (targetPath) { examplePaths.unshift(targetPath); } return function(exposed) { var pkg = fs.readFileSync(path.join.apply(null, [__dirname, '..', 'examples'].concat(examplePaths))).toString(), keys = Object.keys(JSON.parse(pkg)); assertProperties(exposed, keys); }; } function testExposes (options) { return { topic: function () { exec('node ' + path.join(__dirname, '..', 'examples', options.script), this.callback); }, "should expose that property correctly": function (err, stdout, stderr) { assert.isNull(err); var exposed = stderr.match(/'(\w+)'/ig).map(function (p) { return p.substring(1, p.length - 1); }); return !options.assert ? assertProperties(exposed, options.properties) : options.assert(exposed); } } } vows.describe('pkginfo').addBatch({ "When using the pkginfo module": { "and passed a single `string` argument": testExposes({ script: 'single-property.js', properties: ['version'] }), "and passed multiple `string` arguments": testExposes({ script: 'multiple-properties.js', properties: ['version', 'author'] }), "and passed an `object` argument": testExposes({ script: 'object-argument.js', properties: ['version', 'author'] }), "and passed an `array` argument": testExposes({ script: 'array-argument.js', properties: ['version', 'author'] }), "and read from a specified directory": testExposes({ script: 'target-dir.js', assert: compareWithExample('subdir') }), "and passed no arguments": testExposes({ script: 'all-properties.js', assert: compareWithExample() }) } }).export(module);