forked from flix-tech/robotmate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
executable file
·101 lines (86 loc) · 3 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env node
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]]')
.option('conf')
.describe('conf', 'Botium configuration.')
.describe('jobs', 'Number of parallel executions to trigger.');
const parser = require('./lib/parser.js');
const runner = require('./lib/runner.js');
const run = (data, childTest) => {
const driver = new BotDriver();
const container = driver.BuildFluent().Start();
new runner.ConversationProcessor(container, data.fileName, data.conversation, data.lang).process();
container
.Stop()
.Clean()
.Exec()
.then(() => {
childTest.end();
})
.catch((error) => {
childTest.fail(error);
childTest.end();
});
};
const clean = () => {
rimraf.sync(new BotDriver().caps.TEMPDIR);
};
const report = () => {
const failures = tap.results.failures.length;
const testsFailed = tap.results.failures.length > 0;
const failedTests = (testsFailed) ? `${failures} failed, ` : '';
const passedTests = `${tap.results.count - failures} passed, `;
console.info();
console.info(`Conversations: ${failedTests} ${passedTests} ${tap.results.count} total`);
console.info(`Duration: ${(tap.time / 1000).toFixed(2)} seconds`);
if (testsFailed) {
console.error(`${failures} failed conversations:`.red);
tap.results.failures.forEach(x => console.error(x.name.red));
process.exit(1);
}
};
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);
});
});
});
} else {
const data = parser.parseString(fileContent, filePath);
tap.test(testName, (childTest) => {
run(data, childTest, this.timeout);
});
}
});
tap.tearDown(clean);
tap.tearDown(report);