Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add package scripts and cli library, enable integration testing#536

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jaggederest wants to merge9 commits intomain
base:main
Choose a base branch
Loading
fromjaggederest/integration_tests
Open
Show file tree
Hide file tree
Changes fromall 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
1 change: 1 addition & 0 deletions.eslintignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
vitest.config.ts
4 changes: 2 additions & 2 deletions.github/workflows/ci.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ jobs:

-uses:actions/setup-node@v4
with:
node-version:"18"
node-version:"22"

-run:yarn

Expand All@@ -36,7 +36,7 @@ jobs:

-uses:actions/setup-node@v4
with:
node-version:"18"
node-version:"22"

-run:yarn

Expand Down
2 changes: 1 addition & 1 deletion.github/workflows/release.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ jobs:

-uses:actions/setup-node@v4
with:
node-version:"18"
node-version:"22"

-run:yarn

Expand Down
12 changes: 12 additions & 0 deletions.vscode-test.mjs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import{defineConfig}from"@vscode/test-cli";

exportdefaultdefineConfig({
files:"out/test/**/*.test.js",
extensionDevelopmentPath:".",
extensionTestsPath:"./out/test",
launchArgs:["--enable-proposed-api","coder.coder-remote"],
mocha:{
ui:"tdd",
timeout:20000,
},
});
2 changes: 1 addition & 1 deletion.vscodeignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,4 +12,4 @@ node_modules/**
**/.editorconfig
**/*.map
**/*.ts
*.gif
*.gif
12 changes: 8 additions & 4 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,8 +278,11 @@
"package:prerelease":"npx vsce package --pre-release",
"lint":"eslint . --ext ts,md",
"lint:fix":"yarn lint --fix",
"test":"vitest ./src",
"test:ci":"CI=true yarn test"
"test":"vitest",
"test:ci":"CI=true yarn test",
"test:integration":"vscode-test",
"pretest":"yarn run compile-tests && yarn run build && yarn run lint",
"compile-tests":"tsc -p . --outDir out"
},
"devDependencies": {
"@types/eventsource":"^3.0.0",
Expand DownExpand Up@@ -311,7 +314,8 @@
"vitest":"^0.34.6",
"vscode-test":"^1.5.0",
"webpack":"^5.99.6",
"webpack-cli":"^5.1.4"
"webpack-cli":"^5.1.4",
"@vscode/test-cli":"^0.0.10"
},
"dependencies": {
"axios":"1.8.4",
Expand All@@ -326,7 +330,7 @@
"semver":"^7.7.1",
"ua-parser-js":"1.0.40",
"ws":"^8.18.2",
"zod":"^3.25.1"
"zod":"^3.25.65"
},
"resolutions": {
"semver":"7.7.1",
Expand Down
35 changes: 23 additions & 12 deletionssrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,25 +21,36 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
//
// Cursor and VSCode are covered by ms remote, and the only other is windsurf for now
// Means that vscodium is not supported by this for now
constisTestMode=
process.env.NODE_ENV==="test"||
ctx.extensionMode===vscode.ExtensionMode.Test;

constremoteSSHExtension=
vscode.extensions.getExtension("jeanp413.open-remote-ssh")||
vscode.extensions.getExtension("codeium.windsurf-remote-openssh")||
vscode.extensions.getExtension("anysphere.remote-ssh")||
vscode.extensions.getExtension("ms-vscode-remote.remote-ssh");

letvscodeProposed:typeofvscode=vscode;

if(!remoteSSHExtension){
vscode.window.showErrorMessage(
"Remote SSH extension not found, cannot activate Coder extension",
if(!isTestMode){
vscode.window.showErrorMessage(
"Remote SSH extension not found, cannot activate Coder extension",
);
thrownewError("Remote SSH extension not found");
}
// In test mode, use regular vscode API
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice! I wonder if we can avoid the special testing behavior. Maybe we should always try to activate, but if we are unable to get this special API we skip the remote registration (and possibly log a warning)? Similar to what you already have except we always do it, not just in testing.

That would make it nicer for use cases where you have not installed the remote extension yet, for whatever reason, while reducing drift between production and testing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah I suspect this is the kind of behavior we want, so 👍 to logging a warning and handling it gracefully

code-asher reacted with thumbs up emoji
}else{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
vscodeProposed=(moduleasany)._load(
"vscode",
{
filename:remoteSSHExtension.extensionPath,
},
false,
);
thrownewError("Remote SSH extension not found");
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constvscodeProposed:typeofvscode=(moduleasany)._load(
"vscode",
{
filename:remoteSSHExtension?.extensionPath,
},
false,
);

constoutput=vscode.window.createOutputChannel("Coder");
conststorage=newStorage(
Expand DownExpand Up@@ -278,7 +289,7 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
// Since the "onResolveRemoteAuthority:ssh-remote" activation event exists
// in package.json we're able to perform actions before the authority is
// resolved by the remote SSH extension.
if(vscodeProposed.env.remoteAuthority){
if(!isTestMode&&vscodeProposed.env.remoteAuthority){
constremote=newRemote(
vscodeProposed,
storage,
Expand Down
14 changes: 10 additions & 4 deletionssrc/remote.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,9 @@ import * as fs from "fs/promises";
import * as jsonc from "jsonc-parser";
import * as os from "os";
import * as path from "path";
import prettyBytes from "pretty-bytes";
// Dynamic import for ESM module
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let prettyBytes: any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know you said this was temporary, just leaving a note here to acknowledge we need to update this and other references before merge. 😄

jaggederest reacted with heart emoji
import * as semver from "semver";
import * as vscode from "vscode";
import {
Expand DownExpand Up@@ -841,7 +843,7 @@ export class Remote {
`${sshPid}.json`,
);

const updateStatus = (network: {
const updateStatus =async(network: {
p2p: boolean;
latency: number;
preferred_derp: string;
Expand All@@ -850,6 +852,10 @@ export class Remote {
download_bytes_sec: number;
using_coder_connect: boolean;
}) => {
// Load ESM module if not already loaded
if (!prettyBytes) {
prettyBytes = (await import("pretty-bytes")).default;
}
let statusText = "$(globe) ";

// Coder Connect doesn't populate any other stats
Expand DownExpand Up@@ -910,9 +916,9 @@ export class Remote {
.then((content) => {
return JSON.parse(content);
})
.then((parsed) => {
.then(async(parsed) => {
try {
updateStatus(parsed);
awaitupdateStatus(parsed);
} catch (ex) {
// Ignore
}
Expand Down
8 changes: 7 additions & 1 deletionsrc/storage.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,9 @@ import { createWriteStream } from "fs";
importfsfrom"fs/promises";
import{IncomingMessage}from"http";
importpathfrom"path";
importprettyBytesfrom"pretty-bytes";
// Dynamic import for ESM module
// eslint-disable-next-line @typescript-eslint/no-explicit-any
letprettyBytes:any;
import*asvscodefrom"vscode";
import{errToStr}from"./api-helper";
import*asclifrom"./cliManager";
Expand DownExpand Up@@ -122,6 +124,10 @@ export class Storage {
* downloads being disabled.
*/
publicasyncfetchBinary(restClient:Api,label:string):Promise<string>{
// Load ESM module if not already loaded
if(!prettyBytes){
prettyBytes=(awaitimport("pretty-bytes")).default;
}
constbaseUrl=restClient.getAxiosInstance().defaults.baseURL;

// Settings can be undefined when set to their defaults (true in this case),
Expand Down
56 changes: 56 additions & 0 deletionssrc/test/extension.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
import*asassertfrom"assert";
import*asvscodefrom"vscode";

suite("Extension Test Suite",()=>{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Exciting to have this working!!

Kira-Pilot reacted with hooray emoji
vscode.window.showInformationMessage("Start all tests.");

test("Extension should be present",()=>{
assert.ok(vscode.extensions.getExtension("coder.coder-remote"));
});

test("Extension should activate",async()=>{
constextension=vscode.extensions.getExtension("coder.coder-remote");
assert.ok(extension);

if(!extension.isActive){
awaitextension.activate();
}

assert.ok(extension.isActive);
});

test("Extension should export activate function",async()=>{
constextension=vscode.extensions.getExtension("coder.coder-remote");
assert.ok(extension);

awaitextension.activate();
// The extension doesn't export anything, which is fine
// The test was expecting exports.activate but the extension
// itself is the activate function
assert.ok(extension.isActive);
});

test("Commands should be registered",async()=>{
constextension=vscode.extensions.getExtension("coder.coder-remote");
assert.ok(extension);

if(!extension.isActive){
awaitextension.activate();
}

// Give a small delay for commands to register
awaitnewPromise((resolve)=>setTimeout(resolve,100));

constcommands=awaitvscode.commands.getCommands(true);
constcoderCommands=commands.filter((cmd)=>cmd.startsWith("coder."));

assert.ok(
coderCommands.length>0,
"Should have registered Coder commands",
);
assert.ok(
coderCommands.includes("coder.login"),
"Should have coder.login command",
);
});
});
11 changes: 5 additions & 6 deletionstsconfig.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
{
"compilerOptions": {
"module":"commonjs",
"target":"es6",
"module":"Node16",
"target":"ES2022",
"outDir":"out",
// "dom" is required for importing the API from coder/coder.
"lib": ["es6","dom"],
"lib": ["ES2022","dom"],
"sourceMap":true,
"rootDirs": ["node_modules","src"],
"strict":true,
"esModuleInterop":true
"skipLibCheck":true
},
"exclude": ["node_modules",".vscode-test"]
"exclude": ["vitest.config.ts"]
}
17 changes: 17 additions & 0 deletionsvitest.config.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
import{defineConfig}from"vitest/config";

exportdefaultdefineConfig({
test:{
include:["src/**/*.test.ts"],
exclude:[
"**/node_modules/**",
"**/dist/**",
"**/build/**",
"**/out/**",
"**/src/test/**",
"src/test/**",
"./src/test/**",
],
environment:"node",
},
});
Loading

[8]ページ先頭

©2009-2025 Movatter.jp