Skip to content

Commit

Permalink
VS Code extension tests (#625)
Browse files Browse the repository at this point in the history
Integration tests for the VS Code extension.
  • Loading branch information
minestarks authored Oct 5, 2023
1 parent c2e1be1 commit 3bb38b7
Show file tree
Hide file tree
Showing 18 changed files with 2,120 additions and 29 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
"/jupyterlab/lib",
"/jupyterlab/qsharp-jupyterlab/labextension",
"/vscode/out/",
"/vscode/test/out/",
],
env: {
browser: true,
Expand Down
43 changes: 39 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ concurrency:

env:
CARGO_TERM_COLOR: always
NODE_VERSION: "18.17.1"
PYTHON_VERSION: "3.11"
RUST_TOOLCHAIN_VERSION: "1.72"
RUST_TOOLCHAIN_COMPONENTS: rustfmt clippy

Expand Down Expand Up @@ -77,14 +79,14 @@ jobs:
submodules: "true"
- uses: actions/setup-node@v3
with:
node-version: '18.17.1'
node-version: ${{ env.NODE_VERSION }}
- name: npm install
run: npm install
- name: npm check
run: npm run check

build:
name: CI Build and Test
name: Build and test
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
Expand All @@ -106,12 +108,45 @@ jobs:
if: matrix.os == 'macos-latest'
- uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: ${{ env.PYTHON_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: '18.17.1'
node-version: ${{ env.NODE_VERSION }}
- uses: Swatinem/rust-cache@v2
- name: Prereqs
run: python ./prereqs.py --install
- name: Build and Test
run: python ./build.py --no-check

integration-tests:
name: Integration tests
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]

runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v3
with:
submodules: "true"
- name: Setup rust toolchain
uses: ./.github/actions/toolchains/rust
with:
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
components: ${{ env.RUST_TOOLCHAIN_COMPONENTS }}
- name: Add additional Rust targets
run: |
rustup target add aarch64-apple-darwin
if: matrix.os == 'macos-latest'
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- uses: Swatinem/rust-cache@v2
- name: Prereqs
run: python ./prereqs.py --install
- name: Run integration tests
run: python ./build.py --no-check --no-test --wasm --npm --vscode --integration-tests
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ __pycache__/
/samples/
/target/
/vscode/out/
/vscode/test/out/
/wasm/
69 changes: 52 additions & 17 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import platform
import sys
import time
import venv
import shutil
import subprocess
Expand Down Expand Up @@ -60,6 +61,13 @@
help="Run the prerequisites check (default is --check-prereqs)",
)

parser.add_argument(
"--integration-tests",
action=argparse.BooleanOptionalAction,
default=False,
help="Build and run the integration tests (default is --no-integration-tests)",
)

args = parser.parse_args()

if args.check_prereqs:
Expand Down Expand Up @@ -95,9 +103,6 @@
build_type = "debug" if args.debug else "release"
run_tests = args.test

# TODO: This requires that both targets are installed on macOS to build Python packages. Add to prereqs checks.
pip_archflags = "-arch x86_64 -arch arm64" if platform.system() == "Darwin" else None

root_dir = os.path.dirname(os.path.abspath(__file__))
wasm_src = os.path.join(root_dir, "wasm")
wasm_bld = os.path.join(root_dir, "target", "wasm32", build_type)
Expand All @@ -109,11 +114,26 @@
vscode_src = os.path.join(root_dir, "vscode")
jupyterlab_src = os.path.join(root_dir, "jupyterlab")


def step_start(description):
global start_time
print(f"build.py step: {description}")
start_time = time.time()


def step_end():
global start_time
duration = time.time() - start_time
print(f"build.py step: Finished in {duration:.3f}s.")


if npm_install_needed:
step_start("Running npm install")
subprocess.run([npm_cmd, "install"], check=True, text=True, cwd=root_dir)
step_end()

if args.check:
print("Running eslint and prettier checks")
step_start("Running eslint and prettier checks")
subprocess.run([npm_cmd, "run", "check"], check=True, text=True, cwd=root_dir)

if build_wasm or build_cli:
Expand All @@ -139,9 +159,10 @@
text=True,
cwd=root_dir,
)
step_end()

