From 2a673fe2d7629bf59578d524cc88e2abb8485ae7 Mon Sep 17 00:00:00 2001 From: Florian Richter Date: Thu, 9 Jan 2020 15:34:18 +0100 Subject: [PATCH] Fix async problem in help-page command (#48) * Fix async problem in help-page command * Adjust timeout and remove unnecessary tests * Fix compilation error * Fix faulty tests --- src/commands/help-page.ts | 16 ++-- test/add-cds.spec.ts | 2 +- test/e2e.spec.ts | 29 ------- test/help-page.spec.ts | 30 ------- test/utils/generate-odata-client-util.spec.ts | 82 +++++++++---------- 5 files changed, 47 insertions(+), 112 deletions(-) delete mode 100644 test/e2e.spec.ts delete mode 100644 test/help-page.spec.ts diff --git a/src/commands/help-page.ts b/src/commands/help-page.ts index dc5ea569..773d11e1 100644 --- a/src/commands/help-page.ts +++ b/src/commands/help-page.ts @@ -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'); } } diff --git a/test/add-cds.spec.ts b/test/add-cds.spec.ts index ea135bf2..0d12461d 100644 --- a/test/add-cds.spec.ts +++ b/test/add-cds.spec.ts @@ -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'); diff --git a/test/e2e.spec.ts b/test/e2e.spec.ts deleted file mode 100644 index e4b74a5f..00000000 --- a/test/e2e.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -/*! - * Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. - */ - -describe('The whole enchilada', () => { - it('should setup and deploy a new project from scratch', () => { - expect(true).toBeTruthy(); - }); - - it('should setup and deploy an existing express app', () => { - expect(true).toBe(true); - }); - - it('should setup and deploy an existing nest app', () => { - expect(true).toBe(true); - }); - - it('should setup and deploy a new project from scratch with approuter', () => { - expect(true).toBeTruthy(); - }); - - it('should setup and deploy an existing express app with approuter', () => { - expect(true).toBe(true); - }); - - it('should setup and deploy an existing nest app with approuter', () => { - expect(true).toBe(true); - }); -}); diff --git a/test/help-page.spec.ts b/test/help-page.spec.ts deleted file mode 100644 index 2e01ecc7..00000000 --- a/test/help-page.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -/*! - * Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. - */ - -const url = jest.fn(); -const openSpy = jest.fn(); -jest.mock('cli-ux', () => { - // Mocking needs to happen before the command is imported - const cli = jest.requireActual('cli-ux'); - return { - ...cli, - default: { - ...cli.default, - url, - open: openSpy - } - }; -}); - -import HelpPage from '../src/commands/help-page'; - -describe('Help Page', () => { - it('should display the link and open the SDK website', async () => { - await HelpPage.run(); - - const helpPageUrl = 'https://developers.sap.com/topics/cloud-sdk.html'; - expect(url).toHaveBeenCalledWith(helpPageUrl, helpPageUrl); - expect(openSpy).toHaveBeenCalledWith(helpPageUrl); - }); -}); diff --git a/test/utils/generate-odata-client-util.spec.ts b/test/utils/generate-odata-client-util.spec.ts index 1491c108..6f8d814b 100644 --- a/test/utils/generate-odata-client-util.spec.ts +++ b/test/utils/generate-odata-client-util.spec.ts @@ -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); }); });