Skip to content

Commit

Permalink
test: happy path for downloading Next LS (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg authored Mar 2, 2024
1 parent d5c0c03 commit 27957c7
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 767 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
test:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
os: [macos-14, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand All @@ -33,7 +33,7 @@ jobs:
node-version: 16.x
cache: 'yarn'
- run: yarn install --immutable
- run: xvfb-run -a yarn test
if: runner.os == 'Linux'
- run: yarn test
if: runner.os != 'Linux'
- name: Run headless test
uses: GabrielBB/[email protected]
with:
run: yarn test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
node_modules
.vscode-test/
*.vsix
test-bin
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"tasks": [
{
"type": "npm",
"script": "watch",
"script": "build",
"problemMatcher": "$ts-webpack-watch",
"isBackground": true,
"presentation": {
Expand Down
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,37 +179,41 @@
]
},
"scripts": {
"vscode:prepublish": "yarn run package",
"compile": "webpack",
"watch": "webpack --watch",
"package": "webpack --mode production --devtool hidden-source-map",
"vscode:prepublish": "yarn run build-base --minify",
"package": "vsce package",
"compile-tests": "tsc -p . --outDir out",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "yarn run compile-tests && yarn run compile",
"lint": "eslint src --ext ts",
"fix": "eslint src --ext ts --fix",
"typecheck": "tsc",
"build-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node --target=node16",
"build": "yarn build-base --sourcemap",
"watch": "yarn build-base --sourcemap --watch",
"pretest": "yarn typecheck && yarn run build",
"test": "node ./out/test/runTest.js"
},
"dependencies": {
"vscode-languageclient": "^9.0.0"
},
"devDependencies": {
"@commitlint/config-conventional": "^18.1.0",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.1",
"@types/node": "16.x",
"@types/sinon": "^17.0.3",
"@types/vscode": "^1.77.0",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"@vscode/test-electron": "^2.3.0",
"commitlint": "^18.2.0",
"esbuild": "^0.20.1",
"eslint": "^8.36.0",
"eslint-plugin-prettier": "^4.2.1",
"glob": "^8.1.0",
"mocha": "^10.2.0",
"mocha": "^10.3.0",
"node-fetch": "^3.3.1",
"prettier": "^2.8.8",
"ts-loader": "^9.4.2",
"typescript": "^4.9.5",
"vscode-languageclient": "^8.1.0",
"webpack": "^5.76.3",
"webpack-cli": "^5.0.1"
"sinon": "^17.0.1",
"typescript": "^4.9.5"
}
}
43 changes: 31 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export function deactivate() {
return true;
}

async function ensureNextLSDownloaded(
export async function ensureNextLSDownloaded(
cacheDir: string,
opts: { force?: boolean } = {}
): Promise<string> {
Expand All @@ -232,17 +232,17 @@ async function ensureNextLSDownloaded(
if (shouldDownload) {
await fsp.mkdir(cacheDir, { recursive: true });

const arch = getArch();
const platform = getPlatform();
const url = `https://github.com/elixir-tools/next-ls/releases/latest/download/next_ls_${platform}_${arch}`;
const exe = getExe(platform);
const url = `https://github.com/elixir-tools/next-ls/releases/latest/download/${exe}`;

const shouldInstall = await vscode.window.showInformationMessage(
"Install Next LS?",
{ modal: true, detail: `Downloading to '${cacheDir}'` },
"Yes"
{ title: "Yes" }
);

if (shouldInstall !== "Yes") {
if (shouldInstall?.title !== "Yes") {
throw new Error("Could not activate Next LS");
}

Expand All @@ -263,7 +263,7 @@ async function ensureNextLSDownloaded(
await fsp.chmod(bin, "755");
}

return bin;
return new Promise((resolve) => resolve(bin));
}

async function isBinaryMissing(bin: string) {
Expand All @@ -275,14 +275,33 @@ async function isBinaryMissing(bin: string) {
}
}

function getArch() {
function getExe(platform: string) {
const arch = os.arch();

switch (arch) {
case "x64":
return "amd64";
case "arm64":
return "arm64";
switch (platform) {
case "windows":
switch (arch) {
case "x64":
return "next_ls_windows_amd64.exe";
}
case "darwin":
switch (arch) {
case "x64":
return "next_ls_darwin_amd64";

case "arm64":
return "next_ls_darwin_amd64";
}

case "linux":
switch (arch) {
case "x64":
return "next_ls_linux_amd64";

case "arm64":
return "next_ls_linux_amd64";
}

default:
throw new Error(`Unsupported architecture: ${arch}`);
}
Expand Down
26 changes: 22 additions & 4 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import * as assert from "assert";
import * as fs from "fs";
import * as path from "path";

// 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";
// import * as myExtension from '../../extension';
import * as myExtension from "../../extension.js";
import * as sinon from "sinon";

suite("Extension Test Suite", () => {
vscode.window.showInformationMessage("Start all tests.");

test("Sample test", () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
setup(function () {
fs.rmSync("./test-bin", { recursive: true, force: true });
sinon.stub(vscode.window, "showInformationMessage").returns(
new Promise((resolve) => {
return resolve({ title: "Yes" });
})
);
});

teardown(function () {
sinon.restore();
});

test("downloads Next LS", async function () {
fs.mkdirSync("./test-bin", { recursive: true });

let result = await myExtension.ensureNextLSDownloaded("test-bin");
assert.equal(path.normalize(result), path.normalize("test-bin/nextls"));
});
});
1 change: 0 additions & 1 deletion src/test/suite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as Mocha from "mocha";
import * as glob from "glob";

export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: "tdd",
color: true,
Expand Down
24 changes: 10 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2020",
"lib": [
"ES2020", "DOM"
],
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
}
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"lib": ["ES2020", "DOM"],
"outDir": "out",
"sourceMap": true,
"strict": false
},
"exclude": ["node_modules", ".vscode-test", ]
}

48 changes: 0 additions & 48 deletions webpack.config.js

This file was deleted.

Loading

0 comments on commit 27957c7

Please sign in to comment.