Skip to content

Commit 6114f56

Browse files
authored
新增插件在macos和windows下的冒烟测试 (#34)
* test: github actions * test: init vscode-test * test: init vscode-test windows * test: add vscode command alicloud.api.restart test * test: add vscode command alicloud.api.restart test * test: add vscode command alicloud.api.restart test * test: add vscode command alicloud.api.restart test * test: add vscode command alicloud.api.restart test * test: add vscode command alicloud.api.restart test * test: add vscode command alicloud.api.restart test * test: alicloud.api.restart * test: Change the github actions trigger condition. * fix: Tidy up dependencies.
1 parent 04d68d2 commit 6114f56

File tree

11 files changed

+978
-95
lines changed

11 files changed

+978
-95
lines changed

.github/workflows/smoketest.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Smoke Test
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
smoke-test-macos:
11+
runs-on: macOS-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: "20"
19+
20+
- name: Install Yarn
21+
run: npm install --global yarn
22+
23+
- name: Install Dependencies
24+
run: yarn install
25+
26+
- name: Install Dependencies Media
27+
run: cd media && yarn install
28+
29+
- name: Run Smoke Test
30+
run: npm run test
31+
smoke-test-windows:
32+
runs-on: windows-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Set up Node.js
37+
uses: actions/setup-node@v1
38+
with:
39+
node-version: "20"
40+
41+
- name: Install Yarn
42+
run: npm install --global yarn
43+
44+
- name: Install Dependencies
45+
run: yarn install
46+
47+
- name: Install Dependencies Media
48+
run: cd media && yarn install
49+
50+
- name: Run Smoke Test
51+
run: npm run test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ media/lib/
2323
scripts/dev/
2424
yarn-error.log
2525
out/
26+
.nyc_output/
2627
.vscode-test/
2728
tsconfig.tsbuildinfo
2829
*.tsbuildinfo

.vscode/settings.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"editor.formatOnSave": true,
33
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
4-
"editor.defaultFormatter": "esbenp.prettier-vscode",
5-
"editor.codeActionsOnSave": {
6-
"source.organizeImports": "explicit"
7-
}
4+
"editor.defaultFormatter": "esbenp.prettier-vscode"
85
}

