This commit is contained in:
JuanAr 2018-08-08 15:16:45 -03:00
Родитель b0ff5f5cbc
Коммит b812c426ca
26 изменённых файлов: 427 добавлений и 441 удалений

Просмотреть файл

@ -11,7 +11,7 @@ indent_size=2
[*.js.map]
indent_style=space
indent_size=2
indent_size=4
[{.analysis_options,*.yml,*.yaml}]
indent_style=space

Просмотреть файл

@ -16,6 +16,6 @@ class LUIS {
this.patternAnyEntities = [];
this.prebuiltEntities = [];
}
};
}
module.exports = LUIS;

Просмотреть файл

@ -24,6 +24,6 @@ class parserObject {
this.qnaJsonStructure = new QnA();
this.qnaAlterations = new qnaAlterations.qnaAlterations();
}
};
}
module.exports = parserObject;

Просмотреть файл

@ -13,6 +13,6 @@ class QnA {
this.urls = urls?urls:[];
this.qnaList = qnaList?qnaList:[];
}
};
}
module.exports = QnA;

Просмотреть файл

@ -25,6 +25,6 @@ class qnaList {
this.questions = questions?questions:[];
this.metadata = metadata?metadata:[];
}
};
}
module.exports = qnaList;

Просмотреть файл

@ -13,6 +13,6 @@ class qnaMetaData {
this.name = name?name:'';
this.value = value?value:'';
}
};
}
module.exports = qnaMetaData;

Просмотреть файл

