Skip to content

Commit

Permalink
test: Introduce Hermes CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
leotm committed Oct 29, 2024
1 parent 78c0eb6 commit f6cb81b
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 6 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,41 @@ jobs:
- name: Run yarn test262
run: exit 0 # TODO remove test262 from required tests for CI

test-hermes:
name: test-hermes

# begin macro

runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]

steps:
- name: Checkout
uses: actions/checkout@v4

# without this, setup-node errors on mismatched yarn versions
- run: corepack enable

- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: yarn

- name: Install dependencies
run: yarn install --immutable

# end macro

- name: Run yarn build
run: yarn build

- name: Run SES/Hermes smoke test
run: cd packages/ses && yarn test:hermes

viable-release:
name: viable-release

Expand Down
2 changes: 2 additions & 0 deletions packages/ses/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"prepare": "npm run clean && npm run build",
"qt": "ava",
"test": "tsd && ava",
"test:hermes": "./scripts/hermes-test.sh",
"test:xs": "xst dist/ses.umd.js test/_lockdown-safe.js",
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
},
Expand All @@ -101,6 +102,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.29.1",
"hermes-engine-cli": "^0.12.0",
"prettier": "^3.3.3",
"terser": "^5.16.6",
"tsd": "^0.31.2",
Expand Down
55 changes: 55 additions & 0 deletions packages/ses/scripts/hermes-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Creates a JS smoke test to be compiled into Hermes bytecode (hbc).
#
# Usage: scripts/hermes-test.sh

set -ueo pipefail

DIR=$(dirname -- "${BASH_SOURCE[0]}")
cd "$DIR/.."

OS="$(uname -s)"

case "$OS" in
Linux*)
OS_DIR="linux64-bin"
;;
Darwin*)
OS_DIR="osx-bin"
;;
CYGWIN*|MINGW*|MSYS*)
OS_DIR="win64-bin"
;;
*)
echo "Unsupported OS: $OS"
exit 1
;;
esac

HERMESC="../../node_modules/hermes-engine-cli/$OS_DIR/hermesc"
HERMES="../../node_modules/hermes-engine-cli/$OS_DIR/hermes"

echo "Concatenating: dist/ses-hermes.cjs + test/_hermes-smoke.js"
cat dist/ses-hermes.cjs test/_hermes-smoke.js > test/_hermes-smoke-dist.js
echo "Generated: test/_hermes-smoke-dist.js"

# Errors on async arrow functions and async generators
# Both are unsupported on Hermes
echo "Executing: test/_hermes-smoke-dist.js on Hermes compiler"
$HERMESC test/_hermes-smoke-dist.js -emit-binary -out test/_hermes-smoke-dist.hbc
echo "Generated: test/_hermes-smoke-dist.hbc"
echo "Hermes compiler done"

# TODO: Disabled until https://github.com/endojs/endo/issues/1891 complete
# echo "Executing generated bytecode file on Hermes VM"
# $HERMES -b test/_hermes-smoke-dist.hbc
# echo "Hermes VM done"
echo "Skipping: Hermes VM"

echo "Hermes tests complete"

echo "Removing: test/_hermes-smoke-dist.js"
rm test/_hermes-smoke-dist.js
echo "Removing: test/_hermes-smoke-dist.hbc"
rm test/_hermes-smoke-dist.hbc
49 changes: 49 additions & 0 deletions packages/ses/test/_hermes-smoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Hermes doesn't support native I/O,
// so we concat the SES shim above,
// when running this test on Hermes.

/**
* Test calling SES lockdown.
*/
const testLockdown = () => {
lockdown();
};

/**
* TODO: Test creating a new Compartment.
*/
// eslint-disable-next-line no-unused-vars
const testCompartment = () => {
// eslint-disable-next-line no-unused-vars
const c = new Compartment();
};

/**
* TODO: Test Compartment import hook and resolve hook.
*/
// eslint-disable-next-line no-unused-vars
async function testCompartmentHooks() {
const resolveHook = a => a;

async function importHook() {
return {
imports: [],
exports: ['meaning'],
execute(exports) {
exports.meaning = 42;
},
};
}

const compartment = new Compartment({}, {}, { resolveHook, importHook });

const module = compartment.module('.');

const {
namespace: { _meaning },
} = await compartment.import('.');

assert(module);
}

testLockdown();
Loading

0 comments on commit f6cb81b

Please sign in to comment.