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

新增插件在macos和windows下的冒烟测试 #34

Merged
merged 13 commits into from
Apr 18, 2024
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
51 changes: 51 additions & 0 deletions .github/workflows/smoketest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Smoke Test

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
smoke-test-macos:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: "20"

- name: Install Yarn
run: npm install --global yarn

- name: Install Dependencies
run: yarn install

- name: Install Dependencies Media
run: cd media && yarn install

- name: Run Smoke Test
run: npm run test
smoke-test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: "20"

- name: Install Yarn
run: npm install --global yarn

- name: Install Dependencies
run: yarn install

- name: Install Dependencies Media
run: cd media && yarn install

- name: Run Smoke Test
run: npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ media/lib/
scripts/dev/
yarn-error.log
out/
.nyc_output/
.vscode-test/
tsconfig.tsbuildinfo
*.tsbuildinfo
Expand Down
5 changes: 1 addition & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"editor.formatOnSave": true,
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
2 changes: 1 addition & 1 deletion media/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "lib/server.js",
"scripts": {
"start": "vite --mode browser",
"build:client": "NODE_ENV=production vite build",
"build:client": "vite build",
"build:server": "ncc build src/server.ts -o lib -m -e *.css",
"build": "npm run build:client && npm run build:server",
"preview": "vite preview",
Expand Down
10 changes: 2 additions & 8 deletions media/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import * as path from "path";
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
root: "",
resolve: {
alias: {
react: path.join(__dirname, "../../../node_modules/react"),
"react-dom": path.join(__dirname, "../../../node_modules/react-dom"),
},
},
resolve: {},
build: {
// minify: false,
rollupOptions: {
Expand Down
38 changes: 31 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,34 @@
"scripts": {
"clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
"watch": "rimraf dist && tsc --build --watch",
"build": "npm run esbuild",
"build": "rimraf dist && tsc --build",
"media": "cd media && vite --mode browser",
"package": "vsce package",
"build:media": "cd media && npm run build:ncc",
"build:media": "cd media && npm run build",
"reinstall": "rimraf node_modules && npm i",
"afterinstall": "cd ../../ && lerna bootstrap",
"build:ncc": "rimraf dist && ncc build ./src/extension.ts -o dist -m --license licenses.txt && mv dist/index.js dist/extension.js",
"vscode:prepublish": "npm run build:ncc",
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --minify",
"esbuild": "npm run esbuild-base -- --sourcemap",
"esbuild-watch": "npm run esbuild-base -- --sourcemap --watch",
"preview": "cd media && vite build --watch"
"preview": "cd media && vite build --watch",
"pretest": "npm run build:media && npm run build",
"test": "node ./dist/test/runTest.js",
"test-coverage": "nyc npm run test"
},
"nyc": {
"include": [
"src/**/*.ts"
],
"extension": [
".ts"
],
"reporter": [
"text-summary",
"html"
],
"all": true
},
"dependencies": {
"@alicloud/credentials": "^2.1.1",
Expand All @@ -227,16 +243,12 @@
"@alicloud/tea-util": "^1.4.2",
"@types/node": "^20.10.5",
"@vscode/codicons": "^0.0.32",
"assert": "^2.0.0",
"debug": "^4.3.0",
"eslint": "^8.16.0",
"fs-extra": "^10.1.0",
"httpx": "^2.2.6",
"kitx": "^2.1.0",
"lodash": "^4.17.20",
"mockjs": "^1.0.1-beta3",
"moment": "^2.24.0",
"ncc": "^0.3.6",
"needle": "^2.5.0",
"pontx-manager": "0.3.83-beta.0",
"pontx-meta-fetch-plugin": "0.3.83",
Expand All @@ -255,14 +267,26 @@
"type": "git"
},
"devDependencies": {
"mockjs": "^1.0.1-beta3",
"assert": "^2.0.0",
"ncc": "^0.3.6",
"@types/fs-extra": "^5.1.0",
"@types/lodash": "^4.14.182",
"@types/mocha": "^10.0.3",
"@types/node": "18.x",
"@types/react": "^18.0.8",
"@types/react-dom": "^18.0.3",
"@types/vscode": "^1.47.0",
"@types/vscode-webview": "^1.57.0",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"@vercel/ncc": "^0.38.1",
"@vitejs/plugin-react": "^1.3.2",
"@vscode/test-electron": "^2.3.9",
"eslint": "^8.52.0",
"glob": "^10.3.10",
"mocha": "^10.4.0",
"nyc": "^15.1.0",
"prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.13",
"rimraf": "^3.0.2",
Expand Down
92 changes: 51 additions & 41 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { PontManager } from "pontx-manager";
import * as _ from "lodash";
import * as vscode from "vscode";
import { findAlicloudAPIConfig, findInterface, getSpecInfoFromName, plugins, showProgress, viewMetaFile, VSCodeLogger, wait } from "./utils";
import {
findAlicloudAPIConfig,
findInterface,
getSpecInfoFromName,
plugins,
showProgress,
viewMetaFile,
VSCodeLogger,
wait,
} from "./utils";
import { AlicloudAPIWebview } from "./webview";
import { alicloudAPIMessageService } from "./Service";
import { PontSpec } from "pontx-spec";
Expand Down Expand Up @@ -103,53 +112,53 @@ export class AlicloudApiCommands {

Promise.resolve(service.pontManager.innerManagerConfig.plugins.generate?.instance).then(
async (generatePlugin) => {
const {product, version} = getSpecInfoFromName(specName || "");
const { product, version } = getSpecInfoFromName(specName || "");
const snippets = await codeSampleProvider({
language: vscode.window.activeTextEditor?.document.languageId || "typescript",
product: product,
version: version,
apiName: apiName,
simplify: true,
});
const VIEW_API_DOC_ID = "VSCODE_PONTX_SHOW_PICK_ITEM_VIEW_API_DOC";
let pickItems = [
{
label: "查看文档",
id: VIEW_API_DOC_ID,
},
const VIEW_API_DOC_ID = "VSCODE_PONTX_SHOW_PICK_ITEM_VIEW_API_DOC";
let pickItems = [
{
label: "查看文档",
id: VIEW_API_DOC_ID,
},
];
if (snippets?.length && vscode.window.activeTextEditor) {
pickItems = [
...pickItems,
...snippets.map((snippet) => {
return {
label: "插入代码段: " + snippet.name,
id: snippet.name,
description: snippet.description,
};
}),
];
if (snippets?.length && vscode.window.activeTextEditor) {
pickItems = [
...pickItems,
...snippets.map((snippet) => {
return {
label: "插入代码段: " + snippet.name,
id: snippet.name,
description: snippet.description,
};
}),
];
}
return vscode.window
.showQuickPick(pickItems, {
matchOnDescription: true,
matchOnDetail: true,
})
.then((snippet) => {
const foundSnippet = snippets.find((inst) => inst.name === snippet?.id);
if (foundSnippet) {
insertCode(foundSnippet.code);
} else if (snippet.id === VIEW_API_DOC_ID) {
vscode.commands.executeCommand("alicloud.api.openDocument", {
specName,
modName,
name: apiName,
spec: apiMeta,
pageType: "document",
schemaType: "api",
});
}
});
}
return vscode.window
.showQuickPick(pickItems, {
matchOnDescription: true,
matchOnDetail: true,
})
.then((snippet) => {
const foundSnippet = snippets.find((inst) => inst.name === snippet?.id);
if (foundSnippet) {
insertCode(foundSnippet.code);
} else if (snippet.id === VIEW_API_DOC_ID) {
vscode.commands.executeCommand("alicloud.api.openDocument", {
specName,
modName,
name: apiName,
spec: apiMeta,
pageType: "document",
schemaType: "api",
});
}
});
},
);
});
Expand Down Expand Up @@ -251,7 +260,7 @@ export class AlicloudApiCommands {
const lastPromptKey = "lastPromptTime";
const globalState = context.globalState;
globalState.update(lastPromptKey, undefined);
console.log("update last prompt key to",globalState.get(lastPromptKey))
console.log("update last prompt key to", globalState.get(lastPromptKey));
});

vscode.commands.registerCommand("alicloud.api.restart", async () => {
Expand Down Expand Up @@ -283,6 +292,7 @@ export class AlicloudApiCommands {
}
},
);
return "ok";
});
vscode.commands.registerCommand("alicloud.api.openPontPanel", async () => {
await vscode.commands.executeCommand("alicloudApiExplorer.focus");
Expand Down
23 changes: 23 additions & 0 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as path from 'path';

import { runTests } from '@vscode/test-electron';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests', err);
process.exit(1);
}
}

main();
33 changes: 33 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as assert from "assert";
import { after, before } from "mocha";

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from "vscode";

suite("Extension Test Suite", () => {
vscode.window.showInformationMessage("Start all tests.");
before(async () => {
// 确保插件激活
const extension = vscode.extensions.getExtension("alibabacloud-openapi.vscode-alicloud-api");
if (!extension.isActive) {
await extension.activate();
}
console.log("Extension activate.");
});

after(() => {
console.log("All tests done!");
});

test("Test alicloud.api.restart command", async () => {
const result = await vscode.commands.executeCommand("alicloud.api.restart");
console.log("alicloud.api.restart successfully executed");
assert.strictEqual("ok", result);
});

test("Sample test", () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});
Loading
Loading