Skip to content

Commit

Permalink
Minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
BugDiver committed Jun 1, 2019
1 parent 1b7f357 commit a121a7f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
6 changes: 4 additions & 2 deletions launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ let packageJson = `
"dependencies": {
"gauge-ts": "latest",
"ts-node": "latest",
"typescript": "latest",
"typescript": "latest"
},
"devDependencies": {
"@types/node": "latest"
}
}
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/loaders/ImplLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -26,4 +26,4 @@ export class ImplLoader {
registry.setInstanceForMethodsIn(file, instance);
hookRegistry.setInstanceForMethodsIn(file, instance)
}
}
}
19 changes: 17 additions & 2 deletions tests/processors/MessageProcessorFactoryTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -51,5 +67,4 @@ describe('MessageProcessorFactory', () => {
expect(mockExit).toHaveBeenCalledWith(1);
})
})

})

0 comments on commit a121a7f

Please sign in to comment.