Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

[Skill Template][TypeScript] Implement tests and fixes #1038

Merged
merged 15 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ module.exports = class extends Generator {
}

const templateName = "customSkill";
const conversationStateTag = "ConversationState";
const userStateTag = "UserState";
const skillDesc = this.props.skillDesc;
if (!this.props.skillName.replace(/\s/g, "").length) {
Expand All @@ -172,6 +171,11 @@ module.exports = class extends Generator {
// Generate vars for templates
const skillNamePascalCase = _upperFirst(_camelCase(this.props.skillName));
const skillNameCamelCase = _camelCase(this.props.skillName);
const skillNameId = skillNameCamelCase.substring(
0,
skillNameCamelCase.indexOf("Skill")
);
const skillNameIdPascalCase = _upperFirst(skillNameId);
skillGenerationPath = path.join(skillGenerationPath, skillName);
if (this.props.skillGenerationPath !== undefined) {
skillGenerationPath = path.join(
Expand All @@ -180,12 +184,6 @@ module.exports = class extends Generator {
);
}

const skillConversationStateNameClass = `I${skillNamePascalCase.concat(
conversationStateTag
)}`;
const skillConversationStateNameFile = skillNameCamelCase.concat(
conversationStateTag
);
const skillUserStateNameClass = `I${skillNamePascalCase.concat(
userStateTag
)}`;
Expand All @@ -212,39 +210,15 @@ module.exports = class extends Generator {
}
);

// Copy bot.recipes files
const recipeFiles = [
path.join("de", "bot.recipe"),
path.join("en", "bot.recipe"),
path.join("es", "bot.recipe"),
path.join("fr", "bot.recipe"),
path.join("it", "bot.recipe"),
path.join("zh", "bot.recipe")
];

recipeFiles.forEach(fileName =>
this.fs.copyTpl(
this.templatePath(templateName, "deploymentScripts", fileName),
this.destinationPath(
skillGenerationPath,
"deploymentScripts",
fileName
),
{
name: skillName
}
)
);

// Copy index.ts
this.fs.copyTpl(
this.templatePath(templateName, "src", "_index.ts"),
this.destinationPath(skillGenerationPath, "src", "index.ts"),
{
skillConversationStateNameClass: skillConversationStateNameClass,
skillConversationStateNameFile: skillConversationStateNameFile,
skillUserStateNameClass: skillUserStateNameClass,
skillUserStateNameFile: skillUserStateNameFile,
skillTemplateName: skillNamePascalCase,
skillTemplateFileName: skillNameCamelCase,
skillProjectName: skillName,
skillProjectNameLU: `${skillName}LU`
}
Expand All @@ -256,15 +230,10 @@ module.exports = class extends Generator {
this.destinationPath(
skillGenerationPath,
"src",
`${skillConversationStateNameFile}.ts`
"skillConversationState.ts"
),
{
skillConversationStateNameClass: skillConversationStateNameClass,
skillConversationStateNameFile: skillConversationStateNameFile,
skillUserStateNameClass: skillUserStateNameClass,
skillUserStateNameFile: skillUserStateNameFile,
skillProjectName: skillName,
skillProjectNameLU: `${skillName}LU`
skillProjectNameLU: `${skillNameId}LU`
}
);

Expand All @@ -277,8 +246,6 @@ module.exports = class extends Generator {
`${skillUserStateNameFile}.ts`
),
{
skillConversationStateNameClass: skillConversationStateNameClass,
skillConversationStateNameFile: skillConversationStateNameFile,
skillUserStateNameClass: skillUserStateNameClass,
skillUserStateNameFile: skillUserStateNameFile,
skillProjectName: skillName,
Expand All @@ -295,8 +262,6 @@ module.exports = class extends Generator {
`${skillNameCamelCase}.ts`
),
{
skillConversationStateNameClass: skillConversationStateNameClass,
skillConversationStateNameFile: skillConversationStateNameFile,
skillUserStateNameClass: skillUserStateNameClass,
skillUserStateNameFile: skillUserStateNameFile,
skillTemplateName: skillNamePascalCase,
Expand All @@ -305,6 +270,49 @@ module.exports = class extends Generator {
}
);

const languageDirectories = ["de", "en", "es", "fr", "it", "zh"];

// Copy LUIS files
languageDirectories.forEach(language =>
this.fs.copy(
this.templatePath(
templateName,
"cognitiveModels",
"LUIS",
language,
"_skill.lu"
),
this.destinationPath(
skillGenerationPath,
"cognitiveModels",
"LUIS",
language,
`${skillNameId}.lu`
)
)
);

// Copy bot.recipes files
languageDirectories.forEach(languageDirectory =>
this.fs.copyTpl(
this.templatePath(
templateName,
"deploymentScripts",
languageDirectory,
"_bot.recipe"
),
this.destinationPath(
skillGenerationPath,
"deploymentScripts",
languageDirectory,
"bot.recipe"
),
{
skillProjectName: skillNameId
}
)
);

// Copy mainDialog.ts
this.fs.copyTpl(
this.templatePath(
Expand All @@ -322,11 +330,10 @@ module.exports = class extends Generator {
"mainDialog.ts"
),
{
skillConversationStateNameClass: skillConversationStateNameClass,
skillConversationStateNameFile: skillConversationStateNameFile,
skillUserStateNameClass: skillUserStateNameClass,
skillUserStateNameFile: skillUserStateNameFile,
skillProjectName: skillName
skillProjectName: skillName,
skillProjectNameId: skillNameId
}
);

Expand All @@ -347,8 +354,6 @@ module.exports = class extends Generator {
"sampleDialog.ts"
),
{
skillConversationStateNameClass: skillConversationStateNameClass,
skillConversationStateNameFile: skillConversationStateNameFile,
skillUserStateNameClass: skillUserStateNameClass,
skillUserStateNameFile: skillUserStateNameFile
}
Expand All @@ -371,11 +376,25 @@ module.exports = class extends Generator {
"skillDialogBase.ts"
),
{
skillConversationStateNameClass: skillConversationStateNameClass,
skillConversationStateNameFile: skillConversationStateNameFile,
skillUserStateNameClass: skillUserStateNameClass,
skillUserStateNameFile: skillUserStateNameFile,
skillProjectName: skillName
skillProjectName: skillName,
skillProjectNameId: skillNameId
}
);

// Copy skillTestBase file
this.fs.copyTpl(
this.templatePath(templateName, "test", "flow", "_skillTestBase.js"),
this.destinationPath(
skillGenerationPath,
"test",
"flow",
`${skillName}TestBase.js`
),
{
skillTemplateName: skillNamePascalCase,
skillTemplateNameFile: `${skillNameCamelCase}.js`
}
);

Expand All @@ -391,10 +410,17 @@ module.exports = class extends Generator {
"tslint.json",
".env.development",
".env.production",
path.join("cognitiveModels", "LUIS", "de", "general.lu"),
path.join("cognitiveModels", "LUIS", "en", "general.lu"),
path.join("cognitiveModels", "LUIS", "es", "general.lu"),
path.join("cognitiveModels", "LUIS", "fr", "general.lu"),
path.join("cognitiveModels", "LUIS", "it", "general.lu"),
path.join("cognitiveModels", "LUIS", "zh", "general.lu"),
path.join("deploymentScripts", "bot.recipe"),
path.join("deploymentScripts", "deploy_bot.ps1"),
path.join("deploymentScripts", "generate_deployment_scripts.ps1"),
path.join("deploymentScripts", "update_published_models.ps1"),
path.join("src", "languageModels.json"),
path.join("src", "dialogs", "main", "mainResponses.ts"),
path.join("src", "dialogs", "sample", "sampleResponses.ts"),
path.join("src", "dialogs", "shared", "sharedResponses.ts")
Expand All @@ -409,8 +435,8 @@ module.exports = class extends Generator {

// Copy commonDirectories
const commonDirectories = [
"cognitiveModels",
path.join("src", "serviceClients"),
path.join("src", "locales"),
path.join("src", "dialogs", "main", "resources"),
path.join("src", "dialogs", "sample", "resources"),
path.join("src", "dialogs", "shared", "resources"),
Expand All @@ -424,20 +450,151 @@ module.exports = class extends Generator {
)
);

// Copy skills files
this.fs.copyTpl(
this.templatePath(templateName, "src", "_skills.json"),
this.destinationPath(skillGenerationPath, "src", "skills.json"),
{
skillTemplateName: skillNameCamelCase,
skillTemplateIntentName: `l_${skillNameIdPascalCase}`,
skillTemplateId: skillNameId,
skillTemplateNameClass: skillNamePascalCase
}
);

this.fs.copyTpl(
this.templatePath(templateName, "test", "mockResources", "_skills.json"),
this.destinationPath(
skillGenerationPath,
"test",
"mockResources",
"skills.json"
),
{
skillTemplateName: skillNameCamelCase,
skillTemplateIntentName: `l_${skillNameIdPascalCase}`,
skillTemplateId: skillNameId,
skillTemplateNameClass: skillNamePascalCase
}
);

// Copy mainDialogTest file
this.fs.copyTpl(
this.templatePath(templateName, "test", "flow", "_mainDialogTest.js"),
this.destinationPath(
skillGenerationPath,
"test",
"flow",
"mainDialogTest.js"
),
{
skillTemplateName: skillNameCamelCase,
skillTemplateNameFile: `${skillNameCamelCase}TestBase.js`
}
);

// Copy sampleDialogTest file
this.fs.copyTpl(
this.templatePath(templateName, "test", "flow", "_sampleDialogTest.js"),
this.destinationPath(
skillGenerationPath,
"test",
"flow",
"sampleDialogTest.js"
),
{
skillTemplateName: skillNameCamelCase,
skillTemplateNameFile: `${skillNameCamelCase}TestBase.js`
}
);

// Copy interruptionTest file
this.fs.copyTpl(
this.templatePath(templateName, "test", "flow", "_interruptionTest.js"),
this.destinationPath(
skillGenerationPath,
"test",
"flow",
"interruptionTest.js"
),
{
skillTemplateName: skillNameCamelCase,
skillTemplateNameFile: `${skillNameCamelCase}TestBase.js`
}
);

// Copy commonFlowFiles
const commonTestFiles = [
path.join("flow", "mainDialogTests.js"),
path.join("flow", "sampleDialogTests.js"),
path.join("flow", "skillTestBase.js"),
"mocha.opts"
];
const commonTestFiles = ["mocha.opts", ".env.test", "testBase.js"];

commonTestFiles.forEach(testFlowFileName =>
this.fs.copy(
this.templatePath(templateName, "test", testFlowFileName),
this.destinationPath(skillGenerationPath, "test", testFlowFileName)
)
);

// Copy LocaleConfigurations bot files
const localeConfigurationTestFiles = [
"_mockedSkillDe.bot",
"_mockedSkillEn.bot",
"_mockedSkillEs.bot",
"_mockedSkillFr.bot",
"_mockedSkillIt.bot",
"_mockedSkillZh.bot"
];

localeConfigurationTestFiles.forEach(fileName =>
this.fs.copyTpl(
this.templatePath(
templateName,
"test",
"mockResources",
"LocaleConfigurations",
fileName
),
this.destinationPath(
skillGenerationPath,
"test",
"mockResources",
"LocaleConfigurations",
fileName.substring(1)
),
{
skillProjectNameId: skillNameId
}
)
);

const commonTestDirectories = [path.join("nockFixtures")];

commonTestDirectories.forEach(testCommonDirectory =>
this.fs.copy(
this.templatePath(templateName, "test", testCommonDirectory),
this.destinationPath(skillGenerationPath, "test", testCommonDirectory)
)
);

const commonMockResourcesFiles = [
path.join("languageModels.json"),
path.join("mockedConfiguration.bot")
];

commonMockResourcesFiles.forEach(mockResourcesFile =>
this.fs.copy(
this.templatePath(
templateName,
"test",
"mockResources",
mockResourcesFile
),
this.destinationPath(
skillGenerationPath,
"test",
"mockResources",
mockResourcesFile
)
)
);
}

end() {
Expand Down
Loading