@ -61,6 +61,7 @@ const helpers = {
let sectionsInFile = [];
let currentSectionType = null; //PARSERCONSTS
let inQnAAnswer = false;
let lineIndex = 0;
for(lineIndex in linesInFile) {
let currentLine = linesInFile[lineIndex].trim();
// QnA answer can be multi-line markdown. So (re)set the in answer flag
@ -129,7 +130,6 @@ const helpers = {
if(currentLine.toLowerCase().includes(':')) {
// get entity name and type
let entityDef = currentLine.replace(PARSERCONSTS.ENTITY, '').split(':');
let entityName = entityDef[0];
let entityType = entityDef[1];
// is entityType a phraseList?
if(entityType.trim().toLowerCase().includes('phraselist') || entityType.trim().toLowerCase().includes('qna-alterations')) {
@ -204,28 +204,28 @@ const helpers = {
var validateAndPushCurrentBuffer = function(previousSection, sectionsInFile, currentSectionType, lineIndex, log) {
previousSection = helpers.sanitizeNewLines(previousSection);
switch(currentSectionType) {
case PARSERCONSTS.INTENT:
// warn if there isnt at least one utterance in an intent
if(previousSection.split(NEWLINE).length === 1) {
++lineIndex;
if(previousSection.split(NEWLINE)[0].includes('?')) {
throw(new exception(retCode.errorCode.INVALID_LINE, 'Line #' + lineIndex + ': [ERR] No answer found for question: ' + previousSection.split(NEWLINE)[0]));
} else {
if(log) process.stdout.write(chalk.yellow('Line #' + lineIndex + ': [WARN] No utterances found for intent: ' + previousSection.split(NEWLINE)[0] + NEWLINE));
}
--lineIndex;
case PARSERCONSTS.INTENT:
// warn if there isnt at least one utterance in an intent
if(previousSection.split(NEWLINE).length === 1) {
++lineIndex;
if(previousSection.split(NEWLINE)[0].includes('?')) {
throw(new exception(retCode.errorCode.INVALID_LINE, 'Line #' + lineIndex + ': [ERR] No answer found for question: ' + previousSection.split(NEWLINE)[0]));
} else {
if(log) process.stdout.write(chalk.yellow('Line #' + lineIndex + ': [WARN] No utterances found for intent: ' + previousSection.split(NEWLINE)[0] + NEWLINE));
}
sectionsInFile.push(previousSection);
break;
case PARSERCONSTS.ENTITY:
// warn if there isnt at least one synonym for a list entity
if(previousSection.split(NEWLINE).length === 1) {
++lineIndex;
if(log) process.stdout.write(chalk.yellow('Line #' + lineIndex + ': [WARN] No synonyms list found for list entity:' + previousSection.split(NEWLINE)[0] + NEWLINE));
--lineIndex;
}
sectionsInFile.push(previousSection);
break;
--lineIndex;
}
sectionsInFile.push(previousSection);
break;
case PARSERCONSTS.ENTITY:
// warn if there isnt at least one synonym for a list entity
if(previousSection.split(NEWLINE).length === 1) {
++lineIndex;
if(log) process.stdout.write(chalk.yellow('Line #' + lineIndex + ': [WARN] No synonyms list found for list entity:' + previousSection.split(NEWLINE)[0] + NEWLINE));
--lineIndex;
}
sectionsInFile.push(previousSection);
break;
}
return sectionsInFile;
};

Просмотреть файл

@ -8,7 +8,7 @@ const fParser = require('../lib/parser');
const chalk = require('chalk');
const retCode = require('../lib/enums/CLI-errors');
const cmdEnum = require('../lib/enums/parsecommands');
program.Command.prototype.unknownOption = function (flag) {
program.Command.prototype.unknownOption = function () {
process.stderr.write(chalk.default.redBright(`\n Unknown arguments: ${process.argv.slice(2).join(' ')}\n`));
program.help();
};
@ -28,20 +28,20 @@ program
.option('--verbose', '[Optional] Get verbose messages from parser')
.parse(process.argv);
if (process.argv.length < 4) {
if (process.argv.length < 4) {
program.help();
} else {
if (!program.in && !program.lu_folder) {
process.stderr.write(chalk.default.redBright(`\n No .lu file or folder specified.\n`));
program.help();
} else {
if (!program.in && !program.lu_folder) {
process.stderr.write(chalk.default.redBright(`\n No .lu file or folder specified.\n`));
program.help();
}
fParser.handleFile(program, cmdEnum.luis)
.then(function(){
process.exit(retCode.errorCode.SUCCESS);
})
.catch(function(err) {
process.stderr.write(chalk.default.redBright(err.text + '\n'));
process.stderr.write(chalk.default.redBright('Stopping further processing. \n'));
process.exit(err.errCode);
});
}
fParser.handleFile(program, cmdEnum.luis)
.then(function () {
process.exit(retCode.errorCode.SUCCESS);
})
.catch(function (err) {
process.stderr.write(chalk.default.redBright(err.text + '\n'));
process.stderr.write(chalk.default.redBright('Stopping further processing. \n'));
process.exit(err.errCode);
});
}

Просмотреть файл

@ -8,7 +8,7 @@ const fParser = require('../lib/parser');
const chalk = require('chalk');
const retCode = require('../lib/enums/CLI-errors');
const cmdEnum = require('../lib/enums/parsecommands');
program.Command.prototype.unknownOption = function (flag) {
program.Command.prototype.unknownOption = function () {
process.stderr.write(chalk.default.redBright(`\n Unknown arguments: ${process.argv.slice(2).join(' ')}\n`));
program.help();
};
@ -25,20 +25,20 @@ program
.option('--verbose', '[Optional] Get verbose messages from parser')
.parse(process.argv);
if (process.argv.length < 4) {
if (process.argv.length < 4) {
program.help();
} else {
if (!program.in && !program.lu_folder) {
process.stderr.write(chalk.default.redBright(`\n No .lu file or folder specified.\n`));
program.help();
} else {
if (!program.in && !program.lu_folder) {
process.stderr.write(chalk.default.redBright(`\n No .lu file or folder specified.\n`));
program.help();
}
fParser.handleFile(program, cmdEnum.qna)
.then(function(){
process.exit(retCode.errorCode.SUCCESS);
})
.catch(function(err) {
process.stderr.write(chalk.default.redBright(err.text + '\n'));
process.stderr.write(chalk.default.redBright('Stopping further processing. \n'));
process.exit(err.errCode);
});
}
fParser.handleFile(program, cmdEnum.qna)
.then(function () {
process.exit(retCode.errorCode.SUCCESS);
})
.catch(function (err) {
process.stderr.write(chalk.default.redBright(err.text + '\n'));
process.stderr.write(chalk.default.redBright('Stopping further processing. \n'));
process.exit(err.errCode);
});
}

Просмотреть файл

@ -5,8 +5,7 @@
*/
const program = require('commander');
const chalk = require('chalk');
const retCode = require('../lib/enums/CLI-errors');
program.Command.prototype.unknownOption = function (flag) {
program.Command.prototype.unknownOption = function () {
process.stderr.write(chalk.default.redBright(`\n Unknown arguments: ${process.argv.slice(2).join(' ')}\n`));
program.help();
};
@ -19,8 +18,8 @@ program
.alias('toqna')
.parse(process.argv);
const commands = ['toluis', 'toqna']
if (!commands.includes(process.argv[2].toLowerCase())) {
process.stderr.write(chalk.default.redBright(`\n Unknown command: ${process.argv.slice(2).join(' ')}\n`));
program.help();
}
const commands = ['toluis', 'toqna']
if (!commands.includes(process.argv[2].toLowerCase())) {
process.stderr.write(chalk.default.redBright(`\n Unknown command: ${process.argv.slice(2).join(' ')}\n`));
program.help();
}

Просмотреть файл

@ -7,7 +7,7 @@ const program = require('commander');
const chalk = require('chalk');
const toLU = require('../lib/toLU');
const retCode = require('../lib/enums/CLI-errors');
program.Command.prototype.unknownOption = function (flag) {
program.Command.prototype.unknownOption = function () {
process.stderr.write(chalk.default.redBright(`\n Unknown arguments: ${process.argv.slice(2).join(' ')}\n`));
program.help();
};
@ -24,20 +24,20 @@ program
.option('-s, --skip_header', '[Optional] Generate .lu file without the header comment')
.parse(process.argv);
if (process.argv.length < 4) {
if (process.argv.length < 4) {
program.help();
} else {
if (!program.LUIS_File && !program.QNA_FILE && !program.QNA_ALTERATION_FILE) {
process.stderr.write(chalk.default.redBright(`\n No LUIS input file or QnA Maker JSON or QnA Alteration file specified.`));
program.help();
} else {
if (!program.LUIS_File && !program.QNA_FILE && !program.QNA_ALTERATION_FILE) {
process.stderr.write(chalk.default.redBright(`\n No LUIS input file or QnA Maker JSON or QnA Alteration file specified.`));
program.help();
}
toLU.generateMarkdown(program)
.then(function(){
process.exit(retCode.errorCode.SUCCESS);
})
.catch(function(err) {
process.stderr.write(chalk.default.redBright(err.text + '\n'));
process.stderr.write(chalk.default.redBright('Stopping further processing. \n'));
process.exit(err.errCode);
});
}
toLU.generateMarkdown(program)
.then(function () {
process.exit(retCode.errorCode.SUCCESS);
})
.catch(function (err) {
process.stderr.write(chalk.default.redBright(err.text + '\n'));
process.stderr.write(chalk.default.redBright('Stopping further processing. \n'));
process.exit(err.errCode);
});
}

Просмотреть файл

@ -7,7 +7,7 @@ const program = require('commander');
const chalk = require('chalk');
const translate = require('../lib/translate');
const retCode = require('../lib/enums/CLI-errors');
program.Command.prototype.unknownOption = function (flag) {
program.Command.prototype.unknownOption = function () {
process.stderr.write(chalk.default.redBright(`\n Unknown arguments: ${process.argv.slice(2).join(' ')}\n`));
program.help();
};
@ -28,25 +28,24 @@ program
.option('--verbose', '[Optional] Get verbose messages from parser')
.parse(process.argv);
if (!program.in && !program.lu_folder) {
process.stderr.write(chalk.default.redBright(`\n No .lu file or folder specified.\n`));
program.help();
}
if(!program.translate_key) {
process.stderr.write(chalk.default.redBright(`\n No translate key provided.\n`));
program.help();
}
if(!program.to_lang) {
process.stderr.write(chalk.default.redBright(`\n No target language provided.\n`));
program.help();
}
translate.translateContent(program)
.then(function(){
process.exit(retCode.errorCode.SUCCESS);
})
.catch(function(err) {
process.stderr.write(chalk.default.redBright(err.text + '\n'));
process.stderr.write(chalk.default.redBright('Stopping further processing. \n'));
process.exit(err.errCode);
});
if (!program.in && !program.lu_folder) {
process.stderr.write(chalk.default.redBright(`\n No .lu file or folder specified.\n`));
program.help();
}
if (!program.translate_key) {
process.stderr.write(chalk.default.redBright(`\n No translate key provided.\n`));
program.help();
}
if (!program.to_lang) {
process.stderr.write(chalk.default.redBright(`\n No target language provided.\n`));
program.help();
}
translate.translateContent(program)
.then(function () {
process.exit(retCode.errorCode.SUCCESS);
})
.catch(function (err) {
process.stderr.write(chalk.default.redBright(err.text + '\n'));
process.stderr.write(chalk.default.redBright('Stopping further processing. \n'));
process.exit(err.errCode);
});

Просмотреть файл

@ -6,8 +6,8 @@
const program = require('commander');
const chalk = require('chalk');
const pjson = require('../package.json');
const retCode = require('../lib/enums/CLI-errors');
program.Command.prototype.unknownOption = function (flag) {
program.Command.prototype.unknownOption = function () {
process.stderr.write(chalk.default.redBright(`\n Unknown arguments: ${process.argv.slice(2).join(' ')}\n`));
program.help();
};
@ -21,8 +21,8 @@ program
.command('translate', 'Translate .lu files')
.alias('t')
.parse(process.argv);
const commands = ['parse', 'p', 'refresh', 'd', 'translate', 't'];
if (!commands.includes(process.argv[2].toLowerCase())) {
process.stderr.write(chalk.default.redBright(`\n Unknown command: ${process.argv.slice(2).join(' ')}\n`));
program.help();
}
const commands = ['parse', 'p', 'refresh', 'd', 'translate', 't'];
if (!commands.includes(process.argv[2].toLowerCase())) {
process.stderr.write(chalk.default.redBright(`\n Unknown command: ${process.argv.slice(2).join(' ')}\n`));
program.help();
}

Просмотреть файл

@ -17,7 +17,6 @@ const helperClass = require('./classes/hclasses');
const deepEqual = require('deep-equal');
const qna = require('./classes/qna');
const exception = require('./classes/exception');
const LUIS = require('./classes/LUIS');
const qnaAlterations = require('./classes/qnaAlterations');
const NEWLINE = require('os').EOL;
const parseFileContentsModule = {
@ -246,7 +245,7 @@ const parseFileContentsModule = {
if(blob.prebuiltEntities.length > 0) {
blob.prebuiltEntities.forEach(function(prebuiltEntity){
let prebuiltTypeExists = false;
for(fIndex in FinalLUISJSON.prebuiltEntities) {
for(let fIndex in FinalLUISJSON.prebuiltEntities) {
if(prebuiltEntity.type === FinalLUISJSON.prebuiltEntities[fIndex].type) {
// do we have all the roles? if not, merge the roles
prebuiltEntity.roles.forEach(function(role) {
@ -319,7 +318,7 @@ const mergeResults = function(blob, finalCollection, type) {
}
// add if this item if it does not already exist in final collection
let itemExists = false;
for(fIndex in finalCollection[type]) {
for(let fIndex in finalCollection[type]) {
if(deepEqual(finalCollection[type][fIndex],blobItem)){
itemExists = true;
break;
@ -635,13 +634,13 @@ const parseAndHandleIntent = function(parsedContent, chunkSplitByLine) {
if((utterance.indexOf('-') !== 0) &&
(utterance.indexOf('*') !== 0) &&
(utterance.indexOf('+') !== 0)) {
throw ({
errCode: retCode.errorCode.INVALID_UTTERANCE_DEF,
text: 'Utterance: "' + utterance + '" does not have list decoration. Prefix line with "-" or "+" or "*"'
})
}
throw ({
errCode: retCode.errorCode.INVALID_UTTERANCE_DEF,
text: 'Utterance: "' + utterance + '" does not have list decoration. Prefix line with "-" or "+" or "*"'
})
}
utterance = utterance.slice(1).trim();
// handle entities in the utterance
// handle entities in the utterance
if(utterance.includes("{")) {
let entityRegex = new RegExp(/\{(.*?)\}/g);
let entitiesFound = utterance.match(entityRegex);
@ -739,33 +738,34 @@ const parseAndHandleIntent = function(parsedContent, chunkSplitByLine) {
const parseURLOrFileRef = function(parsedContent, type, chunkSplitByLine) {
let urlRef_regex = chunkSplitByLine[0].trim().replace(type, '').split(/\(['"](.*?)['"]\)/g);
switch(type) {
case PARSERCONSTS.URLREF:
if(urlRef_regex.length !== 3 || urlRef_regex[1].trim() === '') {
throw(new exception(retCode.errorCode.INVALID_URL_REF, '[ERROR]: ' + 'Invalid URL Ref: ' + chunkSplitByLine[0]));
}
parsedContent.qnaJsonStructure.urls.push(urlRef_regex[1]);
case PARSERCONSTS.URLREF:
if(urlRef_regex.length !== 3 || urlRef_regex[1].trim() === '') {
throw(new exception(retCode.errorCode.INVALID_URL_REF, '[ERROR]: ' + 'Invalid URL Ref: ' + chunkSplitByLine[0]));
}
parsedContent.qnaJsonStructure.urls.push(urlRef_regex[1]);
break;
case PARSERCONSTS.FILEREF:
if(urlRef_regex.length !== 3 || urlRef_regex[1].trim() === '') {
throw(new exception(retCode.errorCode.INVALID_LU_FILE_REF, '[ERROR]: ' + 'Invalid LU File Ref: ' + chunkSplitByLine[0]));
}
parsedContent.additionalFilesToParse.push(urlRef_regex[1]);
case PARSERCONSTS.FILEREF:
if(urlRef_regex.length !== 3 || urlRef_regex[1].trim() === '') {
throw(new exception(retCode.errorCode.INVALID_LU_FILE_REF, '[ERROR]: ' + 'Invalid LU File Ref: ' + chunkSplitByLine[0]));
}
parsedContent.additionalFilesToParse.push(urlRef_regex[1]);
break;
case PARSERCONSTS.URLORFILEREF:
let linkValueRegEx = new RegExp(/\(.*?\)/g);
let linkValueList = chunkSplitByLine[0].trim().match(linkValueRegEx);
let linkValue = linkValueList[0].replace('(','').replace(')','');
if(linkValue === '') {
throw(new exception(retCode.errorCode.INVALID_LU_FILE_REF, '[ERROR]: Invalid LU File Ref: ' + chunkSplitByLine[0]));
}
let parseUrl = url.parse(linkValue);
if (parseUrl.host || parseUrl.hostname) {
parsedContent.qnaJsonStructure.urls.push(linkValue);
} else {
parsedContent.additionalFilesToParse.push(linkValue);
}
case PARSERCONSTS.URLORFILEREF: {
let linkValueRegEx = new RegExp(/\(.*?\)/g);
let linkValueList = chunkSplitByLine[0].trim().match(linkValueRegEx);
let linkValue = linkValueList[0].replace('(', '').replace(')', '');
if (linkValue === '') {
throw (new exception(retCode.errorCode.INVALID_LU_FILE_REF, '[ERROR]: Invalid LU File Ref: ' + chunkSplitByLine[0]));
}
let parseUrl = url.parse(linkValue);
if (parseUrl.host || parseUrl.hostname) {
parsedContent.qnaJsonStructure.urls.push(linkValue);
} else {
parsedContent.additionalFilesToParse.push(linkValue);
}
break;
}
}
}
/**
* Helper function to add an item to collection if it does not exist

Просмотреть файл

@ -3,6 +3,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/*eslint no-console: ["error", { allow: ["log"] }] */
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');

Просмотреть файл

@ -31,7 +31,7 @@ const translateHelpers = {
let currentSectionType = '';
let data = '';
let lText = '';
for(lineIndex in linesInFile) {
for(let lineIndex in linesInFile) {
let currentLine = linesInFile[lineIndex].trim();
// is current line a comment?
if(currentLine.indexOf(PARSERCONSTS.COMMENT) === 0) {
@ -74,118 +74,119 @@ const translateHelpers = {
currentLine.indexOf('+') === 0 ) {
let listSeparator = '';
let content = '';
switch(currentSectionType) {
case PARSERCONSTS.INTENT:
// strip line of the list separator
listSeparator = currentLine.charAt(0);
content = currentLine.slice(1).trim();
let entitiesList = [];
// strip line off labelled entity values,mark pattern any entities as not to localize
if(content.includes('{')) {
const entityRegex = new RegExp(/\{(.*?)\}/g);
let entitiesFound = content.match(entityRegex);
let eStartIndex = -1;
let eEndIndex = -1;
entitiesFound.forEach(function(entity) {
let lEntity = entity.replace('{', '').replace('}', '');
let labelledValue = '';
// is this a labelled value?
if(lEntity.includes('=')) {
let entitySplit = lEntity.split('=');
if(entitySplit.length > 2) {
throw(new exception(retCode.errorCode.INVALID_INPUT, '[ERROR]: Nested entity references are not supported in utterance: ' + content));
switch (currentSectionType) {
case PARSERCONSTS.INTENT: {
// strip line of the list separator
listSeparator = currentLine.charAt(0);
content = currentLine.slice(1).trim();
let entitiesList = [];
// strip line off labelled entity values,mark pattern any entities as not to localize
if (content.includes('{')) {
const entityRegex = new RegExp(/\{(.*?)\}/g);
let entitiesFound = content.match(entityRegex);
let eStartIndex = -1;
let eEndIndex = -1;
entitiesFound.forEach(function (entity) {
let lEntity = entity.replace('{', '').replace('}', '');
let labelledValue = '';
// is this a labelled value?
if (lEntity.includes('=')) {
let entitySplit = lEntity.split('=');
if (entitySplit.length > 2) {
throw (new exception(retCode.errorCode.INVALID_INPUT, '[ERROR]: Nested entity references are not supported in utterance: ' + content));
}
lEntity = entitySplit[0].trim();
labelledValue = entitySplit[1].trim();
if (!labelledValue.includes(' ')) {
let updatedUtteranceLeft = content.substring(0, content.indexOf(entity));
let updatedUtteranceRight = content.substring(content.indexOf(entity) + entity.length);
content = updatedUtteranceLeft + labelledValue + updatedUtteranceRight;
eStartIndex = content.indexOf(labelledValue);
eEndIndex = eStartIndex + labelledValue.length - 1;
entitiesList.push(new helperClasses.entity(lEntity, labelledValue, eStartIndex, eEndIndex));
}
} else {
eStartIndex = content.indexOf(lEntity);
eEndIndex = eStartIndex + lEntity.length - 1;
entitiesList.push(new helperClasses.entity(lEntity, labelledValue, eStartIndex, eEndIndex));
}
});
}
try {
data = await translateHelpers.translateText(content, subscriptionKey, to_lang, src_lang);
} catch (err) {
throw (err);
}
if (entitiesList.length === 0) {
localizedContent += listSeparator + ' ' + data[0].translations[0].text + NEWLINE;
if (log) process.stdout.write(chalk.default.gray(listSeparator + ' ' + data[0].translations[0].text + NEWLINE));
} else {
// handle alignment
lText = data[0].translations[0].text;
if (data[0].translations[0].alignment) {
let alData = data[0].translations[0].alignment.proj.split(' ');
entitiesList.forEach(function (entity) {
let testIndex = entity.start + ':' + entity.end;
let alDataMap = alData.filter(val => {
let p = val.split('-');
if (p[0] === testIndex) return p[1];
});
if (alDataMap.length !== 0) {
let seIndex = alDataMap[0].split('-')[1].split(':');
let leftText = lText.substring(0, seIndex[0]);
let rightText = lText.substring(parseInt(seIndex[1]) + 1);
if (entity.value === '') {
// we have a pattern any entity
lText = leftText + entity.entity + rightText;
} else {
let locLabelledValue = lText.substring(seIndex[0], parseInt(seIndex[1]) + 1);
lText = leftText + '{' + entity.entity + '=' + locLabelledValue + '}' + rightText
}
lEntity = entitySplit[0].trim();
labelledValue = entitySplit[1].trim();
if(!labelledValue.includes(' ')) {
updatedUtteranceLeft = content.substring(0,content.indexOf(entity));
updatedUtteranceRight = content.substring(content.indexOf(entity) + entity.length);
content = updatedUtteranceLeft + labelledValue + updatedUtteranceRight;
eStartIndex = content.indexOf(labelledValue);
eEndIndex = eStartIndex + labelledValue.length - 1;
entitiesList.push(new helperClasses.entity(lEntity, labelledValue, eStartIndex, eEndIndex));
}
} else {
eStartIndex = content.indexOf(lEntity);
eEndIndex = eStartIndex + lEntity.length - 1;
entitiesList.push(new helperClasses.entity(lEntity, labelledValue, eStartIndex, eEndIndex));
}
});
}
try {
data = await translateHelpers.translateText(content, subscriptionKey, to_lang, src_lang);
} catch (err) {
throw(err);
}
if(entitiesList.length === 0) {
localizedContent += listSeparator + ' ' + data[0].translations[0].text + NEWLINE;
if(log) process.stdout.write(chalk.default.gray(listSeparator + ' ' + data[0].translations[0].text + NEWLINE));
} else {
// handle alignment
lText = data[0].translations[0].text;
if(data[0].translations[0].alignment) {
let alData = data[0].translations[0].alignment.proj.split(' ');
entitiesList.forEach(function(entity) {
let testIndex = entity.start + ':' + entity.end;
let alDataMap = alData.filter(val => {
let p = val.split('-');
if(p[0] === testIndex) return p[1];
});
if(alDataMap.length !== 0) {
let seIndex = alDataMap[0].split('-')[1].split(':');
let leftText = lText.substring(0, seIndex[0]);
let rightText = lText.substring(parseInt(seIndex[1]) + 1);
if(entity.value === '') {
// we have a pattern any entity
lText = leftText + entity.entity + rightText;
} else {
locLabelledValue = lText.substring(seIndex[0], parseInt(seIndex[1]) + 1);
lText = leftText + '{' + entity.entity + '=' + locLabelledValue + '}' + rightText
}
}
});
} else {
try {
data = await translateHelpers.translateText(content, subscriptionKey, to_lang, src_lang);
} catch (err) {
throw(err);
}
lText = data[0].translations[0].text;
try {
data = await translateHelpers.translateText(content, subscriptionKey, to_lang, src_lang);
} catch (err) {
throw (err);
}
localizedContent += listSeparator + ' ' + lText + NEWLINE;
if(log) process.stdout.write(chalk.default.gray(listSeparator + ' ' + lText + NEWLINE));
lText = data[0].translations[0].text;
}
break;
case PARSERCONSTS.ENTITY:
// strip line of the list separator
listSeparator = currentLine.charAt(0);
content = currentLine.slice(1).trim();
try {
data = await translateHelpers.translateText(content, subscriptionKey, to_lang, src_lang);
} catch (err) {
throw(err);
}
lText = data[0].translations[0].text;
localizedContent += listSeparator + ' ' + lText + NEWLINE;
if(log) process.stdout.write(chalk.default.gray(listSeparator + ' ' + lText + NEWLINE));
break;
case PARSERCONSTS.QNA:
default:
// strip line of the list separator
listSeparator = currentLine.charAt(0);
content = currentLine.slice(1).trim();
try {
data = await translateHelpers.translateText(content, subscriptionKey, to_lang, src_lang);
} catch (err) {
throw(err);
}
lText = data[0].translations[0].text;
localizedContent += listSeparator + ' ' + lText + NEWLINE;
if(log) process.stdout.write(chalk.default.gray(listSeparator + ' ' + lText + NEWLINE));
break;
if (log) process.stdout.write(chalk.default.gray(listSeparator + ' ' + lText + NEWLINE));
}
break;
}
case PARSERCONSTS.ENTITY:
// strip line of the list separator
listSeparator = currentLine.charAt(0);
content = currentLine.slice(1).trim();
try {
data = await translateHelpers.translateText(content, subscriptionKey, to_lang, src_lang);
} catch (err) {
throw (err);
}
lText = data[0].translations[0].text;
localizedContent += listSeparator + ' ' + lText + NEWLINE;
if (log) process.stdout.write(chalk.default.gray(listSeparator + ' ' + lText + NEWLINE));
break;
case PARSERCONSTS.QNA:
default:
// strip line of the list separator
listSeparator = currentLine.charAt(0);
content = currentLine.slice(1).trim();
try {
data = await translateHelpers.translateText(content, subscriptionKey, to_lang, src_lang);
} catch (err) {
throw (err);
}
lText = data[0].translations[0].text;
localizedContent += listSeparator + ' ' + lText + NEWLINE;
if (log) process.stdout.write(chalk.default.gray(listSeparator + ' ' + lText + NEWLINE));
break;
}
} else if(currentLine.indexOf(PARSERCONSTS.ENTITY) === 0) {
// we need to localize qna alterations if specified.
@ -270,9 +271,9 @@ const translateHelpers = {
method: 'POST',
body: JSON.stringify ([{'Text' : text}]),
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key' : subscriptionKey,
'X-ClientTraceId' : get_guid (),
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key' : subscriptionKey,
'X-ClientTraceId' : get_guid (),
}
};
const res = await fetch(tUri, options);
@ -290,8 +291,8 @@ const translateHelpers = {
*/
const get_guid = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}

Просмотреть файл

@ -38,10 +38,6 @@ describe('Testing all classes', function() {
assert.equal(new exception(testData).text, '');
});
it('can create a new instance from no values passed in as args', function() {
let testData = {
text: 'foo',
errCode: 21
};
assert.equal(new exception().text, '');
});
});

Просмотреть файл

@ -19,7 +19,7 @@ describe('The ludown cli tool', function() {
describe('with no command', function() {
it('should print the help contents when --help is passed as an argument', function(done) {
exec(`node ${ludown} --help`, (error, stdout, stderr) => {
exec(`node ${ludown} --help`, (error, stdout) => {
try {
assert.equal(stdout.includes('-v'), true);
done();
@ -30,7 +30,7 @@ describe('The ludown cli tool', function() {
});
it('should print the help contents no arguments are passed', function(done) {
exec(`node ${ludown}`, (error, stdout, stderr) => {
exec(`node ${ludown}`, (error, stdout) => {
try {
assert.equal(stdout.includes('-v'), true);
done();
@ -210,7 +210,7 @@ describe('The ludown cli tool', function() {
});
it('should show help when root file is missing', function(done) {
exec(`node ${ludown} parse toluis`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis`, (error, stdout) => {
try {
assert.equal(stdout.includes('Usage: ludown parse ToLuis --in <luFile>'),true);
done();
@ -298,7 +298,7 @@ describe('The ludown cli tool', function() {
});
it('should show help when root file is missing', function(done) {
exec(`node ${ludown} parse toqna`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toqna`, (error, stdout) => {
try {
assert.equal(stdout.includes('ludown parse ToQna --in <luFile>'), true);
done();
@ -377,7 +377,7 @@ describe('The ludown cli tool', function() {
});
it('should show help when root file is missing', function(done) {
exec(`node ${ludown} refresh`, (error, stdout, stderr) => {
exec(`node ${ludown} refresh`, (error, stdout) => {
try {
assert.equal(stdout.includes('Usage: ludown refresh -i <LUISJsonFile>'), true);
done();

Просмотреть файл

@ -12,53 +12,53 @@ var inputFileContent = `> Definition for greeting intent
> users might say these
- Good morning
- Good evening`;
var outputBlob =
var outputBlob =
{
"intents": [
{
"name": "Greeting"
}
],
"entities": [],
"composites": [],
"closedLists": [],
"regex_entities": [],
"model_features": [],
"regex_features": [],
"utterances": [
{
"text": "Hi",
"intent": "Greeting",
"entities": []
},
{
"text": "Hello",
"intent": "Greeting",
"entities": []
},
{
"text": "Good morning",
"intent": "Greeting",
"entities": []
},
{
"text": "Good evening",
"intent": "Greeting",
"entities": []
}
],
"patterns": [],
"patternAnyEntities": [],
"prebuiltEntities": [],
"intents": [
{
"name": "Greeting"
}
],
"entities": [],
"composites": [],
"closedLists": [],
"regex_entities": [],
"model_features": [],
"regex_features": [],
"utterances": [
{
"text": "Hi",
"intent": "Greeting",
"entities": []
},
{
"text": "Hello",
"intent": "Greeting",
"entities": []
},
{
"text": "Good morning",
"intent": "Greeting",
"entities": []
},
{
"text": "Good evening",
"intent": "Greeting",
"entities": []
}
],
"patterns": [],
"patternAnyEntities": [],
"prebuiltEntities": [],
};
describe('Comment blocks in .lu files', function() {
it('should be parsed correctly with 1 intent and comments specified', function(done) {
parseFileContents.parseFile(inputFileContent, false, 'en-us')
.then(function(parsedContent){
assert.deepEqual(parsedContent.LUISJsonStructure, outputBlob);
done();
})
.catch(err => done(err))
.then(function(parsedContent){
assert.deepEqual(parsedContent.LUISJsonStructure, outputBlob);
done();
})
.catch(err => done(err))
});
});

Просмотреть файл

@ -2,6 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/*eslint no-console: ["error", { allow: ["log"] }] */
var chai = require('chai');
var assert = chai.assert;
var path = require('path');
@ -15,29 +16,29 @@ const PATH_TO_OUTPUT_FOLDER = path.resolve(TEST_ROOT + '/output');
function compareFiles(actualPath, expectedPath) {
let expected = txtfile.readSync(actualPath).split(/\r?\n/);
let actual = txtfile.readSync(expectedPath).split(/\r?\n/);;
let actual = txtfile.readSync(expectedPath).split(/\r?\n/);
assert.deepEqual(actual, expected);
}
function sanitizeExampleJson(fileContent) {
let escapedExampleNewLine = JSON.stringify('\r\n').replace(/\"/g, '').replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
let escapedNewLine = JSON.stringify(NEWLINE).replace(/\"/g, '');
let escapedExampleNewLine = JSON.stringify('\r\n').replace(/"/g, '').replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
let escapedNewLine = JSON.stringify(NEWLINE).replace(/"/g, '');
return fileContent.replace(new RegExp(escapedExampleNewLine, 'g'), escapedNewLine);
}
describe('The example lu files', function() {
before(function(){
before(function () {
try {
if(!fs.existsSync(PATH_TO_OUTPUT_FOLDER)) {
if (!fs.existsSync(PATH_TO_OUTPUT_FOLDER)) {
fs.mkdirSync(PATH_TO_OUTPUT_FOLDER);
}
} catch (err) {
console.log('Unable to create test\\output folder. The tests will fail');
}
});
});
it('refresh command successfully reconstructs a markdown file from a QnA input file with qnaDocuments section', function(done) {
exec(`node ${ludown} refresh -q ${TEST_ROOT}/testcases/qnaDocuments.json -o ${TEST_ROOT}/output -n qnaDocuments`, (error, stdout, stderr) => {
exec(`node ${ludown} refresh -q ${TEST_ROOT}/testcases/qnaDocuments.json -o ${TEST_ROOT}/output -n qnaDocuments`, () => {
try {
done();
} catch(err) {
@ -47,7 +48,7 @@ describe('The example lu files', function() {
});
it('refresh command successfully reconstructs a markdown file from a LUIS input file with out of order entity references', function(done) {
exec(`node ${ludown} refresh -i ${TEST_ROOT}/testcases/test269-d.json -o ${TEST_ROOT}/output -n test269-d2`, (error, stdout, stderr) => {
exec(`node ${ludown} refresh -i ${TEST_ROOT}/testcases/test269-d.json -o ${TEST_ROOT}/output -n test269-d2`, () => {
try {
done();
} catch(err) {
@ -57,7 +58,7 @@ describe('The example lu files', function() {
});
it('refresh command successfully reconstructs a markdown file from a LUIS input file with out of order entity references', function(done) {
exec(`node ${ludown} refresh -i ${TEST_ROOT}/testcases/test269-d.json -o ${TEST_ROOT}/output --skip_header -n test269-d`, (error, stdout, stderr) => {
exec(`node ${ludown} refresh -i ${TEST_ROOT}/testcases/test269-d.json -o ${TEST_ROOT}/output --skip_header -n test269-d`, () => {
try {
compareFiles(TEST_ROOT + '/output/test269-d.lu', TEST_ROOT + '/verified/test269-d.lu');
done();
@ -67,11 +68,8 @@ describe('The example lu files', function() {
});
});
it('refresh command successfully reconstructs a markdown file from a LUIS input file', function(done) {
exec(`node ${ludown} refresh -i ${TEST_ROOT}/verified/all.json -o ${TEST_ROOT}/output --skip_header -n allGen`, (error, stdout, stderr) => {
exec(`node ${ludown} refresh -i ${TEST_ROOT}/verified/all.json -o ${TEST_ROOT}/output --skip_header -n allGen`, () => {
try {
compareFiles(TEST_ROOT + '/output/allGen.lu', TEST_ROOT + '/verified/allRefresh.lu');
done();
@ -81,10 +79,8 @@ describe('The example lu files', function() {
});
});
it('refresh command successfully reconstructs a markdown file from QnA input file', function(done) {
exec(`node ${ludown} refresh -q ${TEST_ROOT}/verified/all-qna.json -o ${TEST_ROOT}/output --skip_header -n allGenQnA`, (error, stdout, stderr) => {
exec(`node ${ludown} refresh -q ${TEST_ROOT}/verified/all-qna.json -o ${TEST_ROOT}/output --skip_header -n allGenQnA`, () => {
try {
compareFiles(TEST_ROOT + '/output/allGenQnA.lu', TEST_ROOT + '/verified/allGenQnA.lu');
done();
@ -96,7 +92,7 @@ describe('The example lu files', function() {
})
it('refresh command successfully writes out a markdown file from QnA and luis input files', function(done) {
exec(`node ${ludown} refresh -q ${TEST_ROOT}/verified/all-qna.json -i ${TEST_ROOT}/verified/all.json -o ${TEST_ROOT}/output --skip_header --verbose`, (error, stdout, stderr) => {
exec(`node ${ludown} refresh -q ${TEST_ROOT}/verified/all-qna.json -i ${TEST_ROOT}/verified/all.json -o ${TEST_ROOT}/output --skip_header --verbose`, (error, stdout) => {
try {
compareFiles(TEST_ROOT + '/output/allall-qna.lu', TEST_ROOT + '/verified/allall-qna.lu');
assert.ok(stdout.includes('Successfully wrote to '));
@ -109,7 +105,7 @@ describe('The example lu files', function() {
})
it('Simple intent and utterances are parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/1.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/1.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/1.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/1.json')));
done();
@ -120,10 +116,8 @@ describe('The example lu files', function() {
});
});
it('Multiple intent and utterance definition sections are parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/3.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/3.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/3.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/3.json')));
done();
@ -135,7 +129,7 @@ describe('The example lu files', function() {
});
it('Uttearnces with labelled values are parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/4.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/4.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/4.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/4.json')));
done();
@ -147,7 +141,7 @@ describe('The example lu files', function() {
});
it('Simple entity declaration is parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/5.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/5.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/5.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/5.json')));
done();
@ -159,7 +153,7 @@ describe('The example lu files', function() {
});
it('Prebuilt entity types are parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/6.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/6.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/6.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/6.json')));
done();
@ -171,7 +165,7 @@ describe('The example lu files', function() {
});
it('Pattern.any entity types are parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/7.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/7.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/7.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/7.json')));
done();
@ -183,7 +177,7 @@ describe('The example lu files', function() {
});
it('List entity types are parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/9.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/9.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/9.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/9.json')));
done();
@ -195,7 +189,7 @@ describe('The example lu files', function() {
});
it('List entity definitions and intent definitions can be split up and will be parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/9a.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/9a.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/9a.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/9a.json')));
done();
@ -207,7 +201,7 @@ describe('The example lu files', function() {
});
it('with single file references are parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/buyChocolate.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/buyChocolate.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/buyChocolate.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/buyChocolate.json')));
done();
@ -219,7 +213,7 @@ describe('The example lu files', function() {
});
it('with multiple file references are parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/11.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/11.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/11.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/11.json')));
done();
@ -231,7 +225,7 @@ describe('The example lu files', function() {
});
it('with mix of LUIS and QnA content is parsed correctly [LUIS]', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/12.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/12.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/12.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/12.json')));
done();
@ -243,7 +237,7 @@ describe('The example lu files', function() {
});
it('with mix of LUIS and QnA content is parsed correctly [QnA]', function(done) {
exec(`node ${ludown} parse toqna --in ${TEST_ROOT}/../examples/12.lu -o ${TEST_ROOT}/output -n 12qna`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toqna --in ${TEST_ROOT}/../examples/12.lu -o ${TEST_ROOT}/output -n 12qna`, () => {
try {
assert.deepEqual(JSON.parse(sanitizeExampleJson(txtfile.readSync(TEST_ROOT + '/verified/12qna.json'))), JSON.parse(sanitizeExampleJson(txtfile.readSync(TEST_ROOT + '/output/12qna.json'))));
done();
@ -255,7 +249,7 @@ describe('The example lu files', function() {
});
it('all concepts of lu file definition is parsed correctly [LUIS]', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/all.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/../examples/all.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/all.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/all.json')));
done();
@ -267,7 +261,7 @@ describe('The example lu files', function() {
});
it('all concepts of lu file definition is parsed correctly [QnA]', function(done) {
exec(`node ${ludown} parse toqna --in ${TEST_ROOT}/../examples/all.lu -o ${TEST_ROOT}/output -n all-qna`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toqna --in ${TEST_ROOT}/../examples/all.lu -o ${TEST_ROOT}/output -n all-qna`, () => {
try {
assert.deepEqual(JSON.parse(sanitizeExampleJson(txtfile.readSync(TEST_ROOT + '/verified/all-qna.json'))), JSON.parse(sanitizeExampleJson(txtfile.readSync(TEST_ROOT + '/output/all-qna.json'))));
done();
@ -279,7 +273,7 @@ describe('The example lu files', function() {
});
it('all entity types are parsed correctly', function(done) {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/testcases/all-entity-types.lu -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/testcases/all-entity-types.lu -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/all-entity-types.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/output/all-entity-types.json')));
done();
@ -291,7 +285,7 @@ describe('The example lu files', function() {
});
it('writes out a warning when no utterances are found for an intent', function(done){
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/testcases/missing-utterance.lu -o ${TEST_ROOT}/output --verbose`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/testcases/missing-utterance.lu -o ${TEST_ROOT}/output --verbose`, (error, stdout) => {
try {
assert.ok(stdout.includes('[WARN] No utterances found for intent: # Greeting'));
done();
@ -313,7 +307,7 @@ describe('The example lu files', function() {
});
it('writes out a warning when no synonym definitions are found for a list entity', function(done){
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/testcases/missing-synonyms.lu -o ${TEST_ROOT}/output --verbose`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis --in ${TEST_ROOT}/testcases/missing-synonyms.lu -o ${TEST_ROOT}/output --verbose`, (error, stdout) => {
try {
assert.ok(stdout.includes('[WARN] No synonyms list found'));
done();
@ -323,9 +317,8 @@ describe('The example lu files', function() {
});
});
it('Successfully spits out qnamaker alterations list when specified in .lu files', function(done){
exec(`node ${ludown} parse toqna -a --in ${TEST_ROOT}/../examples/qna-alterations.lu -o ${TEST_ROOT}/output --verbose`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toqna -a --in ${TEST_ROOT}/../examples/qna-alterations.lu -o ${TEST_ROOT}/output --verbose`, (error, stdout) => {
try {
assert.ok(stdout.includes('Successfully wrote QnA Alterations JSON file'));
done();
@ -347,7 +340,7 @@ describe('The example lu files', function() {
});
it('Collate can correctly merge LUIS content split across LU files', function(done){
exec(`node ${ludown} parse toluis -l ${TEST_ROOT}/testcases/collate -n collated-luis -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis -l ${TEST_ROOT}/testcases/collate -n collated-luis -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/output/collated-luis.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/collated-luis.json')));
done();
@ -356,9 +349,9 @@ describe('The example lu files', function() {
}
});
});
it('Collate can correctly merge LUIS content split across LU files to generate batch test input', function(done){
exec(`node ${ludown} parse toluis -l ${TEST_ROOT}/testcases/collate -n collated-luis -o ${TEST_ROOT}/output -t`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toluis -l ${TEST_ROOT}/testcases/collate -n collated-luis -o ${TEST_ROOT}/output -t`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/output/collated-luis_LUISBatchTest.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/collated-luis_LUISBatchTest.json')));
done();
@ -367,9 +360,9 @@ describe('The example lu files', function() {
}
});
});
it('Collate can correctly merge QnA content split across LU files', function(done){
exec(`node ${ludown} parse toqna -l ${TEST_ROOT}/testcases/collate -n collate-qna -o ${TEST_ROOT}/output`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toqna -l ${TEST_ROOT}/testcases/collate -n collate-qna -o ${TEST_ROOT}/output`, () => {
try {
assert.deepEqual(JSON.parse(sanitizeExampleJson(txtfile.readSync(TEST_ROOT + '/output/collate-qna.json'))), JSON.parse(sanitizeExampleJson(txtfile.readSync(TEST_ROOT + '/verified/collate-qna.json'))));
done();
@ -380,7 +373,7 @@ describe('The example lu files', function() {
});
it('Collate can correctly merge QnA word alteration content split across LU files', function(done){
exec(`node ${ludown} parse toqna -l ${TEST_ROOT}/testcases/collate -n alterations -o ${TEST_ROOT}/output -a`, (error, stdout, stderr) => {
exec(`node ${ludown} parse toqna -l ${TEST_ROOT}/testcases/collate -n alterations -o ${TEST_ROOT}/output -a`, () => {
try {
assert.deepEqual(JSON.parse(txtfile.readSync(TEST_ROOT + '/output/alterations_Alterations.json')), JSON.parse(txtfile.readSync(TEST_ROOT + '/verified/collate_Alterations.json')));
done();
@ -389,13 +382,12 @@ describe('The example lu files', function() {
}
});
});
it('Refresh command can successfully generate content from LUIS, QnA and QnA Alterations', function(done){
exec(`node ${ludown} refresh -i ${TEST_ROOT}/verified/collated-luis.json -q ${TEST_ROOT}/verified/collate-qna.json -a ${TEST_ROOT}/verified/collate_Alterations.json -n collate_refresh -o ${TEST_ROOT}/output --skip_header`, (error, stdout, stderr) => {
try {
compareFiles(TEST_ROOT + '/verified/collate_refresh.lu', TEST_ROOT + '/output/collate_refresh.lu');
done();
it('Refresh command can successfully generate content from LUIS, QnA and QnA Alterations', function (done) {
exec(`node ${ludown} refresh -i ${TEST_ROOT}/verified/collated-luis.json -q ${TEST_ROOT}/verified/collate-qna.json -a ${TEST_ROOT}/verified/collate_Alterations.json -n collate_refresh -o ${TEST_ROOT}/output --skip_header`, () => {
try {
compareFiles(TEST_ROOT + '/verified/collate_refresh.lu', TEST_ROOT + '/output/collate_refresh.lu');
done();
} catch (err) {
done(err);
}

Просмотреть файл

@ -28,7 +28,7 @@ describe('With helper functions', function() {
it('splitFileBySections throws when no intent definition found in a line', function(done){
let testLu = `#Greeting`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done('Test failed: splitFileBySections did not throw!');
} catch (err) {
done();
@ -39,7 +39,7 @@ describe('With helper functions', function() {
let testLu = `$test:123=
# Greeting`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done();
} catch (err) {
done(err);
@ -50,7 +50,7 @@ describe('With helper functions', function() {
let testLu = `# Greeting
# None`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done();
} catch (err) {
done(err);
@ -61,7 +61,7 @@ describe('With helper functions', function() {
let testLu = `# ? 123
# Greeting`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done('Test failed: splitFileBySections did not throw!');
} catch (err) {
done();
@ -72,7 +72,7 @@ describe('With helper functions', function() {
let testLu = `# ? 123
[test](1.lu)`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done('Test failed: splitFileBySections did not throw!');
} catch (err) {
done();
@ -82,7 +82,7 @@ describe('With helper functions', function() {
it('splitFileBySections throws when no answer found for question', function(done){
let testLu = `# ? 123`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done('Test failed: splitFileBySections did not throw!');
} catch (err) {
done();
@ -95,7 +95,7 @@ describe('With helper functions', function() {
$commPreference:call
- phone call`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done('Test failed: splitFileBySections did not throw!');
} catch (err) {
done();
@ -108,7 +108,7 @@ describe('With helper functions', function() {
$commPreference:call
- phone call`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done('Test failed: splitFileBySections did not throw!');
} catch (err) {
done();
@ -118,7 +118,7 @@ describe('With helper functions', function() {
it('splitFileBySections throws when invalid entity definition is found', function(done){
let testLu = `$PREBUILT:datetimeV23`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done('Test failed: splitFileBySections did not throw!');
} catch (err) {
done();
@ -128,7 +128,7 @@ describe('With helper functions', function() {
it('splitFileBySections throws when invalid entity definition is found', function(done){
let testLu = `$PREBUILT=datetimeV23`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done('Test failed: splitFileBySections did not throw!');
} catch (err) {
done();
@ -139,7 +139,7 @@ describe('With helper functions', function() {
let testLu = `$commPreference:cal=l
- phone call`;
try {
let test = helpers.splitFileBySections(testLu, false);
helpers.splitFileBySections(testLu, false);
done('Test failed: splitFileBySections did not throw!');
} catch (err) {
done();

Просмотреть файл

@ -2,8 +2,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const chai = require('chai');
const assert = chai.assert;
const parseFile = require('../lib/parseFileContents');
describe('With helper functions', function() {
@ -19,17 +17,17 @@ $commPreference:phraseList
parseFile.parseFile(luFile, false, 'en-us')
.then(function(parsedContent) {
parseFile.validateLUISBlob(parsedContent.LUISJsonStructure)
.then(res => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(err => done())
.then(() => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done())
})
.catch(err => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done('Test fail. validateLUISBlob did not throw when expected!'))
});
it('parseFile throws on invalid file refs', function(done) {
let luFile = `[test]()`;
parseFile.parseFile(luFile, false, 'en-us')
.then(res => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(err => done())
.then(() => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done())
});
it('parseFile throws on nested entity refs', function(done) {
@ -37,8 +35,8 @@ $commPreference:phraseList
- hi {userName=foo {lastName=bar}}
`;
parseFile.parseFile(luFile, false, 'en-us')
.then(res => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(err => done())
.then(() => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done())
});
it('parseFile throws if a QnA maker question does not have a list decoration', function(done) {
@ -46,8 +44,8 @@ $commPreference:phraseList
question 2
`;
parseFile.parseFile(luFile, false, 'en-us')
.then(res => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(err => done())
.then(() => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done())
});
it('parseFile throws if a QnA maker filter section does not have list decoration', function(done) {
@ -56,8 +54,8 @@ question 2
location = seattle
`;
parseFile.parseFile(luFile, false, 'en-us')
.then(res => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(err => done())
.then(() => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done())
});
it('parseFile throws if a QnA maker filter section does not have valid key = value pair', function(done) {
@ -66,8 +64,8 @@ location = seattle
- location
`;
parseFile.parseFile(luFile, false, 'en-us')
.then(res => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(err => done())
.then(() => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done())
});
it('parseFile parses multi-line answer correctly', function(done) {
@ -78,8 +76,8 @@ test
\`\`\`
`;
parseFile.parseFile(luFile, false, 'en-us')
.then(res => done())
.catch(err => done('Test fail. validateLUISBlob did not throw when expected!'))
.then(() => done())
.catch(() => done('Test fail. validateLUISBlob did not throw when expected!'))
});
it('parseFile throws on conflicting phraseList definitions', function(done) {
@ -91,8 +89,8 @@ test
`;
parseFile.parseFile(luFile, false, 'en-us')
.then(res => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(err => done())
.then(() => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done())
});
it('parseFile throws if phraseList value does not have list decoration', function(done) {
@ -100,8 +98,8 @@ test
m&m,mars,mints,spearmings,payday,jelly,kit kat,kitkat,twix
`;
parseFile.parseFile(luFile, false, 'en-us')
.then(res => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(err => done())
.then(() => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done())
});
it('parseFile throws if List synonyms do not have list decoration', function(done) {
@ -109,8 +107,7 @@ m&m,mars,mints,spearmings,payday,jelly,kit kat,kitkat,twix
m&m,mars,mints,spearmings,payday,jelly,kit kat,kitkat,twix
`;
parseFile.parseFile(luFile, false, 'en-us')
.then(res => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(err => done())
.then(() => done('Test fail. validateLUISBlob did not throw when expected!'))
.catch(() => done())
});
});

Просмотреть файл

@ -17,7 +17,7 @@ describe('With the parseAndTranslate method', function() {
.then(function(res) {
assert.equal(helpers.sanitizeNewLines(res), helpers.sanitizeNewLines(`> This is a comment
`));
done();
done();
})
.catch(err => done(err));
});
@ -29,8 +29,8 @@ done();
}
translate.parseAndTranslate(testData.tests.qna.luFile, TRANSLATE_KEY, testData.tests.qna.langCode, '', false, false, false)
.then(function(res) {
assert.equal(helpers.sanitizeNewLines(res), helpers.sanitizeNewLines(testData.tests.qna.translatedContent));
done();
assert.equal(helpers.sanitizeNewLines(res), helpers.sanitizeNewLines(testData.tests.qna.translatedContent));
done();
})
.catch(err => done(err))
});
@ -43,7 +43,7 @@ done();
translate.parseAndTranslate(testData.tests.phraseList.luFile, TRANSLATE_KEY, testData.tests.phraseList.langCode, '', false, false, false)
.then(function(res) {
assert.equal(helpers.sanitizeNewLines(res), helpers.sanitizeNewLines(testData.tests.phraseList.translatedContent));
done();
done();
})
.catch(err => done(err))
});
@ -55,8 +55,8 @@ done();
translate.parseAndTranslate(testData.tests.badLu.luFile, TRANSLATE_KEY, testData.tests.badLu.langCode, '', false, false, false)
.then(res => done(res))
.catch(function(err) {
assert.equal(err.errCode, retCode.errorCode.INVALID_INPUT_FILE);
done();
assert.equal(err.errCode, retCode.errorCode.INVALID_INPUT_FILE);
done();
})
});
@ -67,7 +67,7 @@ done();
translate.parseAndTranslate(testData.tests.fileRef.luFile, TRANSLATE_KEY, testData.tests.fileRef.langCode, '', false, false, false)
.then(function(res) {
assert.equal(helpers.sanitizeNewLines(res), helpers.sanitizeNewLines(testData.tests.fileRef.luFile + NEWLINE));
done();
done();
})
.catch(err => done(err))
});
@ -88,10 +88,10 @@ done();
})
});
it('Invalid key with comments throws', function(done) {
if (!TRANSLATE_KEY) {
this.skip();
}
it('Invalid key with comments throws', function(done) {
if (!TRANSLATE_KEY) {
this.skip();
}
translate.parseAndTranslate(`> test comment
`, TRANSLATE_KEY + '2', testData.tests.badLu.langCode, '', true, false, false)
.then(function(res) {
@ -119,16 +119,16 @@ done();
})
});
it('Labelled entity values are translated correctly', function(done) {
if (!TRANSLATE_KEY) {
this.skip();
}
translate.parseAndTranslate(testData.tests.labelledEntityValue.luFile, TRANSLATE_KEY, testData.tests.labelledEntityValue.langCode, '', false, true, false)
.then(function(res) {
assert.equal(helpers.sanitizeNewLines(res), helpers.sanitizeNewLines(testData.tests.labelledEntityValue.translatedContent));
done();
})
.catch(err => done(err))
it('Labelled entity values are translated correctly', function (done) {
if (!TRANSLATE_KEY) {
this.skip();
}
translate.parseAndTranslate(testData.tests.labelledEntityValue.luFile, TRANSLATE_KEY, testData.tests.labelledEntityValue.langCode, '', false, true, false)
.then(function (res) {
assert.equal(helpers.sanitizeNewLines(res), helpers.sanitizeNewLines(testData.tests.labelledEntityValue.translatedContent));
done();
})
.catch(err => done(err))
});
it('Invalid key with QnA throws', function(done) {
@ -153,10 +153,10 @@ done();
}
translate.parseAndTranslate(`# Greeting
`, TRANSLATE_KEY, testData.tests.badLu.langCode, '', false, false, true)
.then(function(res) {
.then(function() {
done();
})
.catch(function(err) {
.catch(function() {
done('Test Fail! Threw when not expected');
})
});
@ -195,8 +195,8 @@ done();
}
translate.parseAndTranslate(testData.tests.intentsAndUtterances.luFile, TRANSLATE_KEY, testData.tests.intentsAndUtterances.langCode, 'en-us', true, false, true)
.then(function(res) {
assert.equal(res, helpers.sanitizeNewLines(testData.tests.intentsAndUtterances.translatedContent));
done();
assert.equal(res, helpers.sanitizeNewLines(testData.tests.intentsAndUtterances.translatedContent));
done();
})
.catch(err => done(err))
});
@ -208,8 +208,8 @@ done();
translate.parseAndTranslate(`# ? hello
\`\`\`markdown`, TRANSLATE_KEY, 'de', 'en-us', true, false, true)
.then(function(res) {
assert.equal('# ? Hallo' + NEWLINE + '```markdown' + NEWLINE, res);
done();
assert.equal('# ? Hallo' + NEWLINE + '```markdown' + NEWLINE, res);
done();
})
.catch(err => done(err))
});

Просмотреть файл

@ -19,7 +19,7 @@ describe('With toLU module', function() {
it('throws when input file does not parse as luis content', function(done) {
let invalidFile = resolvePath('test/1.lu')
toLU.generateMarkdown({LUIS_File:invalidFile})
.then(res => done('Test fail! Did not throw when expected'))
.then(() => done('Test fail! Did not throw when expected'))
.catch(err => {
assert.equal(new exception(err).errCode, retCode.errorCode.FILE_OPEN_ERROR);
done();
@ -30,7 +30,7 @@ describe('With toLU module', function() {
it('throws when input file has composite entities', function(done) {
let invalidFile = resolvePath('test/testcases/InvalidLUISModel.json')
toLU.generateMarkdown({LUIS_File:invalidFile})
.then(res => done('Test fail! Did not throw when expected'))
.then(() => done('Test fail! Did not throw when expected'))
.catch(err => {
assert.equal(new exception(err).errCode, retCode.errorCode.INVALID_INPUT_FILE);
done();
@ -40,7 +40,7 @@ describe('With toLU module', function() {
it('throws when input file has regex entities', function(done) {
let invalidFile = resolvePath('test/testcases/InvalidLUISModel1.json')
toLU.generateMarkdown({LUIS_File:invalidFile})
.then(res => done('Test fail! Did not throw when expected'))
.then(() => done('Test fail! Did not throw when expected'))
.catch(err => {
assert.equal(new exception(err).errCode, retCode.errorCode.INVALID_INPUT_FILE);
done();
@ -50,7 +50,7 @@ describe('With toLU module', function() {
it('throws when input file has regex features', function(done) {
let invalidFile = resolvePath('test/testcases/InvalidLUISModel2.json')
toLU.generateMarkdown({LUIS_File:invalidFile})
.then(res => done('Test fail! Did not throw when expected'))
.then(() => done('Test fail! Did not throw when expected'))
.catch(err => {
assert.equal(new exception(err).errCode, retCode.errorCode.INVALID_INPUT_FILE);
done();
@ -60,7 +60,7 @@ describe('With toLU module', function() {
it('throws when input file does not parse as qna content', function(done) {
let invalidFile = resolvePath('test/1.lu')
toLU.generateMarkdown({QNA_FILE:invalidFile})
.then(res => done('Test fail! Did not throw when expected'))
.then(() => done('Test fail! Did not throw when expected'))
.catch(err => {
assert.equal(new exception(err).errCode, retCode.errorCode.FILE_OPEN_ERROR);
done();
@ -70,7 +70,7 @@ describe('With toLU module', function() {
it('throws when input file does not parse as qna content', function(done) {
let invalidFile = resolvePath('examples/1.lu')
toLU.generateMarkdown({LUIS_File:invalidFile})
.then(res => done('Test fail! Did not throw when expected'))
.then(() => done('Test fail! Did not throw when expected'))
.catch(err => {
assert.equal(new exception(err).errCode, retCode.errorCode.INVALID_INPUT_FILE);
done();
@ -80,11 +80,10 @@ describe('With toLU module', function() {
it('throws when input file does not parse as LUIS content', function(done) {
let invalidFile = resolvePath('examples/1.lu')
toLU.generateMarkdown({QNA_FILE:invalidFile})
.then(res => done('Test fail! Did not throw when expected'))
.then(() => done('Test fail! Did not throw when expected'))
.catch(err => {
assert.equal(new exception(err).errCode, retCode.errorCode.INVALID_INPUT_FILE);
done();
})
});
});

Просмотреть файл

@ -2,6 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/*eslint no-console: ["error", { allow: ["log"] }] */
const chai = require('chai');
const assert = chai.assert;
const translate = require('../lib/translate');
@ -37,13 +38,13 @@ describe('With translate module', function() {
} catch (err) {
console.log('Unable to create test/output folder. The tests will fail');
}
});
});
it('should throw when invalid file is specified', function(done){
let invalidFile = resolvePath('test/1.lu');
translate.translateContent({in: invalidFile})
.then(res => done('Test fail! Did not throw when expected'))
.catch(err => done())
.then(() => done('Test fail! Did not throw when expected'))
.catch(() => done())
});
it('correctly localize the file content', function(done) {
@ -51,7 +52,7 @@ describe('With translate module', function() {
this.skip();
}
let luFilePath = resolvePath('examples/1.lu');
exec(`node ${ludown} translate -k ${TRANSLATE_KEY} -t de -o ${LUDOWN_ROOT}/test/output -n 1_de --verbose --in ` + luFilePath, (error, stdout, stderr) => {
exec(`node ${ludown} translate -k ${TRANSLATE_KEY} -t de -o ${LUDOWN_ROOT}/test/output -n 1_de --verbose --in ` + luFilePath, (error, stdout) => {
try {
compareFiles(LUDOWN_ROOT + '/test/output/de/1.lu', LUDOWN_ROOT + '/test/verified/1.lu');
console.log(stdout);
@ -69,7 +70,7 @@ describe('With translate module', function() {
.then(function(res) {
done(res);
})
.catch(function(err){
.catch(function(){
done();
})
});
@ -114,10 +115,10 @@ describe('With translate module', function() {
}
let fileContent = `- 123`;
trHelpers.parseAndTranslate(fileContent, TRANSLATE_KEY, 'dex', '', false, true, SHOW_LOGS)
.then(function(res) {
.then(function() {
done('Test fail! Did not throw when expected');
})
.catch (err => done());
.catch (() => done());
});
it('Translate throw with invalid src lang code', function(done) {
@ -126,10 +127,10 @@ describe('With translate module', function() {
}
let fileContent = `[123]('./1.lu')`;
trHelpers.parseAndTranslate(fileContent, TRANSLATE_KEY, 'de', 'esx', false, true, SHOW_LOGS)
.then(function(res) {
.then(function() {
done('Test fail! Did not throw when expected');
})
.catch (err => done());
.catch (() => done());
});
it('Link text can be left untranslated', function(done) {
@ -156,10 +157,10 @@ describe('With translate module', function() {
let fileContent = `\`\`\`markdown
test 123`;
trHelpers.parseAndTranslate(fileContent, TRANSLATE_KEY, 'de', 'esx', false, true, SHOW_LOGS)
.then(function(res) {
.then(function() {
done('Test fail! Did not throw when expected');
})
.catch (err => done());
.catch (() => done());
});
it('Alterations are translated correctly', function(done) {
@ -178,5 +179,4 @@ describe('With translate module', function() {
})
.catch (err => done(err));
});
});

Просмотреть файл

@ -18,7 +18,9 @@
},
"eslintConfig": {
"env": {
"node": true
"node": true,
"es6": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {