From e884597c198b1fd6edf6b13fd6025eb2fd17b6c4 Mon Sep 17 00:00:00 2001 From: Nguyen Thai Hung <59815499+hung-cybo@users.noreply.github.com> Date: Tue, 7 May 2024 13:02:14 +0700 Subject: [PATCH] test(create-plugin): add test cases for JsSdkTest-10,11,12,13 (#2742) --- packages/create-plugin/__e2e__/e2e.test.ts | 428 +++++------------- .../__e2e__/fixtures/allOptions.ts | 93 ++++ .../fixtures/createKintonePluginCommand.ts | 93 ++++ .../__e2e__/fixtures/emptyOutputDir.ts | 15 + .../__e2e__/fixtures/existOutputDir.ts | 22 + .../pluginDescriptionContain200Chars.ts | 58 +++ .../pluginDescriptionContain201Chars.ts | 28 ++ .../fixtures/pluginNameContain64Chars.ts | 58 +++ .../fixtures/pluginNameContain65Chars.ts | 24 + .../__e2e__/fixtures/requiredOptions.ts | 56 +++ packages/create-plugin/__e2e__/setup.ts | 5 + .../__e2e__/utils/executeCommand.ts | 4 +- packages/create-plugin/jest.e2e.config.js | 1 + 13 files changed, 557 insertions(+), 328 deletions(-) create mode 100644 packages/create-plugin/__e2e__/fixtures/allOptions.ts create mode 100644 packages/create-plugin/__e2e__/fixtures/createKintonePluginCommand.ts create mode 100644 packages/create-plugin/__e2e__/fixtures/emptyOutputDir.ts create mode 100644 packages/create-plugin/__e2e__/fixtures/existOutputDir.ts create mode 100644 packages/create-plugin/__e2e__/fixtures/pluginDescriptionContain200Chars.ts create mode 100644 packages/create-plugin/__e2e__/fixtures/pluginDescriptionContain201Chars.ts create mode 100644 packages/create-plugin/__e2e__/fixtures/pluginNameContain64Chars.ts create mode 100644 packages/create-plugin/__e2e__/fixtures/pluginNameContain65Chars.ts create mode 100644 packages/create-plugin/__e2e__/fixtures/requiredOptions.ts create mode 100644 packages/create-plugin/__e2e__/setup.ts diff --git a/packages/create-plugin/__e2e__/e2e.test.ts b/packages/create-plugin/__e2e__/e2e.test.ts index 8fcab7e2a3..80d3896633 100644 --- a/packages/create-plugin/__e2e__/e2e.test.ts +++ b/packages/create-plugin/__e2e__/e2e.test.ts @@ -5,8 +5,6 @@ import { CREATE_PLUGIN_COMMAND, DEFAULT_ANSWER, ANSWER_NO, - ANSWER_YES, - CREATE_KINTONE_PLUGIN_COMMAND, } from "./utils/constants"; import path from "path"; import { generateWorkingDir } from "./utils/generateWorkingDir"; @@ -17,7 +15,36 @@ import { readPluginManifestJson, } from "./utils/verification"; import { getBoundMessage } from "../src/messages"; -import { generateRandomString } from "./utils/helper"; +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"; + +export type TestPattern = { + description: string; + prepareFn?: (...arg: any[]) => void; + input: { + command: string; + outputDir: string; + questionsInput: QuestionInput[]; + commandArgument?: string; + template?: "minimum" | "modern"; + }; + expected: { + success?: { + manifestJson: { [key: PropertyKey]: unknown }; + }; + failure?: { + stdout?: string; + stderr?: string; + }; + }; +}; describe("create-plugin", function () { let workingDir: string; @@ -26,135 +53,88 @@ describe("create-plugin", function () { console.log(`Working directory: ${workingDir}`); }); - it("#JsSdkTest-1 Should able to create a plugin with specified output directory and required options successfully", async () => { - const m = getBoundMessage("en"); - const outputDir = "test1"; - const questionsInput: QuestionInput[] = [ - { - question: m("Q_NameEn"), - answer: "test1-name", - }, - { - question: m("Q_DescriptionEn"), - answer: "test1-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, - }, - ]; + const patterns = [ + requiredOptions, + pluginNameContain64Chars, + pluginDescriptionContain200Chars, + allOptions, + emptyOutputDir, + existOutputDir, + pluginNameContain65Chars, + pluginDescriptionContain201Chars, + createKintonePluginCommand, + ]; + + it.each(patterns)("$description", async ({ prepareFn, input, expected }) => { + if (prepareFn) { + prepareFn({ workingDir }); + } const response = await executeCommandWithInteractiveInput({ - command: CREATE_PLUGIN_COMMAND, + command: input.command, workingDir, - outputDir, - questionsInput, + outputDir: input.outputDir, + questionsInput: input.questionsInput, + commandArguments: input.commandArgument, }); - assert(response.status === 0, "Failed to create plugin"); - - const pluginDir = path.resolve(workingDir, outputDir); - assert.ok(fs.existsSync(pluginDir), "plugin dir is not created."); - - const actualManifestJson = readPluginManifestJson(pluginDir); - const expectedManifestJson = { - name: { en: "test1-name" }, - description: { en: "test1-description" }, - }; - assertObjectIncludes(actualManifestJson, expectedManifestJson); - }); - - it("#JsSdkTest-2 Should able to create a plugin with plugin-in name contains 64 characters", async () => { - const m = getBoundMessage("en"); - const outputDir = "test2"; - const pluginName = generateRandomString(64); - const questionsInput: QuestionInput[] = [ - { - question: m("Q_NameEn"), - answer: pluginName, - }, - { - question: m("Q_DescriptionEn"), - answer: "64characters", - }, - { - question: m("Q_SupportJa"), - answer: ANSWER_NO, - }, - { - question: m("Q_SupportZh"), - answer: ANSWER_NO, - }, - { - question: m("Q_WebsiteUrlEn"), - answer: DEFAULT_ANSWER, - }, - { - question: m("Q_MobileSupport"), - answer: ANSWER_NO, - }, - { - question: m("Q_EnablePluginUploader"), - answer: ANSWER_NO, - }, - ]; - - const response = await executeCommandWithInteractiveInput({ - command: CREATE_PLUGIN_COMMAND, - workingDir, - outputDir, - questionsInput, - }); + if (expected.success !== undefined) { + assert(response.status === 0, "Failed to create plugin"); - assert(response.status === 0, "Failed to create plugin"); + const pluginDir = path.resolve(workingDir, input.outputDir); + assert.ok(fs.existsSync(pluginDir), "plugin dir is not created."); - const pluginDir = path.resolve(workingDir, outputDir); - assert.ok(fs.existsSync(pluginDir), "plugin dir is not created."); + const actualManifestJson = readPluginManifestJson( + pluginDir, + input.template, + ); + assertObjectIncludes(actualManifestJson, expected.success.manifestJson); + } - const actualManifestJson = readPluginManifestJson(pluginDir); - const expectedManifestJson = { - name: { en: pluginName }, - description: { en: "64characters" }, - }; - assertObjectIncludes(actualManifestJson, expectedManifestJson); + if (expected.failure !== undefined) { + assert.notEqual(response.status, 0, "The command should throw an error."); + if (expected.failure.stdout) { + assert.match( + response.stdout.toString().trim(), + new RegExp(expected.failure.stdout), + ); + } + + if (expected.failure.stderr) { + assert.match( + response.stderr.toString().trim(), + new RegExp(expected.failure.stderr), + ); + } + } }); - it("#JsSdkTest-3 Should able to create a plugin with plugin-in description contains 200 characters", async () => { + it("#JsSdkTest-11 Should throw an error when the output directory contains forbidden characters", async () => { const m = getBoundMessage("en"); - const outputDir = "test3"; - const pluginDescription = generateRandomString(200); + let outputDir: string; + const isWindows = process.platform === "win32"; + if (isWindows) { + outputDir = ":"; + } else { + outputDir = "/"; + } + const questionsInput: QuestionInput[] = [ { question: m("Q_NameEn"), - answer: "200characters", + answer: "test11-name", }, { question: m("Q_DescriptionEn"), - answer: pluginDescription, + answer: "test11-description", }, { question: m("Q_SupportJa"), - answer: ANSWER_NO, + answer: DEFAULT_ANSWER, }, { question: m("Q_SupportZh"), - answer: ANSWER_NO, + answer: DEFAULT_ANSWER, }, { question: m("Q_WebsiteUrlEn"), @@ -177,223 +157,19 @@ describe("create-plugin", function () { questionsInput, }); - assert(response.status === 0, "Failed to create plugin"); - - const pluginDir = path.resolve(workingDir, outputDir); - assert.ok(fs.existsSync(pluginDir), "plugin dir is not created."); - - const actualManifestJson = readPluginManifestJson(pluginDir); - const expectedManifestJson = { - name: { en: "200characters" }, - description: { en: pluginDescription }, - }; - assertObjectIncludes(actualManifestJson, expectedManifestJson); - }); - - it("#JsSdkTest-4 Should able to create a plugin with specified output directory and all options successfully", async () => { - const m = getBoundMessage("en"); - const outputDir = "test1"; - const questionsInput: QuestionInput[] = [ - { - question: m("Q_NameEn"), - answer: "test4-name", - }, - { - question: m("Q_DescriptionEn"), - answer: "test4-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_YES, - }, - { - question: m("Q_EnablePluginUploader"), - answer: ANSWER_YES, - }, - ]; - - const response = await executeCommandWithInteractiveInput({ - command: CREATE_PLUGIN_COMMAND, - workingDir, - outputDir, - questionsInput, - }); - - assert(response.status === 0, "Failed to create plugin"); - - const pluginDir = path.resolve(workingDir, outputDir); - assert.ok(fs.existsSync(pluginDir), "plugin dir is not created."); - - const actualManifestJson = readPluginManifestJson(pluginDir); - const expectedManifestJson = { - name: { - en: "test4-name", - ja: "私のプラグイン", - zh: "我的插件", - }, - description: { - en: "test4-description", - ja: "私のプラグイン", - zh: "我的插件", - }, - homepage_url: { - en: "https://github.com", - ja: "https://github.jp", - zh: "https://github.cn", - }, - mobile: { - js: ["js/mobile.js"], - css: ["css/mobile.css"], - }, - }; - assertObjectIncludes(actualManifestJson, expectedManifestJson); - }); - - it("#JsSdkTest-9 Should throw an error when the output directory is empty", async () => { - const outputDir = ""; - const response = await executeCommandWithInteractiveInput({ - command: CREATE_PLUGIN_COMMAND, - workingDir, - outputDir, - questionsInput: [], - }); - - assert.notEqual(response.status, 0, "The command should throw an error."); - assert.equal( - response.stderr.toString().trim(), - "Please specify the output directory", - ); - }); - - it("#JsSdkTest-14 Should able to create plugin with `create-kintone-plugin` command and all options", async () => { - const m = getBoundMessage("en"); - const outputDir = "test14"; - const questionsInput: QuestionInput[] = [ - { - question: m("Q_NameEn"), - answer: "test14-name", - }, - { - question: m("Q_DescriptionEn"), - answer: "test14-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_YES, - }, - { - question: m("Q_EnablePluginUploader"), - answer: ANSWER_YES, - }, - ]; - - const response = await executeCommandWithInteractiveInput({ - command: CREATE_KINTONE_PLUGIN_COMMAND, - workingDir, - outputDir, - questionsInput, - }); - - assert(response.status === 0, "Failed to create plugin"); - - const pluginDir = path.resolve(workingDir, outputDir); - assert.ok(fs.existsSync(pluginDir), "plugin dir is not created."); - - const actualManifestJson = readPluginManifestJson(pluginDir); - const expectedManifestJson = { - name: { - en: "test14-name", - ja: "私のプラグイン", - zh: "我的插件", - }, - description: { - en: "test14-description", - ja: "私のプラグイン", - zh: "我的插件", - }, - homepage_url: { - en: "https://github.com", - ja: "https://github.jp", - zh: "https://github.cn", - }, - mobile: { - js: ["js/mobile.js"], - css: ["css/mobile.css"], - }, - }; - assertObjectIncludes(actualManifestJson, expectedManifestJson); + if (isWindows) { + assert.equal(response.status, 0); + assert.match( + response.stderr.toString().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(), + /Error: \/ already exists. Choose a different directory/, + ); + } }); afterEach(() => { diff --git a/packages/create-plugin/__e2e__/fixtures/allOptions.ts b/packages/create-plugin/__e2e__/fixtures/allOptions.ts new file mode 100644 index 0000000000..f8fe4d9318 --- /dev/null +++ b/packages/create-plugin/__e2e__/fixtures/allOptions.ts @@ -0,0 +1,93 @@ +import type { TestPattern } from "../e2e.test"; +import { ANSWER_YES, CREATE_PLUGIN_COMMAND } from "../utils/constants"; +import { getBoundMessage } from "../../src/messages"; + +const m = getBoundMessage("en"); + +export const pattern: TestPattern = { + description: + "#JsSdkTest-4 Should able to create a plugin with specified output directory and all options successfully", + input: { + command: CREATE_PLUGIN_COMMAND, + outputDir: "test4", + questionsInput: [ + { + question: m("Q_NameEn"), + answer: "test4-name", + }, + { + question: m("Q_DescriptionEn"), + answer: "test4-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_YES, + }, + { + question: m("Q_EnablePluginUploader"), + answer: ANSWER_YES, + }, + ], + }, + expected: { + success: { + manifestJson: { + name: { + en: "test4-name", + ja: "私のプラグイン", + zh: "我的插件", + }, + description: { + en: "test4-description", + ja: "私のプラグイン", + zh: "我的插件", + }, + homepage_url: { + en: "https://github.com", + ja: "https://github.jp", + zh: "https://github.cn", + }, + mobile: { + js: ["js/mobile.js"], + css: ["css/mobile.css"], + }, + }, + }, + }, +}; diff --git a/packages/create-plugin/__e2e__/fixtures/createKintonePluginCommand.ts b/packages/create-plugin/__e2e__/fixtures/createKintonePluginCommand.ts new file mode 100644 index 0000000000..98d6be9218 --- /dev/null +++ b/packages/create-plugin/__e2e__/fixtures/createKintonePluginCommand.ts @@ -0,0 +1,93 @@ +import type { TestPattern } from "../e2e.test"; +import { ANSWER_YES, CREATE_KINTONE_PLUGIN_COMMAND } from "../utils/constants"; +import { getBoundMessage } from "../../src/messages"; + +const m = getBoundMessage("en"); + +export const pattern: TestPattern = { + description: + "#JsSdkTest-14 Should able to create plugin with `create-kintone-plugin` command and all options", + input: { + command: CREATE_KINTONE_PLUGIN_COMMAND, + outputDir: "test14", + questionsInput: [ + { + question: m("Q_NameEn"), + answer: "test14-name", + }, + { + question: m("Q_DescriptionEn"), + answer: "test14-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_YES, + }, + { + question: m("Q_EnablePluginUploader"), + answer: ANSWER_YES, + }, + ], + }, + expected: { + success: { + manifestJson: { + name: { + en: "test14-name", + ja: "私のプラグイン", + zh: "我的插件", + }, + description: { + en: "test14-description", + ja: "私のプラグイン", + zh: "我的插件", + }, + homepage_url: { + en: "https://github.com", + ja: "https://github.jp", + zh: "https://github.cn", + }, + mobile: { + js: ["js/mobile.js"], + css: ["css/mobile.css"], + }, + }, + }, + }, +}; diff --git a/packages/create-plugin/__e2e__/fixtures/emptyOutputDir.ts b/packages/create-plugin/__e2e__/fixtures/emptyOutputDir.ts new file mode 100644 index 0000000000..81ac20ee6b --- /dev/null +++ b/packages/create-plugin/__e2e__/fixtures/emptyOutputDir.ts @@ -0,0 +1,15 @@ +import type { TestPattern } from "../e2e.test"; +import { CREATE_PLUGIN_COMMAND } from "../utils/constants"; + +export const pattern: TestPattern = { + description: + "#JsSdkTest-9 Should throw an error when the output directory is empty", + input: { + command: CREATE_PLUGIN_COMMAND, + outputDir: "", + questionsInput: [], + }, + expected: { + failure: { stderr: "Please specify the output directory" }, + }, +}; diff --git a/packages/create-plugin/__e2e__/fixtures/existOutputDir.ts b/packages/create-plugin/__e2e__/fixtures/existOutputDir.ts new file mode 100644 index 0000000000..f4a425fbf9 --- /dev/null +++ b/packages/create-plugin/__e2e__/fixtures/existOutputDir.ts @@ -0,0 +1,22 @@ +import type { TestPattern } from "../e2e.test"; +import { CREATE_PLUGIN_COMMAND } from "../utils/constants"; +import fs from "fs"; + +const outputDir = "test10"; +export const pattern: TestPattern = { + description: + "#JsSdkTest-10 Should throw an error when the output directory is duplicated with the existent directory", + prepareFn: (settings: { workingDir: string }) => { + fs.mkdirSync(`${settings.workingDir}/${outputDir}`); + }, + input: { + command: CREATE_PLUGIN_COMMAND, + outputDir: outputDir, + questionsInput: [], + }, + expected: { + failure: { + stderr: `Error: ${outputDir} already exists. Choose a different directory`, + }, + }, +}; diff --git a/packages/create-plugin/__e2e__/fixtures/pluginDescriptionContain200Chars.ts b/packages/create-plugin/__e2e__/fixtures/pluginDescriptionContain200Chars.ts new file mode 100644 index 0000000000..8d5d0b497b --- /dev/null +++ b/packages/create-plugin/__e2e__/fixtures/pluginDescriptionContain200Chars.ts @@ -0,0 +1,58 @@ +import type { TestPattern } from "../e2e.test"; +import { + ANSWER_NO, + CREATE_PLUGIN_COMMAND, + DEFAULT_ANSWER, +} from "../utils/constants"; +import { getBoundMessage } from "../../src/messages"; +import { generateRandomString } from "../utils/helper"; + +const m = getBoundMessage("en"); +const pluginDescription = generateRandomString(200); + +export const pattern: TestPattern = { + description: + "#JsSdkTest-3 Should able to create a plugin with plugin-in description contains 200 characters", + input: { + command: CREATE_PLUGIN_COMMAND, + outputDir: "test3", + questionsInput: [ + { + question: m("Q_NameEn"), + answer: "200characters", + }, + { + question: m("Q_DescriptionEn"), + answer: pluginDescription, + }, + { + question: m("Q_SupportJa"), + answer: ANSWER_NO, + }, + { + question: m("Q_SupportZh"), + answer: ANSWER_NO, + }, + { + 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: "200characters" }, + description: { en: pluginDescription }, + }, + }, + }, +}; diff --git a/packages/create-plugin/__e2e__/fixtures/pluginDescriptionContain201Chars.ts b/packages/create-plugin/__e2e__/fixtures/pluginDescriptionContain201Chars.ts new file mode 100644 index 0000000000..3a639b6b40 --- /dev/null +++ b/packages/create-plugin/__e2e__/fixtures/pluginDescriptionContain201Chars.ts @@ -0,0 +1,28 @@ +import type { TestPattern } from "../e2e.test"; +import { CREATE_PLUGIN_COMMAND } from "../utils/constants"; +import { generateRandomString } from "../utils/helper"; +import { getBoundMessage } from "../../src/messages"; + +const m = getBoundMessage("en"); + +export const pattern: TestPattern = { + description: + "#JsSdkTest-13 Should throw an error when creating plugin with plugin-in description contains 201 characters", + input: { + command: CREATE_PLUGIN_COMMAND, + outputDir: "test13", + questionsInput: [ + { + question: m("Q_NameEn"), + answer: "test13", + }, + { + question: m("Q_DescriptionEn"), + answer: generateRandomString(201), + }, + ], + }, + expected: { + failure: { stdout: ">> Plug-in description must be 1-200chars" }, + }, +}; diff --git a/packages/create-plugin/__e2e__/fixtures/pluginNameContain64Chars.ts b/packages/create-plugin/__e2e__/fixtures/pluginNameContain64Chars.ts new file mode 100644 index 0000000000..fdc5d7571a --- /dev/null +++ b/packages/create-plugin/__e2e__/fixtures/pluginNameContain64Chars.ts @@ -0,0 +1,58 @@ +import type { TestPattern } from "../e2e.test"; +import { + ANSWER_NO, + CREATE_PLUGIN_COMMAND, + DEFAULT_ANSWER, +} from "../utils/constants"; +import { getBoundMessage } from "../../src/messages"; +import { generateRandomString } from "../utils/helper"; + +const m = getBoundMessage("en"); +const pluginName = generateRandomString(64); + +export const pattern: TestPattern = { + description: + "#JsSdkTest-2 Should able to create a plugin with plugin-in name contains 64 characters", + input: { + command: CREATE_PLUGIN_COMMAND, + outputDir: "test2", + questionsInput: [ + { + question: m("Q_NameEn"), + answer: pluginName, + }, + { + question: m("Q_DescriptionEn"), + answer: "64characters", + }, + { + question: m("Q_SupportJa"), + answer: ANSWER_NO, + }, + { + question: m("Q_SupportZh"), + answer: ANSWER_NO, + }, + { + 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: pluginName }, + description: { en: "64characters" }, + }, + }, + }, +}; diff --git a/packages/create-plugin/__e2e__/fixtures/pluginNameContain65Chars.ts b/packages/create-plugin/__e2e__/fixtures/pluginNameContain65Chars.ts new file mode 100644 index 0000000000..7a55c11a7a --- /dev/null +++ b/packages/create-plugin/__e2e__/fixtures/pluginNameContain65Chars.ts @@ -0,0 +1,24 @@ +import type { TestPattern } from "../e2e.test"; +import { CREATE_PLUGIN_COMMAND } from "../utils/constants"; +import { generateRandomString } from "../utils/helper"; +import { getBoundMessage } from "../../src/messages"; + +const m = getBoundMessage("en"); + +export const pattern: TestPattern = { + description: + "#JsSdkTest-12 Should throw an error when creating plugin with plugin-in name contains 65 characters", + input: { + command: CREATE_PLUGIN_COMMAND, + outputDir: "test12", + questionsInput: [ + { + question: m("Q_NameEn"), + answer: generateRandomString(65), + }, + ], + }, + expected: { + failure: { stdout: ">> Plug-in name must be 1-64chars" }, + }, +}; diff --git a/packages/create-plugin/__e2e__/fixtures/requiredOptions.ts b/packages/create-plugin/__e2e__/fixtures/requiredOptions.ts new file mode 100644 index 0000000000..13d694cabf --- /dev/null +++ b/packages/create-plugin/__e2e__/fixtures/requiredOptions.ts @@ -0,0 +1,56 @@ +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"); + +export const pattern: TestPattern = { + description: + "#JsSdkTest-1 Should able to create a plugin with specified output directory and required options successfully", + input: { + command: CREATE_PLUGIN_COMMAND, + outputDir: "test1", + questionsInput: [ + { + question: m("Q_NameEn"), + answer: "test1-name", + }, + { + question: m("Q_DescriptionEn"), + answer: "test1-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: "test1-name" }, + description: { en: "test1-description" }, + }, + }, + }, +}; diff --git a/packages/create-plugin/__e2e__/setup.ts b/packages/create-plugin/__e2e__/setup.ts new file mode 100644 index 0000000000..6e0bb99617 --- /dev/null +++ b/packages/create-plugin/__e2e__/setup.ts @@ -0,0 +1,5 @@ +const isRunOnActions = () => !!process.env.GITHUB_ACTIONS; + +if (isRunOnActions()) { + jest.retryTimes(3, { logErrorsBeforeRetry: true }); +} diff --git a/packages/create-plugin/__e2e__/utils/executeCommand.ts b/packages/create-plugin/__e2e__/utils/executeCommand.ts index 956464805c..96f5d6dcab 100644 --- a/packages/create-plugin/__e2e__/utils/executeCommand.ts +++ b/packages/create-plugin/__e2e__/utils/executeCommand.ts @@ -75,7 +75,7 @@ export const executeCommandWithInteractiveInput = async (options: { throw new Error(`Command ${command} not found.`); } - const commandString = `${commands[command]} ${commandArguments || ""} ${outputDir}`; + const commandString = `${commands[command]} ${commandArguments || ""} "${outputDir}"`; const cliProcess = execCommand("node", commandString, { cwd: workingDir, }); @@ -115,7 +115,7 @@ export const executeCommandWithInteractiveInput = async (options: { }); cliProcess.stderr.on("data", async (data: Buffer) => { - stderr = data; + stderr = stderr ? Buffer.concat([stderr, data]) : data; cliProcess.stdin.end(); }); diff --git a/packages/create-plugin/jest.e2e.config.js b/packages/create-plugin/jest.e2e.config.js index e9670b536c..b6c9727843 100644 --- a/packages/create-plugin/jest.e2e.config.js +++ b/packages/create-plugin/jest.e2e.config.js @@ -3,6 +3,7 @@ const config = { roots: [""], testRegex: "/__e2e__/.*\\.test\\.ts$", testEnvironment: "./JestCustomEnvironment.js", + setupFilesAfterEnv: ["/__e2e__/setup.ts"], testTimeout: 120000, }; module.exports = config;