if build_cli:
print("Building the command line compiler")
step_start("Building the command line compiler")
cargo_build_args = ["cargo", "build"]
if build_type == "release":
cargo_build_args.append("--release")
Expand All @@ -153,9 +174,10 @@
if build_type == "release":
cargo_test_args.append("--release")
subprocess.run(cargo_test_args, check=True, text=True, cwd=root_dir)
step_end()

if build_pip:
print("Building the pip package")
step_start("Building the pip package")
# Check if in a virtual environment
if (
os.environ.get("VIRTUAL_ENV") is None
Expand All @@ -181,9 +203,9 @@

# copy the process env vars
pip_env: dict[str, str] = os.environ.copy()
if pip_archflags is not None:
if platform.system() == "Darwin":
# if on mac, add the arch flags for universal binary
pip_env["ARCHFLAGS"] = pip_archflags
pip_env["ARCHFLAGS"] = "-arch x86_64 -arch arm64"

pip_build_args = [
python_bin,
Expand Down Expand Up @@ -247,9 +269,10 @@
subprocess.run(pytest_args, check=True, text=True, cwd=qir_test_dir)
else:
print("Could not import PyQIR, skipping tests")
step_end()

if build_wasm:
print("Building the wasm crate")
step_start("Building the wasm crate")
# wasm-pack can't build for web and node in the same build, so need to run twice.
# Hopefully not needed if https://github.com/rustwasm/wasm-pack/issues/313 lands.
build_flag = "--release" if build_type == "release" else "--dev"
Expand All @@ -266,23 +289,25 @@
subprocess.run(
wasm_pack_args + node_build_args, check=True, text=True, cwd=wasm_src
)
step_end()

if build_samples:
print("Building qsharp samples")
step_start("Building qsharp samples")
files = [
os.path.join(dp, f)
for dp, _, filenames in os.walk(samples_src)
for f in filenames
if os.path.splitext(f)[1] == ".qs"
]
args = ["cargo", "run", "--bin", "qsc"]
cargo_args = ["cargo", "run", "--bin", "qsc"]
if build_type == "release":
args.append("--release")
cargo_args.append("--release")
for file in files:
subprocess.run((args + ["--", file]), check=True, text=True, cwd=root_dir)
subprocess.run((cargo_args + ["--", file]), check=True, text=True, cwd=root_dir)
step_end()

if build_npm:
print("Building the npm package")
step_start("Building the npm package")
# Copy the wasm build files over for web and node targets
for target in ["web", "node"]:
lib_dir = os.path.join(npm_src, "lib", target)
Expand All @@ -307,19 +332,22 @@
print("Running tests for the npm package")
npm_test_args = ["node", "--test"]
subprocess.run(npm_test_args, check=True, text=True, cwd=npm_src)
step_end()

if build_play:
print("Building the playground")
step_start("Building the playground")
play_args = [npm_cmd, "run", "build"]
subprocess.run(play_args, check=True, text=True, cwd=play_src)
step_end()

if build_vscode:
print("Building the VS Code extension")
step_start("Building the VS Code extension")
vscode_args = [npm_cmd, "run", "build"]
subprocess.run(vscode_args, check=True, text=True, cwd=vscode_src)
step_end()

if build_jupyterlab:
print("Building the JupyterLab extension")
step_start("Building the JupyterLab extension")

# Check if in a virtual environment
if (
Expand Down Expand Up @@ -354,3 +382,10 @@
jupyterlab_src,
]
subprocess.run(pip_build_args, check=True, text=True, cwd=jupyterlab_src)
step_end()

if args.integration_tests:
step_start("Running the VS Code integration tests")
vscode_args = [npm_cmd, "test"]
subprocess.run(vscode_args, check=True, text=True, cwd=vscode_src)
step_end()
Loading

0 comments on commit 3bb38b7

Please sign in to comment.