Mk nohup (#3285)
This commit is contained in:
parent
ab96676e36
commit
4963a1eea8
|
@ -14,7 +14,18 @@ test('should be able to run a shell command', async (t) => {
|
||||||
rig.createFile('blah.txt', 'some content');
|
rig.createFile('blah.txt', 'some content');
|
||||||
|
|
||||||
const prompt = `Can you use ls to list the contexts of the current folder`;
|
const prompt = `Can you use ls to list the contexts of the current folder`;
|
||||||
const result = await rig.run(prompt);
|
const result = rig.run(prompt);
|
||||||
|
|
||||||
|
assert.ok(result.includes('blah.txt'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should be able to run a shell command via stdin', async (t) => {
|
||||||
|
const rig = new TestRig();
|
||||||
|
rig.setup(t.name);
|
||||||
|
rig.createFile('blah.txt', 'some content');
|
||||||
|
|
||||||
|
const prompt = `Can you use ls to list the contexts of the current folder`;
|
||||||
|
const result = rig.run({ stdin: prompt });
|
||||||
|
|
||||||
assert.ok(result.includes('blah.txt'));
|
assert.ok(result.includes('blah.txt'));
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,14 +47,30 @@ export class TestRig {
|
||||||
execSync('sync', { cwd: this.testDir });
|
execSync('sync', { cwd: this.testDir });
|
||||||
}
|
}
|
||||||
|
|
||||||
run(prompt, ...args) {
|
run(promptOrOptions, ...args) {
|
||||||
const output = execSync(
|
let command = `node ${this.bundlePath} --yolo`;
|
||||||
`node ${this.bundlePath} --yolo --prompt "${prompt}" ${args.join(' ')}`,
|
const execOptions = {
|
||||||
{
|
cwd: this.testDir,
|
||||||
cwd: this.testDir,
|
encoding: 'utf-8',
|
||||||
encoding: 'utf-8',
|
};
|
||||||
},
|
|
||||||
);
|
if (typeof promptOrOptions === 'string') {
|
||||||
|
command += ` --prompt "${promptOrOptions}"`;
|
||||||
|
} else if (
|
||||||
|
typeof promptOrOptions === 'object' &&
|
||||||
|
promptOrOptions !== null
|
||||||
|
) {
|
||||||
|
if (promptOrOptions.prompt) {
|
||||||
|
command += ` --prompt "${promptOrOptions.prompt}"`;
|
||||||
|
}
|
||||||
|
if (promptOrOptions.stdin) {
|
||||||
|
execOptions.input = promptOrOptions.stdin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
command += ` ${args.join(' ')}`;
|
||||||
|
|
||||||
|
const output = execSync(command, execOptions);
|
||||||
|
|
||||||
if (env.KEEP_OUTPUT === 'true') {
|
if (env.KEEP_OUTPUT === 'true') {
|
||||||
const testId = `${env.TEST_FILE_NAME.replace(
|
const testId = `${env.TEST_FILE_NAME.replace(
|
||||||
|
|
|
@ -184,7 +184,7 @@ export async function main() {
|
||||||
}
|
}
|
||||||
// If not a TTY, read from stdin
|
// If not a TTY, read from stdin
|
||||||
// This is for cases where the user pipes input directly into the command
|
// This is for cases where the user pipes input directly into the command
|
||||||
if (!process.stdin.isTTY) {
|
if (!process.stdin.isTTY && !input) {
|
||||||
input += await readStdin();
|
input += await readStdin();
|
||||||
}
|
}
|
||||||
if (!input) {
|
if (!input) {
|
||||||
|
|
Loading…
Reference in New Issue