Skip to content

Commit

Permalink
test(create-plugin): add test cases for JsSdk-5,6
Browse files Browse the repository at this point in the history
  • Loading branch information
hung-cybo committed May 11, 2024
1 parent e884597 commit 80d5a89
Show file tree
Hide file tree
Showing 7 changed files with 402 additions and 104 deletions.
24 changes: 15 additions & 9 deletions packages/create-plugin/__e2e__/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import assert from "assert";
import type { QuestionInput } from "./utils/executeCommand";
import { executeCommandWithInteractiveInput } from "./utils/executeCommand";
import type { QuestionInput } from "./utils/CreatePlugin";
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 {
Expand All @@ -19,11 +18,14 @@ 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 languageEN } from "./fixtures/languageEN";
import { pattern as languageJA } from "./fixtures/languageJA";
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";

export type TestPattern = {
description: string;
Expand Down Expand Up @@ -58,6 +60,8 @@ describe("create-plugin", function () {
pluginNameContain64Chars,
pluginDescriptionContain200Chars,
allOptions,
languageEN,
languageJA,
emptyOutputDir,
existOutputDir,
pluginNameContain65Chars,
Expand All @@ -70,13 +74,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 +100,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 +155,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
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",
},
},
},
},
};
Loading

0 comments on commit 80d5a89

Please sign in to comment.