Skip to content

Commit

Permalink
Merge pull request #15 from lleites/better_command_parsing
Browse files Browse the repository at this point in the history
Better command parsing
  • Loading branch information
Leandro Leites Barrios authored Feb 18, 2020
2 parents 68e4f14 + b3e4f10 commit a6c9949
Show file tree
Hide file tree
Showing 7 changed files with 1,180 additions and 693 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.nyc_output
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This project is based on [Botium](https://botium.atlassian.net/wiki/spaces/BOTIU

1. Start by downloading and installing [NodeJs](https://nodejs.org/en/download/)
2. Open your terminal (Mac, Linux, ...) or Prompt (Windows)
3. Execute the following command in the terminal: `npm install -g "git+https://[email protected]/flix-tech/robotmate.git#v0.12.0"`
3. Execute the following command in the terminal: `npm install -g "git+https://[email protected]/flix-tech/robotmate.git#v0.13.0"`


### Another way
Expand Down
1,750 changes: 1,116 additions & 634 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
{
"name": "robot-mate",
"version": "0.12.0",
"version": "0.13.0",
"description": "A format to test robots",
"main": "lib/parser.js",
"bin": {
"rmrun": "run.js",
"rmparse": "parse.js"
},
"scripts": {
"test": "mocha",
"test": "tap test",
"lint": "eslint --ignore-path .gitignore ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"acorn": "^6.4.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.3",
"acorn": "^6.1.1"
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.20.1"
},
"dependencies": {
"botium-connector-dialogflow": "^0.0.8",
"botium-core": "^1.5.1",
"colors": "^1.3.3",
"csv-parser": "^2.3.0",
"botium-connector-dialogflow": "^0.0.13",
"botium-connector-echo": "0.0.4",
"botium-core": "^1.8.1",
"colors": "^1.4.0",
"dev-null": "^0.1.1",
"dialogflow": "^0.10.1",
"dialogflow": "^1.2.0",
"klaw-sync": "^6.0.0",
"mocha": "^5.2.0",
"mustache": "^3.0.1",
"rimraf": "^2.6.3",
"rimraf": "^2.7.1",
"tap": "^13.1.11",
"yargs": "^12.0.5"
}
Expand Down
94 changes: 49 additions & 45 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
const { BotDriver } = require('botium-core');
const fs = require('fs');
const tap = require('tap');
const csv = require('csv-parser');
const mustache = require('mustache');
const klawSync = require('klaw-sync');
const rimraf = require('rimraf');
const devnull = require('dev-null');
require('colors');
const { argv } = require('yargs')
.usage('Usage: $0 <path> --conf <conf> [--jobs [num]] [--retries [num]]')
.option('conf')
const { argv } = require('yargs').strict()
.usage('Usage: $0 <path> [--conf conf] [--jobs num] [--retries num]')
.describe('conf', 'Botium configuration.')
.nargs('conf', 1)
.describe('jobs', 'Number of parallel executions to trigger.')
.describe('retries', 'Number of retries to perform when a conversation fails.');
.nargs('jobs', 1)
.describe('retries', 'Number of retries to perform when a conversation fails.')
.nargs('retries', 1);

const parser = require('./lib/parser.js');
const runner = require('./lib/runner.js');

const maxRetries = argv.retries || 0;
const run = (data, childTest, retries = 0) => {
const driver = new BotDriver();

const run = (driver, data, childTest, maxRetries, retries = 0) => {
const container = driver.BuildFluent().Start();

new runner.ConversationProcessor(container, data.fileName, data.conversation, data.lang).process();
Expand All @@ -35,7 +34,7 @@ const run = (data, childTest, retries = 0) => {
})
.catch((error) => {
if (retries < maxRetries) {
run(data, childTest, retries + 1);
run(driver, data, childTest, maxRetries, retries + 1);
} else {
childTest.fail(error);
childTest.end();
Expand Down Expand Up @@ -64,43 +63,48 @@ const report = () => {
}
};

const conversationsPath = argv._[0] || '.';
process.env.BOTIUM_CONFIG = argv.conf || 'botium.json';

const files = conversationsPath.endsWith('.rmc') ? [conversationsPath]
: klawSync(conversationsPath)
.filter(file => file.path.endsWith('.rmc'))
.map(file => file.path);

tap.jobs = argv.jobs || 1;
tap.pipe(devnull());

files.forEach((filePath) => {
const testName = filePath;
const fileContent = fs.readFileSync(filePath, 'utf-8');
const csvFilePath = filePath.replace('.rmc', '.csv');
if (fs.existsSync(csvFilePath)) {
const csvRows = [];
fs.createReadStream(csvFilePath)
.pipe(csv({ delimiter: ',' }))
.on('data', csvRow => csvRows.push(csvRow))
.on('end', () => {
csvRows.forEach((csvRow, index) => {
const processedFileContent = mustache.render(fileContent, csvRow);
const data = parser.parseString(processedFileContent, filePath);
tap.test(`${testName} CSV Line : ${index + 1}`, (childTest) => {
data.fileName = `${data.fileName}:${index + 1}`;
run(data, childTest, this.timeout);
});
});
});

const BOTIUM_CONF_DEFAULT = 'botium.json';
const main = () => {
const conversationsPath = argv._[0] || '.';

if (argv.conf) {
if (fs.existsSync(argv.conf)) {
process.env.BOTIUM_CONFIG = argv.conf;
} else {
console.error(`Configuration file ${argv.conf} does not exist`);
process.exit(1);
}
} else {
console.info(`No configuration provided, using: ${BOTIUM_CONF_DEFAULT}`);
process.env.BOTIUM_CONFIG = BOTIUM_CONF_DEFAULT;
}
let driver = null;
try {
driver = new BotDriver();
} catch (e) {
console.error('There is a problem with your Botium configuration, please check.');
throw e;
}


const files = conversationsPath.endsWith('.rmc') ? [conversationsPath]
: klawSync(conversationsPath)
.filter(file => file.path.endsWith('.rmc'))
.map(file => file.path);
const maxRetries = argv.retries || 0;
tap.jobs = argv.jobs || 1;
tap.pipe(devnull());
files.forEach((filePath) => {
const testName = filePath;
const fileContent = fs.readFileSync(filePath, 'utf-8');
const data = parser.parseString(fileContent, filePath);
tap.test(testName, (childTest) => {
run(data, childTest, this.timeout);
run(driver, data, childTest, maxRetries);
});
}
});
});
tap.tearDown(clean);
tap.tearDown(report);
};

tap.tearDown(clean);
tap.tearDown(report);
main();
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('tap').mochaGlobals();
const assert = require('assert');
const fs = require('fs');
const parser = require('../lib/parser.js');
Expand Down
1 change: 1 addition & 0 deletions test/test_runner.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('tap').mochaGlobals();
const assert = require('assert');
const parser = require('../lib/parser.js');
const { ConversationProcessor, DIALOGFLOW_CONSTANTS } = require('../lib/runner.js');
Expand Down

0 comments on commit a6c9949

Please sign in to comment.