media/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "lib/server.js",
66
"scripts": {
77
"start": "vite --mode browser",
8-
"build:client": "NODE_ENV=production vite build",
8+
"build:client": "vite build",
99
"build:server": "ncc build src/server.ts -o lib -m -e *.css",
1010
"build": "npm run build:client && npm run build:server",
1111
"preview": "vite preview",

media/vite.config.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import { defineConfig } from "vite";
21
import react from "@vitejs/plugin-react";
3-
import * as path from "path";
2+
import { defineConfig } from "vite";
43

54
// https://vitejs.dev/config/
65
export default defineConfig({
76
plugins: [react()],
87
root: "",
9-
resolve: {
10-
alias: {
11-
react: path.join(__dirname, "../../../node_modules/react"),
12-
"react-dom": path.join(__dirname, "../../../node_modules/react-dom"),
13-
},
14-
},
8+
resolve: {},
159
build: {
1610
// minify: false,
1711
rollupOptions: {

package.json

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,34 @@
207207
"scripts": {
208208
"clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
209209
"watch": "rimraf dist && tsc --build --watch",
210-
"build": "npm run esbuild",
210+
"build": "rimraf dist && tsc --build",
211211
"media": "cd media && vite --mode browser",
212212
"package": "vsce package",
213-
"build:media": "cd media && npm run build:ncc",
213+
"build:media": "cd media && npm run build",
214214
"reinstall": "rimraf node_modules && npm i",
215215
"afterinstall": "cd ../../ && lerna bootstrap",
216216
"build:ncc": "rimraf dist && ncc build ./src/extension.ts -o dist -m --license licenses.txt && mv dist/index.js dist/extension.js",
217217
"vscode:prepublish": "npm run build:ncc",
218218
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --minify",
219219
"esbuild": "npm run esbuild-base -- --sourcemap",
220220
"esbuild-watch": "npm run esbuild-base -- --sourcemap --watch",
221-
"preview": "cd media && vite build --watch"
221+
"preview": "cd media && vite build --watch",
222+
"pretest": "npm run build:media && npm run build",
223+
"test": "node ./dist/test/runTest.js",
224+
"test-coverage": "nyc npm run test"
225+
},
226+
"nyc": {
227+
"include": [
228+
"src/**/*.ts"
229+
],
230+
"extension": [
231+
".ts"
232+
],
233+
"reporter": [
234+
"text-summary",
235+
"html"
236+
],
237+
"all": true
222238
},
223239
"dependencies": {
224240
"@alicloud/credentials": "^2.1.1",
@@ -227,16 +243,12 @@
227243
"@alicloud/tea-util": "^1.4.2",
228244
"@types/node": "^20.10.5",
229245
"@vscode/codicons": "^0.0.32",
230-
"assert": "^2.0.0",
231246
"debug": "^4.3.0",
232-
"eslint": "^8.16.0",
233247
"fs-extra": "^10.1.0",
234248
"httpx": "^2.2.6",
235249
"kitx": "^2.1.0",
236250
"lodash": "^4.17.20",
237-
"mockjs": "^1.0.1-beta3",
238251
"moment": "^2.24.0",
239-
"ncc": "^0.3.6",
240252
"needle": "^2.5.0",
241253
"pontx-manager": "0.3.83-beta.0",
242254
"pontx-meta-fetch-plugin": "0.3.83",
@@ -255,14 +267,26 @@
255267
"type": "git"
256268
},
257269
"devDependencies": {
270+
"mockjs": "^1.0.1-beta3",
271+
"assert": "^2.0.0",
272+
"ncc": "^0.3.6",
258273
"@types/fs-extra": "^5.1.0",
259274
"@types/lodash": "^4.14.182",
275+
"@types/mocha": "^10.0.3",
276+
"@types/node": "18.x",
260277
"@types/react": "^18.0.8",
261278
"@types/react-dom": "^18.0.3",
262279
"@types/vscode": "^1.47.0",
263280
"@types/vscode-webview": "^1.57.0",
281+
"@typescript-eslint/eslint-plugin": "^6.9.0",
282+
"@typescript-eslint/parser": "^6.9.0",
264283
"@vercel/ncc": "^0.38.1",
265284
"@vitejs/plugin-react": "^1.3.2",
285+
"@vscode/test-electron": "^2.3.9",
286+
"eslint": "^8.52.0",
287+
"glob": "^10.3.10",
288+
"mocha": "^10.4.0",
289+
"nyc": "^15.1.0",
266290
"prettier": "^3.2.5",
267291
"prettier-plugin-tailwindcss": "^0.5.13",
268292
"rimraf": "^3.0.2",

src/commands.ts

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { PontManager } from "pontx-manager";
22
import * as _ from "lodash";
33
import * as vscode from "vscode";
4-
import { findAlicloudAPIConfig, findInterface, getSpecInfoFromName, plugins, showProgress, viewMetaFile, VSCodeLogger, wait } from "./utils";
4+
import {
5+
findAlicloudAPIConfig,
6+
findInterface,
7+
getSpecInfoFromName,
8+
plugins,
9+
showProgress,
10+
viewMetaFile,
11+
VSCodeLogger,
12+
wait,
13+
} from "./utils";
514
import { AlicloudAPIWebview } from "./webview";
615
import { alicloudAPIMessageService } from "./Service";
716
import { PontSpec } from "pontx-spec";
@@ -103,53 +112,53 @@ export class AlicloudApiCommands {
103112

104113
Promise.resolve(service.pontManager.innerManagerConfig.plugins.generate?.instance).then(
105114
async (generatePlugin) => {
106-
const {product, version} = getSpecInfoFromName(specName || "");
115+
const { product, version } = getSpecInfoFromName(specName || "");
107116
const snippets = await codeSampleProvider({
108117
language: vscode.window.activeTextEditor?.document.languageId || "typescript",
109118
product: product,
110119
version: version,
111120
apiName: apiName,
112121
simplify: true,
113122
});
114-
const VIEW_API_DOC_ID = "VSCODE_PONTX_SHOW_PICK_ITEM_VIEW_API_DOC";
115-
let pickItems = [
116-
{
117-
label: "查看文档",
118-
id: VIEW_API_DOC_ID,
119-
},
123+
const VIEW_API_DOC_ID = "VSCODE_PONTX_SHOW_PICK_ITEM_VIEW_API_DOC";
124+
let pickItems = [
125+
{
126+
label: "查看文档",
127+
id: VIEW_API_DOC_ID,
128+
},
129+
];
130+
if (snippets?.length && vscode.window.activeTextEditor) {
131+
pickItems = [
132+
...pickItems,
133+
...snippets.map((snippet) => {
134+
return {
135+
label: "插入代码段: " + snippet.name,
136+
id: snippet.name,
137+
description: snippet.description,
138+
};
139+
}),
120140
];
121-
if (snippets?.length && vscode.window.activeTextEditor) {
122-
pickItems = [
123-
...pickItems,
124-
...snippets.map((snippet) => {
125-
return {
126-
label: "插入代码段: " + snippet.name,
127-
id: snippet.name,
128-
description: snippet.description,
129-
};
130-
}),
131-
];
132-
}
133-
return vscode.window
134-
.showQuickPick(pickItems, {
135-
matchOnDescription: true,
136-
matchOnDetail: true,
137-
})
138-
.then((snippet) => {
139-
const foundSnippet = snippets.find((inst) => inst.name === snippet?.id);
140-
if (foundSnippet) {
141-
insertCode(foundSnippet.code);
142-
} else if (snippet.id === VIEW_API_DOC_ID) {
143-
vscode.commands.executeCommand("alicloud.api.openDocument", {
144-
specName,
145-
modName,
146-
name: apiName,
147-
spec: apiMeta,
148-
pageType: "document",
149-
schemaType: "api",
150-
});
151-
}
152-
});
141+
}
142+
return vscode.window
143+
.showQuickPick(pickItems, {
144+
matchOnDescription: true,
145+
matchOnDetail: true,
146+
})
147+
.then((snippet) => {
148+
const foundSnippet = snippets.find((inst) => inst.name === snippet?.id);
149+
if (foundSnippet) {
150+
insertCode(foundSnippet.code);
151+
} else if (snippet.id === VIEW_API_DOC_ID) {
152+
vscode.commands.executeCommand("alicloud.api.openDocument", {
153+
specName,
154+
modName,
155+
name: apiName,
156+
spec: apiMeta,
157+
pageType: "document",
158+
schemaType: "api",
159+
});
160+
}
161+
});
153162
},
154163
);
155164
});
@@ -251,7 +260,7 @@ export class AlicloudApiCommands {
251260
const lastPromptKey = "lastPromptTime";
252261
const globalState = context.globalState;
253262
globalState.update(lastPromptKey, undefined);
254-
console.log("update last prompt key to",globalState.get(lastPromptKey))
263+
console.log("update last prompt key to", globalState.get(lastPromptKey));
255264
});
256265

257266
vscode.commands.registerCommand("alicloud.api.restart", async () => {
@@ -283,6 +292,7 @@ export class AlicloudApiCommands {
283292
}
284293
},
285294
);
295+
return "ok";
286296
});
287297
vscode.commands.registerCommand("alicloud.api.openPontPanel", async () => {
288298
await vscode.commands.executeCommand("alicloudApiExplorer.focus");

src/test/runTest.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as path from 'path';
2+
3+
import { runTests } from '@vscode/test-electron';
4+
5+
async function main() {
6+
try {
7+
// The folder containing the Extension Manifest package.json
8+
// Passed to `--extensionDevelopmentPath`
9+
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
10+
11+
// The path to test runner
12+
// Passed to --extensionTestsPath
13+
const extensionTestsPath = path.resolve(__dirname, './suite/index');
14+
15+
// Download VS Code, unzip it and run the integration test
16+
await runTests({ extensionDevelopmentPath, extensionTestsPath });
17+
} catch (err) {
18+
console.error('Failed to run tests', err);
19+
process.exit(1);
20+
}
21+
}
22+
23+
main();

src/test/suite/extension.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as assert from "assert";
2+
import { after, before } from "mocha";
3+
4+
// You can import and use all API from the 'vscode' module
5+
// as well as import your extension to test it
6+
import * as vscode from "vscode";
7+
8+
suite("Extension Test Suite", () => {
9+
vscode.window.showInformationMessage("Start all tests.");
10+
before(async () => {
11+
// 确保插件激活
12+
const extension = vscode.extensions.getExtension("alibabacloud-openapi.vscode-alicloud-api");
13+
if (!extension.isActive) {
14+
await extension.activate();
15+
}
16+
console.log("Extension activate.");
17+
});
18+
19+
after(() => {
20+
console.log("All tests done!");
21+
});
22+
23+
test("Test alicloud.api.restart command", async () => {
24+
const result = await vscode.commands.executeCommand("alicloud.api.restart");
25+
console.log("alicloud.api.restart successfully executed");
26+
assert.strictEqual("ok", result);
27+
});
28+
29+
test("Sample test", () => {
30+
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
31+
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
32+
});
33+
});

0 commit comments

Comments
 (0)