Skip to content

Commit

Permalink
Scarb from correct source test
Browse files Browse the repository at this point in the history
commit-id:28a8da67
  • Loading branch information
Draggu committed Jan 9, 2025
1 parent 3c486c2 commit 2c33e8c
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 29 deletions.
47 changes: 44 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,45 @@ jobs:
- run: npm ci
- run: npm run compile-test
- run: npm test
ui-test-scarb:
name: check scarb from different sources
strategy:
matrix:
from-config: [true, false]
from-path: [true, false]
from-asdf-local: [true, false]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22.x"
cache: npm
# Scarb in PATH
- run: |
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v "2.9.1"
echo "PATH_SCARB_VERSION=2.9.1" >> $GITHUB_ENV
if: ${{ matrix.from-path }}
# Scarb in config on ~/.local/bin/scarb
- run: |
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -p -v "2.8.5"
echo "CONFIG_SCARB_VERSION=2.8.5" >> $GITHUB_ENV
if: ${{ matrix.from-config }}
# Scarb from asdf
- uses: asdf-vm/actions/setup@v3
if: ${{ matrix.from-asdf-local }}
- run: |
asdf plugin add scarb
asdf install scarb "2.9.2"
asdf local scarb "2.9.2"
echo "ASDF_SCARB_VERSION=2.9.2" >> $GITHUB_ENV
if: ${{ matrix.from-asdf-local }}
- run: npm ci
- run: npm run compile-test
- run: xvfb-run --auto-servernum --server-args='-screen 0 1920x1080x24' npm run ui-test-scarb
test-ui-parametrized:
name: test ui
strategy:
Expand All @@ -63,10 +102,12 @@ jobs:
if: ${{ matrix.os != 'ubuntu-latest'}}
test-ui:
if: ${{ always() }}
needs: test-ui-parametrized
needs:
- test-ui-parametrized
- ui-test-scarb
runs-on: ubuntu-latest
steps:
- if: needs.test-ui-parametrized.result == 'success'
- if: needs.test-ui-parametrized.result == 'success' && needs.ui-test-scarb.result == 'success'
run: exit 0
- if: needs.test-ui-parametrized.result != 'success'
- if: needs.test-ui-parametrized.result != 'success' || needs.ui-test-scarb.result != 'success'
run: exit 1
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
"lint-eslint": "eslint .",
"lint-fmt": "prettier --check .",
"test": "node --test out/test/**/*.js",
"ui-test": "extest setup-and-run './out/ui-test/*.js' --code_version max --code_settings ui-test/settings.json --extensions_dir .test-extensions"
"ui-test-scarb": "extest setup-and-run './out/ui-test/scarb/*.js' --code_version max --code_settings ui-test/settings.json --extensions_dir .test-extensions",
"ui-test": "extest setup-and-run './out/ui-test/generic/*.js' --code_version max --code_settings ui-test/settings.json --extensions_dir .test-extensions"
},
"engines": {
"vscode": "^1.84.0"
Expand Down
22 changes: 22 additions & 0 deletions test-support/page-objects/cairoStatusBarItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { StatusBar, WebElement } from "vscode-extension-tester";

export async function getStatusBarItem(): Promise<WebElement | undefined> {
const items = await new StatusBar().getItems();

for (const item of items) {
try {
// This can throw StaleElementReferenceError because item was destroyed before reading its text.
const text = await item.getText();

if (text.startsWith("Cairo")) {
return item;
}
} catch {
// No need to do anything here.
// If this was cairo status bar we will simply return after loop.
// Else it is not interesting for us anyway.
}
}

return undefined;
}
2 changes: 1 addition & 1 deletion ui-test/expandMacro.ts → ui-test/generic/expandMacro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EditorView, TextEditor, VSBrowser, Workbench } from "vscode-extension-tester";
import { expect } from "chai";
import { isScarbAvailable } from "../test-support/scarb";
import { isScarbAvailable } from "../../test-support/scarb";
import * as path from "path";

