fix: make sure the tests run in ci

#89
This commit is contained in:
Hendrik Eeckhaut
2025-01-22 17:37:13 +01:00
committed by GitHub
parent 2b783618d2
commit 14eee4a2e3
6 changed files with 5705 additions and 6111 deletions

View File

@@ -4,7 +4,6 @@ on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
LOCAL-NOTARY: true

1703
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -15,7 +15,7 @@
"serve:test": "serve --config ../serve.json ./test-build -l 3001",
"build:src": "webpack --config webpack.build.config.js",
"build:types": "tsc --project tsconfig.compile.json",
"build:tlsn-binaries": "sh utils/build-tlsn-binaries.sh",
"build:tlsn-binaries": "sh utils/build-tlsn-binaries.sh v0.1.0-alpha.7",
"build:lib": "NODE_ENV=production concurrently npm:build:src npm:build:types",
"build": "npm run build:lib",
"watch:dev": "webpack --config webpack.web.dev.config.js --watch",
@@ -28,7 +28,6 @@
"test:only": "npm run build:test && npm run run:test"
},
"devDependencies": {
"@types/expect": "^24.3.0",
"@types/mocha": "^10.0.6",
"@types/serve-handler": "^6.1.4",
"browserify": "^17.0.0",
@@ -50,7 +49,7 @@
"node-loader": "^0.6.0",
"prettier": "^3.0.2",
"process": "^0.11.10",
"puppeteer": "^23.5.0",
"puppeteer": "^24.1.0",
"serve": "14.2.1",
"serve-handler": "^6.1.5",
"stream-browserify": "^3.0.0",
@@ -72,4 +71,4 @@
"dependencies": {
"tlsn-wasm": "^0.1.0-alpha.7.2"
}
}
}

10039
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
import puppeteer, { Browser, Page, PuppeteerLaunchOptions } from 'puppeteer';
import puppeteer, { Browser, LaunchOptions, Page } from 'puppeteer';
import { describe, it, before, after } from 'mocha';
const assert = require('assert');
import { exec, ChildProcess } from 'node:child_process';
@@ -9,10 +9,11 @@ const yaml = require('js-yaml');
const timeout = 300000;
// puppeteer options
let opts: PuppeteerLaunchOptions = {
let opts: LaunchOptions = {
headless: !!process.env.HEADLESS ? true : false,
slowMo: 100,
timeout: timeout,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
};
if (process.env.CHROME_PATH) {
@@ -29,10 +30,15 @@ let server: ChildProcess;
let tlsnServerFixture: ChildProcess;
const spawnTlsnServerFixture = () => {
const tlsnServerFixturePath = './utils/tlsn/crates/server-fixture/';
tlsnServerFixture = exec(`../../target/release/main`, {
tlsnServerFixture = exec(`../../target/release/tlsn-server-fixture`, {
cwd: tlsnServerFixturePath,
});
tlsnServerFixture.on('error', (error) => {
console.error(`Failed to start TLSN Server Fixture: ${error}`);
process.exit(1);
});
tlsnServerFixture.stdout?.on('data', (data) => {
console.log(`Server: ${data}`);
});
@@ -49,6 +55,10 @@ const spawnLocalNotaryServer = async () => {
localNotaryServer = exec(`../../../target/release/notary-server`, {
cwd: localNotaryServerPath,
});
localNotaryServer.on('error', (error) => {
console.error(`Failed to start Notary server: ${error}`);
process.exit(1);
});
localNotaryServer.stdout?.on('data', (data) => {
console.log(`Server: ${data}`);
});
@@ -71,7 +81,7 @@ const spawnLocalNotaryServer = async () => {
}
};
const configureNotarySerer = () => {
const configureNotaryServer = () => {
try {
const configPath = './utils/tlsn/crates/notary/server/config/config.yaml';
const fileContents = fs.readFileSync(configPath, 'utf8');
@@ -91,7 +101,7 @@ before(async function () {
server = exec('serve --config ../serve.json ./test-build -l 3001');
spawnTlsnServerFixture();
configureNotarySerer();
configureNotaryServer(); //TODO: After alpha.8: remove this and add as argument to notary server
await spawnLocalNotaryServer();
browser = await puppeteer.launch(opts);
page = await browser.newPage();
@@ -112,17 +122,25 @@ after(async function () {
server.kill();
console.log('* Stopped Test Web Server ✅');
await page.close();
await browser.close();
const childProcess = browser.process();
if (childProcess) {
childProcess.kill(9);
if (page) {
await page.close();
}
console.log('* Closed browser ✅');
process.exit(0);
if (browser) {
await browser.close();
const childProcess = browser.process();
if (childProcess) {
childProcess.kill(9);
}
console.log('* Closed browser ✅');
const tests = this.test?.parent?.suites.flatMap((suite) => suite.tests);
const failed = tests!.some((test) => test.state === 'failed');
process.exit(failed ? 1 : 0);
}
process.exit(1);
} catch (e) {
console.error(e);
process.exit(0);
process.exit(1);
}
});
@@ -131,18 +149,13 @@ describe('tlsn-js test suite', function () {
const [id] = file.split('.');
it(`Test ID: ${id}`, async function () {
const content = await check(id);
assert(content === 'OK');
assert.strictEqual(
content,
'OK',
`Test ID: ${id} - Expected 'OK' but got '${content}'`,
);
});
});
// it('should prove and verify data from the local tlsn-server-fixture', async function () {
// const content = await check('full-integration-swapi');
// assert(content === 'OK');
// });
//
// it('should verify', async function () {
// const content = await check('simple-verify');
// assert(content === 'OK');
// });
});
async function check(testId: string): Promise<string> {

View File

@@ -1,9 +1,13 @@
#!/bin/bash
# Run tlsn Server fixture
set -e # Exit on error
# Set the directory to the location of the script
cd "$(dirname "$0")"
VERSION=${1:-origin/dev} # use `dev` branch if no version is set
# Name of the directory where the repo will be cloned
REPO_DIR="tlsn"
@@ -20,7 +24,8 @@ else
fi
# Checkout the specific tag
git checkout "dev"
git checkout "${VERSION}" --force
git reset --hard
for dir in "crates/server-fixture/" "crates/notary/server"; do
# Change to the specific subdirectory