Skip to content

Commit

Permalink
test(create-plugin): add test cases for JsSdkTest-5,6,7,8 (#2763)
Browse files Browse the repository at this point in the history
  • Loading branch information
hung-cybo authored May 14, 2024
1 parent 3e7ebcc commit 3b51339
Show file tree
Hide file tree
Showing 11 changed files with 537 additions and 115 deletions.
51 changes: 32 additions & 19 deletions packages/create-plugin/__e2e__/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import assert from "assert";
import type { QuestionInput } from "./utils/executeCommand";
import { executeCommandWithInteractiveInput } from "./utils/executeCommand";
import type { QuestionInput } from "./utils/CreatePlugin";
import type { PluginTemplate } from "./utils/verification";
import {
CREATE_PLUGIN_COMMAND,
DEFAULT_ANSWER,
ANSWER_NO,
} from "./utils/constants";
import path from "path";
import { generateWorkingDir } from "./utils/generateWorkingDir";
import { generateWorkingDir } from "./utils/helper";
import fs from "fs";
import { rimrafSync } from "rimraf";
import {
assertObjectIncludes,
readPluginManifestJson,
} from "./utils/verification";
import { getBoundMessage } from "../src/messages";
import { pattern as requiredOptions } from "./fixtures/requiredOptions";
import { pattern as pluginNameContain64Chars } from "./fixtures/pluginNameContain64Chars";
import { pattern as pluginDescriptionContain200Chars } from "./fixtures/pluginDescriptionContain200Chars";
import { pattern as allOptions } from "./fixtures/allOptions";
import { pattern as emptyOutputDir } from "./fixtures/emptyOutputDir";
import { pattern as pluginNameContain65Chars } from "./fixtures/pluginNameContain65Chars";
import { pattern as pluginDescriptionContain201Chars } from "./fixtures/pluginDescriptionContain201Chars";
import { pattern as existOutputDir } from "./fixtures/existOutputDir";
import { pattern as createKintonePluginCommand } from "./fixtures/createKintonePluginCommand";
import { CreatePlugin } from "./utils/CreatePlugin";
import {
requiredOptions,
pluginNameContain64Chars,
pluginDescriptionContain200Chars,
allOptions,
languageEN,
languageJA,
emptyOutputDir,
pluginNameContain65Chars,
pluginDescriptionContain201Chars,
existOutputDir,
createKintonePluginCommand,
minimumTemplate,
modernTemplate,
} from "./fixtures";

export type TestPattern = {
description: string;
Expand All @@ -33,7 +40,7 @@ export type TestPattern = {
outputDir: string;
questionsInput: QuestionInput[];
commandArgument?: string;
template?: "minimum" | "modern";
template?: PluginTemplate;
};
expected: {
success?: {
Expand All @@ -58,6 +65,10 @@ describe("create-plugin", function () {
pluginNameContain64Chars,
pluginDescriptionContain200Chars,
allOptions,
languageEN,
languageJA,
minimumTemplate,
modernTemplate,
emptyOutputDir,
existOutputDir,
pluginNameContain65Chars,
Expand All @@ -70,13 +81,14 @@ describe("create-plugin", function () {
prepareFn({ workingDir });
}

const response = await executeCommandWithInteractiveInput({
const createPlugin = new CreatePlugin({
command: input.command,
workingDir,
outputDir: input.outputDir,
questionsInput: input.questionsInput,
commandArguments: input.commandArgument,
});
const response = await createPlugin.executeCommand();

if (expected.success !== undefined) {
assert(response.status === 0, "Failed to create plugin");
Expand All @@ -95,14 +107,14 @@ describe("create-plugin", function () {
assert.notEqual(response.status, 0, "The command should throw an error.");
if (expected.failure.stdout) {
assert.match(
response.stdout.toString().trim(),
response.stdout.trim(),
new RegExp(expected.failure.stdout),
);
}

if (expected.failure.stderr) {
assert.match(
response.stderr.toString().trim(),
response.stderr.trim(),
new RegExp(expected.failure.stderr),
);
}
Expand Down Expand Up @@ -150,23 +162,24 @@ describe("create-plugin", function () {
},
];

const response = await executeCommandWithInteractiveInput({
const createPlugin = new CreatePlugin({
command: CREATE_PLUGIN_COMMAND,
workingDir,
outputDir,
questionsInput,
});
const response = await createPlugin.executeCommand();

if (isWindows) {
assert.equal(response.status, 0);
assert.match(
response.stderr.toString().trim(),
response.stderr.trim(),
/Could not create a plug-in project. Error:\nEINVAL: invalid argument, mkdir '.*:'/,
);
} else {
assert.notEqual(response.status, 0);
assert.match(
response.stderr.toString().trim(),
response.stderr.trim(),
/Error: \/ already exists. Choose a different directory/,
);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/create-plugin/__e2e__/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export { pattern as requiredOptions } from "./requiredOptions";
export { pattern as pluginNameContain64Chars } from "./pluginNameContain64Chars";
export { pattern as pluginDescriptionContain200Chars } from "./pluginDescriptionContain200Chars";
export { pattern as allOptions } from "./allOptions";
export { pattern as languageEN } from "./languageEN";
export { pattern as languageJA } from "./languageJA";
export { pattern as emptyOutputDir } from "./emptyOutputDir";
export { pattern as pluginNameContain65Chars } from "./pluginNameContain65Chars";
export { pattern as pluginDescriptionContain201Chars } from "./pluginDescriptionContain201Chars";
export { pattern as existOutputDir } from "./existOutputDir";
export { pattern as createKintonePluginCommand } from "./createKintonePluginCommand";
export { pattern as minimumTemplate } from "./minimumTemplate";
export { pattern as modernTemplate } from "./modernTemplate";
95 changes: 95 additions & 0 deletions packages/create-plugin/__e2e__/fixtures/languageEN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { TestPattern } from "../e2e.test";
import {
ANSWER_NO,
ANSWER_YES,
CREATE_PLUGIN_COMMAND,
} from "../utils/constants";
import { getBoundMessage } from "../../src/messages";

const lang = "en";
const m = getBoundMessage(lang);

export const pattern: TestPattern = {
description:
"#JsSdkTest-5 Should able to create plugin with --lang argument (EN language)",
input: {
command: CREATE_PLUGIN_COMMAND,
outputDir: "test5",
commandArgument: `--lang ${lang}`,
questionsInput: [
{
question: m("Q_NameEn"),
answer: "test5-name",
},
{
question: m("Q_DescriptionEn"),
answer: "test5-description",
},
{
question: m("Q_SupportJa"),
answer: ANSWER_YES,
},
{
question: m("Q_NameJa"),
answer: "私のプラグイン",
},
{
question: m("Q_DescriptionJa"),
answer: "私のプラグイン",
},
{
question: m("Q_SupportZh"),
answer: ANSWER_YES,
},
{
question: m("Q_NameZh"),
answer: "我的插件",
},
{
question: m("Q_DescriptionZh"),
answer: "我的插件",
},
{
question: m("Q_WebsiteUrlEn"),
answer: "https://github.com",
},
{
question: m("Q_WebsiteUrlJa"),
answer: "https://github.jp",
},
{
question: m("Q_WebsiteUrlZh"),
answer: "https://github.cn",
},
{
question: m("Q_MobileSupport"),
answer: ANSWER_NO,
},
{
question: m("Q_EnablePluginUploader"),
answer: ANSWER_NO,
},
],
},
expected: {
success: {
manifestJson: {
name: {
en: "test5-name",
ja: "私のプラグイン",
zh: "我的插件",
},
description: {
en: "test5-description",
ja: "私のプラグイン",
zh: "我的插件",
},
homepage_url: {
en: "https://github.com",
ja: "https://github.jp",
zh: "https://github.cn",
},
},
},
},
};
95 changes: 95 additions & 0 deletions packages/create-plugin/__e2e__/fixtures/languageJA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { TestPattern } from "../e2e.test";
import {
ANSWER_NO,
ANSWER_YES,
CREATE_PLUGIN_COMMAND,
} from "../utils/constants";
import { getBoundMessage } from "../../src/messages";

const lang = "ja";
const m = getBoundMessage(lang);

export const pattern: TestPattern = {
description:
"#JsSdkTest-6 Should able to create plugin with --lang argument (JA language)",
input: {
command: CREATE_PLUGIN_COMMAND,
outputDir: "test6",
commandArgument: `--lang ${lang}`,
questionsInput: [
{
question: m("Q_NameEn"),
answer: "test6-name",
},
{
question: m("Q_DescriptionEn"),
answer: "test6-description",
},
{
question: m("Q_SupportJa"),
answer: ANSWER_YES,
},
{
question: m("Q_NameJa"),
answer: "私のプラグイン",
},
{
question: m("Q_DescriptionJa"),
answer: "私のプラグイン",
},
{
question: m("Q_SupportZh"),
answer: ANSWER_YES,
},
{
question: m("Q_NameZh"),
answer: "我的插件",
},
{
question: m("Q_DescriptionZh"),
answer: "我的插件",
},
{
question: m("Q_WebsiteUrlEn"),
answer: "https://github.com",
},
{
question: m("Q_WebsiteUrlJa"),
answer: "https://github.jp",
},
{
question: m("Q_WebsiteUrlZh"),
answer: "https://github.cn",
},
{
question: m("Q_MobileSupport"),
answer: ANSWER_NO,
},
{
question: m("Q_EnablePluginUploader"),
answer: ANSWER_NO,
},
],
},
expected: {
success: {
manifestJson: {
name: {
en: "test6-name",
ja: "私のプラグイン",
zh: "我的插件",
},
description: {
en: "test6-description",
ja: "私のプラグイン",
zh: "我的插件",
},
homepage_url: {
en: "https://github.com",
ja: "https://github.jp",
zh: "https://github.cn",
},
},
},
},
};
63 changes: 63 additions & 0 deletions packages/create-plugin/__e2e__/fixtures/minimumTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { TestPattern } from "../e2e.test";
import {
ANSWER_NO,
CREATE_PLUGIN_COMMAND,
DEFAULT_ANSWER,
} from "../utils/constants";
import { getBoundMessage } from "../../src/messages";

const m = getBoundMessage("en");
const template = "minimum";

export const pattern: TestPattern = {
description:
"#JsSdkTest-7 Should able to create a plugin with minimum template",
input: {
command: CREATE_PLUGIN_COMMAND,
outputDir: "test7",
commandArgument: `--template ${template}`,
template,
questionsInput: [
{
question: m("Q_NameEn"),
answer: "test7-name",
},
{
question: m("Q_DescriptionEn"),
answer: "test7-description",
},
{
question: m("Q_SupportJa"),
answer: DEFAULT_ANSWER,
},
{
question: m("Q_SupportZh"),
answer: DEFAULT_ANSWER,
},
{
question: m("Q_WebsiteUrlEn"),
answer: DEFAULT_ANSWER,
},
{
question: m("Q_MobileSupport"),
answer: ANSWER_NO,
},
{
question: m("Q_EnablePluginUploader"),
answer: ANSWER_NO,
},
],
},
expected: {
success: {
manifestJson: {
name: { en: "test7-name" },
description: { en: "test7-description" },
desktop: {
js: ["js/desktop.js"],
css: ["css/51-modern-default.css", "css/desktop.css"],
},
},
},
},
};
Loading

0 comments on commit 3b51339

Please sign in to comment.