Add tests for commandExecutor
This commit is contained in:
Родитель
7dc97a4e74
Коммит
e1e35c5743
|
@ -2,6 +2,17 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"protocol": "legacy",
|
||||
"name": "Attach to Process (Legacy Protocol)",
|
||||
"port": 5858,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/packages/*/out/**/*.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Launch Extensions",
|
||||
"type": "extensionHost",
|
||||
|
@ -29,7 +40,7 @@
|
|||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/packages/*/out/test/**/*.js"
|
||||
"${workspaceRoot}/packages/*/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "Watch"
|
||||
},
|
||||
|
@ -45,7 +56,7 @@
|
|||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/packages/*/out/test/**/*.js"
|
||||
"${workspaceRoot}/packages/*/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "Watch"
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"@types/node": "^6.0.40",
|
||||
"chai": "^4.0.2",
|
||||
"mocha": "3.2.0",
|
||||
"nyc": "^11.0.2",
|
||||
"typescript": "2.3.4"
|
||||
},
|
||||
"scripts": {
|
||||
|
@ -24,7 +25,8 @@
|
|||
"lint": "tslint --project .",
|
||||
"watch": "tsc -watch -p .",
|
||||
"clean": "rm -rf node_modules && rm -rf out",
|
||||
"test": "node ./node_modules/.bin/_mocha --recursive out/test"
|
||||
"test": "node ./node_modules/.bin/_mocha --recursive out/test",
|
||||
"coverage": "./node_modules/.bin/nyc npm test"
|
||||
},
|
||||
"main": "./out/src/"
|
||||
}
|
|
@ -56,7 +56,11 @@ export class CommandExecution {
|
|||
const timer = Observable.interval(1000);
|
||||
timerSubscriber = timer.subscribe(next => {
|
||||
if (cancellationToken.isCancellationRequested) {
|
||||
childProcess.kill();
|
||||
try {
|
||||
childProcess.kill();
|
||||
} catch (e) {
|
||||
// This is best effort, by the time we get here, the process might have been killed.
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
import { expect } from 'chai';
|
||||
|
||||
import { CliCommandExecutor, SfdxCommandBuilder } from '../../src/cli';
|
||||
|
||||
describe('CommandExecutor tests', () => {
|
||||
describe('Handle listeners on stdout and stderr', () => {
|
||||
it('Should pipe stdout', async () => {
|
||||
const execution = new CliCommandExecutor(
|
||||
new SfdxCommandBuilder().withArg('force').withArg('--help').build(),
|
||||
{}
|
||||
).execute();
|
||||
|
||||
let stdout = '';
|
||||
execution.stdoutSubject.subscribe(data => (stdout += data.toString()));
|
||||
let stderr = '';
|
||||
execution.stderrSubject.subscribe(data => (stderr += data.toString()));
|
||||
const exitCode = await new Promise<string>((resolve, reject) => {
|
||||
execution.processExitSubject.subscribe(
|
||||
data => {
|
||||
resolve(data.toString());
|
||||
},
|
||||
err => {
|
||||
reject(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
expect(exitCode).to.equal('0');
|
||||
expect(stdout).to.contain(
|
||||
'Usage: sfdx COMMAND [command-specific-options]'
|
||||
);
|
||||
expect(stderr).to.contain('');
|
||||
});
|
||||
|
||||
it('Should pipe stderr', async () => {
|
||||
const execution = new CliCommandExecutor(
|
||||
new SfdxCommandBuilder().withArg('force').withArg('--unknown').build(),
|
||||
{}
|
||||
).execute();
|
||||
|
||||
let stdout = '';
|
||||
execution.stdoutSubject.subscribe(data => (stdout += data.toString()));
|
||||
let stderr = '';
|
||||
execution.stderrSubject.subscribe(data => (stderr += data.toString()));
|
||||
const exitCode = await new Promise<string>((resolve, reject) => {
|
||||
execution.processExitSubject.subscribe(
|
||||
data => {
|
||||
resolve(data.toString());
|
||||
},
|
||||
err => {
|
||||
reject(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
expect(exitCode).to.not.equal('0');
|
||||
expect(stdout).to.contain('');
|
||||
expect(stderr).to.contain('Error: Unexpected flag --unknown');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -19,6 +19,7 @@
|
|||
"@types/path-exists": "^1.0.29",
|
||||
"chai": "^4.0.2",
|
||||
"mocha": "3.2.0",
|
||||
"nyc": "^11.0.2",
|
||||
"typescript": "2.3.4",
|
||||
"vscode": "1.1.0"
|
||||
},
|
||||
|
@ -64,4 +65,4 @@
|
|||
"portfinder": "1.0.12",
|
||||
"vscode-languageclient": "3.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"@types/path-exists": "^1.0.29",
|
||||
"chai": "^4.0.2",
|
||||
"mocha": "3.2.0",
|
||||
"nyc": "^11.0.2",
|
||||
"typescript": "2.3.4",
|
||||
"vscode": "1.1.0"
|
||||
},
|
||||
|
@ -78,4 +79,4 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче