Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(create-plugin): add test cases for JsSdk-5,6,7,8 #2756

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 21 additions & 10 deletions packages/create-plugin/__e2e__/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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 {
Expand All @@ -19,11 +19,16 @@ 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 { pattern as minimumTemplate } from "./fixtures/minimumTemplate";
import { pattern as modernTemplate } from "./fixtures/modernTemplate";
import { CreatePlugin } from "./utils/CreatePlugin";

export type TestPattern = {
description: string;
Expand All @@ -33,7 +38,7 @@ export type TestPattern = {
outputDir: string;
questionsInput: QuestionInput[];
commandArgument?: string;
template?: "minimum" | "modern";
template?: PluginTemplate;
};
expected: {
success?: {
Expand All @@ -58,6 +63,10 @@ describe("create-plugin", function () {
pluginNameContain64Chars,
pluginDescriptionContain200Chars,
allOptions,
languageEN,
languageJA,
minimumTemplate,
modernTemplate,
emptyOutputDir,
existOutputDir,
pluginNameContain65Chars,
Expand All @@ -70,13 +79,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 +105,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 +160,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",
},
},
},
},
};
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"],
},
},
},
},
};