Skip to content

Commit

Permalink
test with different versions of oclif
Browse files Browse the repository at this point in the history
  • Loading branch information
james-hu committed Mar 9, 2024
1 parent 63d40b2 commit 444ed4a
Show file tree
Hide file tree
Showing 29 changed files with 16,324 additions and 357 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/dist
test/simple-cli-prj/
test/simple-cli-prj*/
2 changes: 1 addition & 1 deletion .mocharc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spec:
- test/**/*.spec.ts
- test/*.spec.ts
require:
- source-map-support/register
- ts-node/register
98 changes: 50 additions & 48 deletions test/oclif-utils.int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,56 @@ function runWithinDir(dir: string): (cmd: string) => Promise<ProcessOutput> {
}

describe('OclifUtils used in test projects', () => {
describe('simple-cli-prj', () => {
const runWithinPrj = runWithinDir('test/simple-cli-prj');

before(async () => {
const outcome = await runWithinPrj('rm -rf node_modules && npm ci');
expect(outcome.exitCode).to.equal(0);
});

it('handles missing required arg', async () => {
const outcome = await runWithinPrj('./bin/run');
expect(outcome.exitCode).to.equal(2);
expect(outcome.stderr).to.contain('Missing 1 required arg');
});

it('handles missing required flag', async () => {
const outcome = await runWithinPrj('./bin/run me');
expect(outcome.exitCode).to.equal(2);
expect(outcome.stderr).to.contain('Missing required flag');
});

it('handles happy case', async () => {
const outcome = await runWithinPrj('./bin/run me --from myself');
expect(outcome.exitCode).to.equal(0);
expect(outcome.stdout).to.contain('Hello to me from myself');
});

it('handles happy case with --gen', async () => {
const outcome = await runWithinPrj('./bin/run me --from myself --gen');
expect(outcome.exitCode).to.equal(0);
expect(outcome.stdout).to.contain('simple-cli-prj me --from myself --gen');
});

for (const arg of ['-h', '--help']) {
it(`prints help when there is only ${arg}`, async () => {
const outcome = await runWithinPrj(`./bin/run ${arg}`);
for (const v of ['2', '3']) {
describe(`simple-cli-prj-v${v}`, () => {
const runWithinPrj = runWithinDir(`test/simple-cli-prj-v${v}`);

before(async () => {
const outcome = await runWithinPrj('rm -rf node_modules && npm ci');
expect(outcome.exitCode).to.equal(0);
expect(outcome.stdout).to.contain('USAGE');
expect(outcome.stdout).to.contain('ARGUMENTS');
expect(outcome.stdout).to.contain('FLAGS');
expect(outcome.stdout).to.contain('DESCRIPTION');
expect(outcome.stdout).to.contain('EXAMPLES');
});
}

it('does not print help when it is not the only argument', async () => {
const outcome = await runWithinPrj('./bin/run me -h');
expect(outcome.exitCode).to.equal(2);
expect(outcome.stderr).to.contain('Missing required flag');
});
});

it('handles missing required arg', async () => {
const outcome = await runWithinPrj('./bin/run');
expect(outcome.exitCode).to.equal(2);
expect(outcome.stderr).to.contain('Missing 1 required arg');
});

it('handles missing required flag', async () => {
const outcome = await runWithinPrj('./bin/run me');
expect(outcome.exitCode).to.equal(2);
expect(outcome.stderr).to.contain('Missing required flag');
});

it('handles happy case', async () => {
const outcome = await runWithinPrj('./bin/run me --from myself');
expect(outcome.exitCode).to.equal(0);
expect(outcome.stdout).to.contain('Hello to me from myself');
});

it('handles happy case with --gen', async () => {
const outcome = await runWithinPrj('./bin/run me --from myself --gen');
expect(outcome.exitCode).to.equal(0);
expect(outcome.stdout).to.contain('simple-cli-prj me --from myself --gen');
});

for (const arg of ['-h', '--help']) {
it(`prints help when there is only ${arg}`, async () => {
const outcome = await runWithinPrj(`./bin/run ${arg}`);
expect(outcome.exitCode).to.equal(0);
expect(outcome.stdout).to.contain('USAGE');
expect(outcome.stdout).to.contain('ARGUMENTS');
expect(outcome.stdout).to.contain('FLAGS');
expect(outcome.stdout).to.contain('DESCRIPTION');
expect(outcome.stdout).to.contain('EXAMPLES');
});
}

it('does not print help when it is not the only argument', async () => {
const outcome = await runWithinPrj('./bin/run me -h');
expect(outcome.exitCode).to.equal(2);
expect(outcome.stderr).to.contain('Missing required flag');
});
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/.nyc_output
/dist
/lib
/package-lock.json
/tmp
/yarn.lock
node_modules
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 444ed4a

Please sign in to comment.