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 Sep 30, 2024
1 parent 580fd53 commit 13aa1af
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,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.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.2.5",
"sinon": "^15.1.0",
"terser": "^5.16.6",
Expand Down
47 changes: 47 additions & 0 deletions packages/ses/scripts/hermes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

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

# Paths relative to 'packages/ses'
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
53 changes: 53 additions & 0 deletions packages/ses/test/hermes-smoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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();

// testCompartment();

// testCompartmentHooks();
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5626,6 +5626,13 @@ __metadata:
languageName: node
linkType: hard

"hermes-engine-cli@npm:^0.12.0":
version: 0.12.0
resolution: "hermes-engine-cli@npm:0.12.0"
checksum: 10c0/53a00336632cc7a743e9a88a5199865cf922d118f42f15bed4d2ed2fee635acd0d4d8563803b47e7c1bc2d17650281eb9188be8cfdaa25887243cfee840523be
languageName: node
linkType: hard

"hosted-git-info@npm:^2.1.4":
version: 2.8.9
resolution: "hosted-git-info@npm:2.8.9"
Expand Down Expand Up @@ -9227,6 +9234,7 @@ __metadata:
eslint-config-prettier: "npm:^9.1.0"
eslint-plugin-eslint-comments: "npm:^3.2.0"
eslint-plugin-import: "npm:^2.29.1"
hermes-engine-cli: "npm:^0.12.0"
prettier: "npm:^3.2.5"
sinon: "npm:^15.1.0"
terser: "npm:^5.16.6"
Expand Down

0 comments on commit 13aa1af

Please sign in to comment.