Server IP : 127.0.0.2 / Your IP : 18.117.9.230 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/npm/node_modules/write-file-atomic/test/ |
Upload File : |
'use strict' var test = require('tap').test var requireInject = require('require-inject') var writeFileAtomic = requireInject('../index', { 'graceful-fs': { writeFile: function (tmpfile, data, options, cb) { if (/nowrite/.test(tmpfile)) return cb(new Error('ENOWRITE')) cb() }, chown: function (tmpfile, uid, gid, cb) { if (/nochown/.test(tmpfile)) return cb(new Error('ENOCHOWN')) cb() }, rename: function (tmpfile, filename, cb) { if (/norename/.test(tmpfile)) return cb(new Error('ENORENAME')) cb() }, unlink: function (tmpfile, cb) { if (/nounlink/.test(tmpfile)) return cb(new Error('ENOUNLINK')) cb() }, writeFileSync: function (tmpfile, data, options) { if (/nowrite/.test(tmpfile)) throw new Error('ENOWRITE') }, chownSync: function (tmpfile, uid, gid) { if (/nochown/.test(tmpfile)) throw new Error('ENOCHOWN') }, renameSync: function (tmpfile, filename) { if (/norename/.test(tmpfile)) throw new Error('ENORENAME') }, unlinkSync: function (tmpfile) { if (/nounlink/.test(tmpfile)) throw new Error('ENOUNLINK') } } }) var writeFileAtomicSync = writeFileAtomic.sync test('async tests', function (t) { t.plan(7) writeFileAtomic('good', 'test', {mode: '0777'}, function (err) { t.notOk(err, 'No errors occur when passing in options') }) writeFileAtomic('good', 'test', function (err) { t.notOk(err, 'No errors occur when NOT passing in options') }) writeFileAtomic('nowrite', 'test', function (err) { t.is(err.message, 'ENOWRITE', 'writeFile failures propagate') }) writeFileAtomic('nochown', 'test', {chown: {uid: 100, gid: 100}}, function (err) { t.is(err.message, 'ENOCHOWN', 'Chown failures propagate') }) writeFileAtomic('nochown', 'test', function (err) { t.notOk(err, 'No attempt to chown when no uid/gid passed in') }) writeFileAtomic('norename', 'test', function (err) { t.is(err.message, 'ENORENAME', 'Rename errors propagate') }) writeFileAtomic('norename nounlink', 'test', function (err) { t.is(err.message, 'ENORENAME', 'Failure to unlink the temp file does not clobber the original error') }) }) test('sync tests', function (t) { t.plan(7) var throws = function (shouldthrow, msg, todo) { var err try { todo() } catch (e) { err = e } t.is(shouldthrow, err.message, msg) } var noexception = function (msg, todo) { var err try { todo() } catch (e) { err = e } t.notOk(err, msg) } noexception('No errors occur when passing in options', function () { writeFileAtomicSync('good', 'test', {mode: '0777'}) }) noexception('No errors occur when NOT passing in options', function () { writeFileAtomicSync('good', 'test') }) throws('ENOWRITE', 'writeFile failures propagate', function () { writeFileAtomicSync('nowrite', 'test') }) throws('ENOCHOWN', 'Chown failures propagate', function () { writeFileAtomicSync('nochown', 'test', {chown: {uid: 100, gid: 100}}) }) noexception('No attempt to chown when no uid/gid passed in', function () { writeFileAtomicSync('nochown', 'test') }) throws('ENORENAME', 'Rename errors propagate', function () { writeFileAtomicSync('norename', 'test') }) throws('ENORENAME', 'Failure to unlink the temp file does not clobber the original error', function () { writeFileAtomicSync('norename nounlink', 'test') }) })