This commit is contained in:
Tiệp Sunflower
2023-03-06 14:23:39 +07:00
commit aa9c76c82f
2234 changed files with 449471 additions and 0 deletions

13
node_modules/exeq/tests/basic.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
var test = require('tape').test;
var exeq = require('..');
var isPromise = require('is-promise');
test('basic use', function(t) {
t.equal(typeof exeq, 'function');
t.equal(isPromise(exeq()), true);
t.end();
});

22
node_modules/exeq/tests/cd.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
var test = require('tape').test;
var exeq = require('..');
test('cd change cwd', function(t) {
var tempDirName = '__temp-for-tests';
exeq(
'mkdir ' + tempDirName,
'cd ' + tempDirName,
'pwd',
'cd ..',
'pwd',
'rm -rf ' + tempDirName
).then(function(results) {
t.ok(results[2].stdout.indexOf(tempDirName) > -1);
t.notOk(results[4].stdout.indexOf(tempDirName) > -1);
t.end();
});
});

17
node_modules/exeq/tests/command-name.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
var test = require('tape').test;
var exeq = require('..');
test('command name', function(t) {
exeq(
[
'ls -l',
'cd ..'
],
'ps'
).then(function(results) {
t.equal(results[0].cmd, 'ls -l');
t.equal(results[1].cmd, 'cd ..');
t.equal(results[2].cmd, 'ps');
t.end();
});
});

18
node_modules/exeq/tests/count.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
var test = require('tape').test;
var exeq = require('..');
test('command count', function(t) {
exeq(
'cd /usr/bin',
'cd ..',
'cd /usr/bin'
).then(function(results) {
t.equal(results.length, 3);
return exeq();
}).then(function(results) {
t.equal(results.length, 0);
t.end();
});
});

16
node_modules/exeq/tests/error.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
var test = require('tape').test;
var exeq = require('..');
test('catch error', function(t) {
exeq('not-existed-cmd').then(function(results) {
}).catch(function(err) {
t.equal(err.code, 127);
t.ok(err.stderr.indexOf('not found') > -1);
}).finally(function() {
t.end();
});
});

70
node_modules/exeq/tests/events.js generated vendored Normal file
View File

@@ -0,0 +1,70 @@
var test = require('tape').test;
var exeq = require('..');
test('event done', function(t) {
// Keep the origin promise instance
var proc = exeq([
'echo 1',
'echo 2'
]);
var stdout = [];
proc.q.on('stdout', function(data) {
stdout.push(data);
});
proc.q.on('done', function() {
t.equal(stdout.join(''), '1\n2\n');
t.end();
});
});
test('event fail', function(t) {
var proc = exeq([
'fail-me'
]);
var stderr = [];
proc.catch(function(){});
proc.q.on('stderr', function(data) {
stderr.push(data);
});
proc.q.on('failed', function() {
t.ok(stderr.join('').indexOf('not found') > -1 );
t.end();
});
});
test('event killed', function(t) {
var proc = exeq([
'echo 1',
'sleep 10',
'echo 2'
]);
var stdout = [];
proc.q.on('stdout', function(data) {
stdout.push(data);
});
proc.q.on('killed', function(data) {
t.equal(stdout.join(''), '1\n');
t.equal(data.stderr, '1\nProcess has been killed.');
t.end();
});
proc.catch(function(){});
setTimeout(function(){
proc.q.kill();
}, 600);
});

44
node_modules/exeq/tests/kill.js generated vendored Normal file
View File

@@ -0,0 +1,44 @@
var test = require('tape').test;
var exeq = require('..');
test('kill process 1', function(t) {
// Keep the origin promise instance
var proc = exeq([
'echo 1',
'sleep 10',
'echo 2'
]);
proc.catch(function(err) {
t.equal(err.stderr, '1\nProcess has been killed.');
}).finally(function(){
t.end();
});
setTimeout(function(){
proc.q.kill();
}, 300);
});
test('kill process 2', function(t) {
var proc = exeq([
'sleep 10',
'echo 1',
'echo 2'
]);
proc.catch(function(err) {
t.equal(err.errno, 'SIGTERM');
t.equal(err.stderr, 'Process has been killed.');
}).finally(function(){
t.end();
});
setTimeout(function(){
proc.q.kill();
}, 300);
});

21
node_modules/exeq/tests/output-file.js generated vendored Normal file
View File

@@ -0,0 +1,21 @@
var test = require('tape').test;
var exeq = require('..');
var fs = require('fs');
var path = require('path');
test('output file', function(t) {
var n = -1;
exeq(
'ls > a.txt'
).then(function(results) {
t.ok(fs.existsSync(path.resolve('a.txt')));
t.ok(fs.readFileSync('a.txt').toString().indexOf('a.txt') >= 0);
return exeq('rm a.txt');
}).then(function() {
t.notOk(fs.existsSync('a.txt'));
t.end();
});
});

22
node_modules/exeq/tests/stdout.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
var test = require('tape').test;
var exeq = require('..');
test('stdout', function(t) {
exeq(
'echo 123',
'echo "string"',
'echo 456',
'date'
).then(function(results) {
t.equal(results[0].stdout.trim(), '123');
t.equal(results[1].stdout.trim(), 'string');
t.equal(results[2].stdout.trim(), '456');
var date = new Date(results[3].stdout.trim());
t.notEqual(date.toString(), 'Invalid Date');
t.end();
});
});