From a121a7fa4eb28b141ce066b7bf52fbf1ad7348e7 Mon Sep 17 00:00:00 2001 From: BugDiver Date: Sat, 1 Jun 2019 15:58:48 +0530 Subject: [PATCH] Minor changes. --- launcher.js | 6 ++++-- src/loaders/ImplLoader.ts | 12 ++++++------ .../MessageProcessorFactoryTests.ts | 19 +++++++++++++++++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/launcher.js b/launcher.js index d867b5f..29161b7 100755 --- a/launcher.js +++ b/launcher.js @@ -57,7 +57,9 @@ let packageJson = ` "dependencies": { "gauge-ts": "latest", "ts-node": "latest", - "typescript": "latest", + "typescript": "latest" + }, + "devDependencies": { "@types/node": "latest" } } @@ -106,7 +108,7 @@ else if (process.argv[2] === "--start") { + `let runner = new GaugeRuntime();` + `runner.start();` var options = `{"experimentalDecorators": true,"emitDecoratorMetadata": true}` - var runner = cp.spawn('npx', ['ts-node', '-O', options, '-e', script], { + var runner = cp.spawn('npx', ["--no-install", 'ts-node', '-O', options, '-e', script], { env: process.env, silent: false, stdio: "inherit", diff --git a/src/loaders/ImplLoader.ts b/src/loaders/ImplLoader.ts index c8ba8ee..28a4058 100644 --- a/src/loaders/ImplLoader.ts +++ b/src/loaders/ImplLoader.ts @@ -4,20 +4,20 @@ import { Util } from "../utils/Util"; export class ImplLoader { - public async loadImplementations() { registry.clear(); hookRegistry.clear(); for (const file of Util.getListOfFiles()) { process.env.STEP_FILE_PATH = file; let c = await Util.importFile(file); - if (c.default && c.default.length == 0) { // Check if file contains Step decorator then only create a instance - try { + try { + if (c.default && c.default.length == 0) { let instance = new c.default(); this.updateRegsitry(file, instance); - }catch(error) { - console.error('Failed to create a instasnce of exported class from '+ file); } + } catch (error) { + error.message = `${error.message}. Step implemetations classes needs to be exported as default witout any constructor` + console.error(error); } } } @@ -26,4 +26,4 @@ export class ImplLoader { registry.setInstanceForMethodsIn(file, instance); hookRegistry.setInstanceForMethodsIn(file, instance) } -} \ No newline at end of file +} diff --git a/tests/processors/MessageProcessorFactoryTests.ts b/tests/processors/MessageProcessorFactoryTests.ts index 1c18596..8cdb008 100644 --- a/tests/processors/MessageProcessorFactoryTests.ts +++ b/tests/processors/MessageProcessorFactoryTests.ts @@ -25,19 +25,35 @@ describe('MessageProcessorFactory', () => { }) it('should load impl before loading files', async () => { - Util.getListOfFiles = jest.fn().mockReturnValue(['StepImpl.ts']); class Foo { constructor() { } } + Util.getListOfFiles = jest.fn().mockReturnValue(['StepImpl.ts']); Util.importFile = jest.fn().mockResolvedValue({ default: Foo }) let message = new gauge.messages.Message({ messageId: 0, messageType: gauge.messages.Message.MessageType.ExecutionStarting, executionStartingRequest: new gauge.messages.ExecutionStartingRequest() }) + console.error = jest.fn(); + let err = jest.spyOn(console, 'error'); await factory.process(message); + expect(err).toBeCalledTimes(0); + }) + it('should load impl before loading files which fails to create instance', async () => { + Util.getListOfFiles = jest.fn().mockReturnValue(['StepImpl.ts']); + Util.importFile = jest.fn().mockResolvedValue({ default: () => { } }) + let message = new gauge.messages.Message({ + messageId: 0, + messageType: gauge.messages.Message.MessageType.ExecutionStarting, + executionStartingRequest: new gauge.messages.ExecutionStartingRequest() + }) + console.error = jest.fn(); + let err = jest.spyOn(console, 'error'); + await factory.process(message); + expect(err).toHaveBeenCalled(); }) it('should process unsupport message', async () => { @@ -51,5 +67,4 @@ describe('MessageProcessorFactory', () => { expect(mockExit).toHaveBeenCalledWith(1); }) }) - })