balena-cli/tests/commands/version.spec.ts
Scott Lowe 1325fb8c9a Use helpers version of cleanOutput in tests.
Simplify expect semantics in tests.

Change-type: patch
Signed-off-by: Scott Lowe <scott@balena.io>
2019-11-15 12:01:56 +01:00

38 lines
1.0 KiB
TypeScript

import { expect } from 'chai';
import * as fs from 'fs';
import { runCommand } from '../helpers';
const packageJSON = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const nodeVersion = process.version.startsWith('v')
? process.version.slice(1)
: process.version;
describe('balena version', function() {
it('should print the installed version of the CLI', async () => {
const { out } = await runCommand('version');
expect(out.join('')).to.equal(`${packageJSON.version}\n`);
});
it('should print additional version information with the -a flag', async () => {
const { out } = await runCommand('version -a');
expect(out.join('')).to.equal(
`balena-cli version "${packageJSON.version}"
Node.js version "${nodeVersion}"
`,
);
});
it('should print version information as JSON with the the -j flag', async () => {
const { out } = await runCommand('version -j');
const json = JSON.parse(out.join(''));
expect(json).to.deep.equal({
'balena-cli': packageJSON.version,
'Node.js': nodeVersion,
});
});
});