Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal set of tests on the CLI #661

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import assert from 'node:assert/strict';
import { exec as execCb } from 'node:child_process';
import { promisify } from 'node:util';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const scriptPath = path.dirname(fileURLToPath(import.meta.url));
const root = path.resolve(scriptPath, '..');
const execOptions = { cwd: root };

async function strudy(params) {
const exec = promisify(execCb);
const cmd = `node --disable-warning=ExperimentalWarning strudy.js ${params}`;
try {
const { stdout, stderr } = await exec(cmd, execOptions);
return { stdout, stderr };
}
catch (err) {
const { stdout, stderr } = err;
return { stdout, stderr };
}
}

describe(`Strudy's CLI`, function () {
this.slow(5000);

it('reports usage help when asked', async function () {
const { stdout, stderr } = await strudy(`--help`);
assert.match(stdout, /^Usage: strudy \[options\] <report>/);
assert.deepEqual(stderr, '');
});

it('expects a report argument', async function () {
const { stdout, stderr } = await strudy(``);
assert.match(stderr, /error: missing required argument 'report'/);
assert.deepEqual(stdout, '');
});

it('reports an error when provided report does not exist', async function () {
const { stdout, stderr } = await strudy(`notareport`);
assert.match(stderr, /Could not find/);
assert.deepEqual(stdout, '');
});
});