Skip to content

Commit

Permalink
Fixed a few test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
MilapNaik committed Feb 2, 2024
1 parent 13f2ca4 commit 2d13441
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
31 changes: 19 additions & 12 deletions src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function execSync(command: string) {
const output = childProcess.execSync(command, { cwd: tempDir });
process.stdout.write(output);
return output;
// return childProcess.execSync(command, { stdio: 'inherit', cwd: tempDir });
}
describe('cli', () => {
before(function build() {
Expand All @@ -33,14 +32,15 @@ describe('cli', () => {
fsExtra.emptyDirSync(tempDir);
//most tests depend on a manifest file existing, so write an empty one
fsExtra.outputFileSync(`${rootDir}/manifest`, '');
sinon.restore();
});
afterEach(() => {
fsExtra.removeSync(tempDir);
sinon.restore();
});

it('Successfully runs prepublishToStaging', () => {
//make the files
// fsExtra.outputFileSync(`${rootDir}/manifest`, '');
fsExtra.outputFileSync(`${rootDir}/source/main.brs`, '');

expect(() => {
Expand Down Expand Up @@ -175,16 +175,14 @@ describe('cli', () => {
password: '5536',
outFile: 'roku-deploy-test'
});
console.log(stub.getCall(0).args[0]);

expect(
stub.getCall(0).args[0]
).to.eql({
pathToPkg: 'path_to_pkg',
stub.getCall(0).args
).to.eql(['path_to_pkg', {
host: '1.2.3.4',
password: '5536',
outFile: 'roku-deploy-test'
});//TODO: fix!
}]);
});

it('Deploys a package', async () => {
Expand Down Expand Up @@ -284,7 +282,7 @@ describe('cli', () => {
it('Prints device info to console', async () => {
let consoleOutput = '';
sinon.stub(console, 'log').callsFake((...args) => {
consoleOutput += args.join(' ') + '\n'; //TODO: I don't think this is accurately adding a new line
consoleOutput += args.join(' ') + '\n';
});
sinon.stub(rokuDeploy, 'getDeviceInfo').returns(Promise.resolve({
'device-id': '1234',
Expand All @@ -293,10 +291,19 @@ describe('cli', () => {
await new GetDeviceInfoCommand().run({
host: '1.2.3.4'
});
expect(consoleOutput.trim()).to.eql(
'{"device-id":"1234","serial-number":"abcd"}'
);
}); //TODO: This passes when it is it.only, but fails in the larger test suite?

// const consoleOutputObject: Record<string, string> = {
// 'device-id': '1234',
// 'serial-number': 'abcd'
// };

expect(consoleOutput).to.eql([
'Name Value ',
'---------------------------',
'device-id 1234 ',
'serial-number abcd \n'
].join('\n'));
});

it('Gets dev id', async () => {
const stub = sinon.stub(rokuDeploy, 'getDevId').callsFake(async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/GetDeviceInfoCommand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { rokuDeploy } from '../index';
import { rokuDeploy, toTable } from '../index';

export class GetDeviceInfoCommand {
async run(args) {
const outputPath = await rokuDeploy.getDeviceInfo({
host: args.host
});
console.log(JSON.stringify(outputPath));
console.log(toTable(outputPath));
}
}
14 changes: 14 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,17 @@ export function standardizePathPosix(stringParts, ...expressions: any[]) {
result.join('')
);
}

export function toTable(deviceInfo: Record<string, string>) {
const margin = 5;
const keyWidth = Math.max(...Object.keys(deviceInfo).map(x => x.length)) + margin;
const valueWidth = Math.max(...Object.values(deviceInfo).map(x => (x ?? '')?.toString().length)) + margin;
let table = [];
table.push('Name'.padEnd(keyWidth, ' ') + 'Value'.padEnd(keyWidth, ' '));
table.push('-'.repeat(keyWidth + valueWidth));
for (const [key, value] of Object.entries(deviceInfo)) {
table.push(key.padEnd(keyWidth, ' ') + value?.toString().padEnd(keyWidth, ' '));
}

return table.join('\n');
} //TODO: Create a test for this function

0 comments on commit 2d13441

Please sign in to comment.