Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Fix async problem in help-page command (#48)
Browse files Browse the repository at this point in the history
* Fix async problem in help-page command

* Adjust timeout and remove unnecessary tests

* Fix compilation error

* Fix faulty tests
  • Loading branch information
Florian Richter authored Jan 9, 2020
1 parent 970b742 commit 2a673fe
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 112 deletions.
16 changes: 7 additions & 9 deletions src/commands/help-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
*/

import { Command, flags } from '@oclif/command';
import { Command } from '@oclif/command';
import cli from 'cli-ux';

export default class HelpPage extends Command {
static description = 'Open the product page, which contains tutorials and links to all relevant resources';

static flags = {
help: flags.help({ char: 'h' })
};
static description = 'Display the product page, which contains tutorials and links to all relevant resources';

async run() {
this.log('Visit us at: ');
cli.url('https://developers.sap.com/topics/cloud-sdk.html', 'https://developers.sap.com/topics/cloud-sdk.html');
cli.open('https://developers.sap.com/topics/cloud-sdk.html');
this.log('Visit us at:');
this.log(' https://community.sap.com/topics/cloud-sdk');
this.log(' https://developers.sap.com/topics/cloud-sdk.html');

await cli.open('https://community.sap.com/topics/cloud-sdk');
}
}
2 changes: 1 addition & 1 deletion test/add-cds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Add CDS', () => {
expect(dbFiles).toContain('data-model.cds');
const srvFiles = fs.readdirSync(path.resolve(projectDir, 'srv'));
expect(srvFiles).toContain('cat-service.cds');
}, 10000);
}, 15000);

it('should detect and fail if there are conflicts', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'add-cds-conflicts');
Expand Down
29 changes: 0 additions & 29 deletions test/e2e.spec.ts

This file was deleted.

30 changes: 0 additions & 30 deletions test/help-page.spec.ts

This file was deleted.

82 changes: 39 additions & 43 deletions test/utils/generate-odata-client-util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,56 @@ import { Options } from 'yargs';
import { toBooleanFlag, toStringFlag } from '../../src/utils/generate-odata-client-util';

describe('Generate OData Client Utils', () => {
describe('Boolean option transformation from yarn to oclif.', () => {
it('should translate the description correctly', () => {
let yargsOption: Options = { describe: 'expectedDescription', default: false };
expect(toBooleanFlag(yargsOption).description).toBe('expectedDescription [default: false].');
it('should translate the description correctly', () => {
let yargsOption: Options = { describe: 'expectedDescription', default: false };
expect(toBooleanFlag(yargsOption).description).toBe('expectedDescription [default: false].');

yargsOption = { describe: 'expectedDescription', default: true };
expect(toBooleanFlag(yargsOption).description).toBe('expectedDescription [default: true].');
});
yargsOption = { describe: 'expectedDescription', default: true };
expect(toBooleanFlag(yargsOption).description).toBe('expectedDescription [default: true].');
});

it('should translate the alias correctly.', () => {
const yargsOption: Options = { alias: 'expectedAlias' };
expect(toBooleanFlag(yargsOption).char).toBe(yargsOption.alias);
});
it('should translate the alias correctly.', () => {
const yargsOption: Options = { alias: 'expectedAlias' };
expect(toBooleanFlag(yargsOption).char).toBe(yargsOption.alias);
});

it('should translate the required option correctly.', () => {
let yargsOption: Options = { requiresArg: false };
expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg);
it('should translate the required option correctly.', () => {
let yargsOption: Options = { requiresArg: false };
expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg);

yargsOption = { requiresArg: true };
expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg);
});
yargsOption = { requiresArg: true };
expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg);
});

it('should translate the default and allowNo option correctly.', () => {
let yargsOption: Options = { default: false };
expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default);
expect(toBooleanFlag(yargsOption).allowNo).toBe(yargsOption.default);
it('should translate the default and allowNo option correctly.', () => {
let yargsOption: Options = { default: false };
expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default);
expect(toBooleanFlag(yargsOption).allowNo).toBe(yargsOption.default);

yargsOption = { default: true };
expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default);
expect(toBooleanFlag(yargsOption).allowNo).toBe(yargsOption.default);
});
yargsOption = { default: true };
expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default);
expect(toBooleanFlag(yargsOption).allowNo).toBe(yargsOption.default);
});

describe('String option transformation from yarn to oclif.', () => {
it('should translate all string arguments correctly.', () => {
const yargsOption: Options = { alias: 'expectedAlias', description: 'expectedDescription' };
expect(toStringFlag(yargsOption).char).toBe(yargsOption.alias);
expect(toStringFlag(yargsOption).description).toBe(yargsOption.describe);
});
it('should translate all string arguments correctly.', () => {
const yargsOption: Options = { alias: 'expectedAlias', description: 'expectedDescription' };
expect(toStringFlag(yargsOption).char).toBe(yargsOption.alias);
expect(toStringFlag(yargsOption).description).toBe(yargsOption.describe);
});

it('should translate the default option correctly.', () => {
let yargsOption: Options = { default: false };
expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default);
it('should translate the default option correctly.', () => {
let yargsOption: Options = { default: false };
expect(toStringFlag(yargsOption).default).toBe(yargsOption.default);

yargsOption = { default: true };
expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default);
});
yargsOption = { default: true };
expect(toStringFlag(yargsOption).default).toBe(yargsOption.default);
});

it('should translate the required option correctly.', () => {
let yargsOption: Options = { requiresArg: false };
expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg);
it('should translate the required option correctly.', () => {
let yargsOption: Options = { requiresArg: false };
expect(toStringFlag(yargsOption).required).toBe(yargsOption.requiresArg);

yargsOption = { requiresArg: true };
expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg);
});
yargsOption = { requiresArg: true };
expect(toStringFlag(yargsOption).required).toBe(yargsOption.requiresArg);
});
});

0 comments on commit 2a673fe

Please sign in to comment.