describe("Expand macro test", function () {
Expand Down
28 changes: 4 additions & 24 deletions ui-test/statusBar.ts → ui-test/generic/statusBar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { StatusBar, VSBrowser, WebElement, Workbench } from "vscode-extension-tester";
import { StatusBar, VSBrowser, Workbench } from "vscode-extension-tester";
import { expect } from "chai";
import { isScarbAvailable } from "../test-support/scarb";
import { isScarbAvailable } from "../../test-support/scarb";
import * as path from "path";
import { getStatusBarItem } from "../../test-support/page-objects/cairoStatusBarItem";

describe("Status bar", function () {
this.timeout(50000);
Expand All @@ -26,7 +27,7 @@ describe("Status bar", function () {

if (isScarbAvailable) {
expect(title).to.match(
/Cairo, (Cairo Language Server .+ \(.+\)\n)?Cairo Language\nscarb .+ \(.+\)\ncairo: .+ \(.+\)\nsierra: .+/,
/Cairo, (?:Cairo Language Server .+ \(.+\)\n)?Cairo Language\nscarb .+ \(.+\)\ncairo: .+ \(.+\)\nsierra: .+/,
);
} else {
expect(title).to.be.eq("Cairo, Cairo Language");
Expand All @@ -48,24 +49,3 @@ describe("Status bar", function () {
expect(statusBarIsUndefined).to.be.true;
});
});

async function getStatusBarItem(): Promise<WebElement | undefined> {
const items = await new StatusBar().getItems();

for (const item of items) {
try {
// This can throw StaleElementReferenceError because item was destroyed before reading its text.
const text = await item.getText();

if (text.startsWith("Cairo")) {
return item;
}
} catch {
// No need to do anything here.
// If this was cairo status bar we will simply return after loop.
// Else it is not interesting for us anyway.
}
}

return undefined;
}
72 changes: 72 additions & 0 deletions ui-test/scarb/toolchain_info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { StatusBar, VSBrowser, Workbench } from "vscode-extension-tester";
import { expect } from "chai";
import * as path from "path";
import { getStatusBarItem } from "../../test-support/page-objects/cairoStatusBarItem";
import { homedir } from "os";

describe("Toolchain info", function () {
this.timeout(50000);

it("Checks correct scarb precedence", async function () {
// asdf is in fact in PATH and in our tests it is first scarb in path, special case this.
// It is caused by `@actions/core addPath` implementation.
// See: https://github.com/actions/toolkit/blob/01f21badd5a7522507f84558503b56c4deec5326/packages/core/src/core.ts#L107
if (process.env.PATH_SCARB_VERSION && process.env.ASDF_SCARB_VERSION) {
process.env.PATH_SCARB_VERSION = process.env.ASDF_SCARB_VERSION;
}

const scarbs = [
// Order is important here.
process.env.CONFIG_SCARB_VERSION,
process.env.PATH_SCARB_VERSION,
process.env.ASDF_SCARB_VERSION,
];

const expectedScarbVersion = scarbs.find(Boolean); // Find first with value.

// Ignore this test locally, it is strictly designed for our CI.
if (!expectedScarbVersion) {
this.skip();
}

if (process.env.CONFIG_SCARB_VERSION) {
const workbench = new Workbench();

const settings = await workbench.openSettings();

const setting = await settings.findSetting("Scarb Path", "Cairo1");

setting.setValue(path.join(homedir(), ".local", "bin", "scarb"));
}

await VSBrowser.instance.openResources(path.join("ui-test", "fixtures", "empty"));

const statusBar = await VSBrowser.instance.driver.wait(getStatusBarItem, 5000);

expect(statusBar).to.not.be.undefined;

const title = await statusBar!.getAttribute(StatusBar["locators"].StatusBar.itemTitle);

const matches =
/Cairo, (?:Cairo Language Server .+ \(.+\)\n)?Cairo Language\nscarb (.+) \(.+\)\ncairo: .+ \(.+\)\nsierra: .+/.exec(
title,
);

expect(matches).to.not.be.undefined;

const scarbVersion = matches![1];

expect(scarbVersion).to.be.eq(expectedScarbVersion);
});
});

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace NodeJS {
interface ProcessEnv {
ASDF_SCARB_VERSION?: string;
CONFIG_SCARB_VERSION?: string;
PATH_SCARB_VERSION?: string;
}
}
}

0 comments on commit 2c33e8c

Please sign in to comment.