Skip to content

Commit 0f7d433

Browse files
committed
feat(e2e): add Jest configuration and CLI wrapper for e2e
1 parent 69bd374 commit 0f7d433

File tree

6 files changed

+162
-70
lines changed

6 files changed

+162
-70
lines changed

packages/e2e/README.md

Lines changed: 60 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,96 @@
1-
# @litprotocol/e2e
1+
# @lit-protocol/e2e
22

3-
A comprehensive end-to-end testing package for Lit Protocol integrations. This package allows you to programmatically run the full suite of Lit Protocol tests across different authentication methods and network configurations.
3+
Utilities and ready-made specs for Lit Protocol end-to-end testing. This package now ships the canonical Jest suite we run in-repo, plus helpers (state initialisers, Shiva client, etc.) so QA teams can execute the same coverage or layer on additional `.spec.ts` files without cloning this repository.
44

55
## Installation
66

77
```bash
8-
pnpm add @litprotocol/e2e
8+
pnpm add -D jest @lit-protocol/e2e @lit-protocol/lit-client @lit-protocol/networks viem
99
```
1010

11-
## Environment Variables
11+
> The package depends on `jest` being available in the consumer workspace. Install any additional peer dependencies (for example `ts-node` if you prefer to author specs in TypeScript directly).
1212
13-
**Required** - Set these environment variables before running tests:
13+
## Required Environment
14+
15+
Set the same environment variables the in-repo test harness expects **before** running any specs:
1416

1517
```bash
16-
# For live networks (naga-dev, naga-staging)
18+
# Accounts that sponsor users on live and local networks
1719
LIVE_MASTER_ACCOUNT=0x...
18-
19-
# For local network (naga-local)
2020
LOCAL_MASTER_ACCOUNT=0x...
2121

22-
# Optional - can also be passed as parameters
23-
NETWORK=naga-dev
22+
# General configuration (can also be passed to init())
23+
NETWORK=naga-local # or naga-dev / naga-staging / naga-test
2424
LOG_LEVEL=info
25+
26+
# Optional local overrides
27+
NAGA_LOCAL_CONTEXT_PATH=./lit-assets/blockchain/contracts/networkContext.json
28+
NAGA_LOCAL_CONTEXT_NAME=naga-develop
29+
LIT_YELLOWSTONE_PRIVATE_RPC_URL=http://127.0.0.1:8545
2530
```
2631

27-
## Quick Start
32+
Make sure the referenced network (local Naga cluster, Shiva-managed testnet, or live subnet) is running and reachable from your test machine.
2833

29-
```typescript
30-
import { runLitE2eTests } from '@litprotocol/e2e';
34+
## Run the Bundled Suite
3135

32-
// Run all tests on naga-dev network
33-
const results = await runLitE2eTests({
34-
network: 'naga-dev',
35-
});
36+
The published package contains the compiled `e2e.spec.ts`. You can execute it either through the provided CLI or by calling Jest directly:
3637

37-
console.log(`Tests completed: ${results.passed}/${results.totalTests} passed`);
38-
```
38+
```bash
39+
# Preferred: CLI wrapper injects the packaged config automatically
40+
npx lit-e2e
3941

40-
## Configuration Options
41-
42-
```typescript
43-
const results = await runLitE2eTests({
44-
network: 'naga-dev', // Required: 'naga-dev' | 'naga-local' | 'naga-staging'
45-
logLevel: 'info', // Optional: 'silent' | 'info' | 'debug'
46-
testTimeout: 30000, // Optional: timeout per test in milliseconds
47-
selectedTests: [
48-
// Optional: run specific tests only
49-
'pkpSign',
50-
'executeJs',
51-
'viemSignMessage',
52-
],
53-
});
42+
# Equivalent manual invocation
43+
npx jest \
44+
--config node_modules/@lit-protocol/e2e/dist/jest.e2e.package.config.cjs \
45+
node_modules/@lit-protocol/e2e/dist/specs/e2e.spec.js
5446
```
5547

56-
## Available Tests
48+
Both commands honour additional Jest flags (e.g. `--runInBand`, `--verbose`), so you can tailor runs to your infrastructure.
5749

58-
### Endpoint Tests
50+
## Author Your Own Specs
5951

60-
- `pkpSign` - PKP signing functionality
61-
- `executeJs` - Lit Actions execution
62-
- `viewPKPsByAddress` - PKP lookup by address
63-
- `viewPKPsByAuthData` - PKP lookup by auth data
64-
- `pkpEncryptDecrypt` - PKP-based encryption/decryption
65-
- `encryptDecryptFlow` - Full encryption/decryption workflow
66-
- `pkpPermissionsManagerFlow` - PKP permissions management
67-
- `eoaNativeAuthFlow` - EOA native authentication and PKP minting
52+
All helper utilities are exported from `@lit-protocol/e2e`. This includes the environment `init` routine, auth-context builders, and the new Shiva client wrapper.
6853

69-
### Integration Tests
54+
```ts
55+
import { init, createShivaClient } from '@lit-protocol/e2e';
7056

71-
- `viemSignMessage` - Viem integration for message signing
72-
- `viemSignTransaction` - Viem integration for transaction signing
73-
- `viemSignTypedData` - Viem integration for typed data signing
57+
describe('Epoch rollover', () => {
58+
it('advances when Shiva triggers a transition', async () => {
59+
const ctx = await init('naga-local');
60+
const shiva = await createShivaClient(ctx.litClient, {
61+
baseUrl: 'http://localhost:8000',
62+
});
7463

75-
## Test Results
64+
const before = await shiva.inspectEpoch();
65+
await shiva.transitionEpochAndWait();
66+
const after = await shiva.waitForEpochChange({ baselineEpoch: before.epoch });
7667

77-
```typescript
78-
const results = await runLitE2eTests({ network: 'naga-dev' });
68+
expect(after.epoch).not.toEqual(before.epoch);
69+
});
70+
});
71+
```
7972

80-
console.log(`Total: ${results.totalTests}`);
81-
console.log(`Passed: ${results.passed}`);
82-
console.log(`Failed: ${results.failed}`);
83-
console.log(`Duration: ${results.duration}ms`);
73+
Execute custom specs with the same packaged config:
8474

85-
// Check for failures
86-
if (results.failed > 0) {
87-
const failedTests = results.results.filter((r) => r.status === 'failed');
88-
failedTests.forEach((test) => {
89-
console.log(`Failed: ${test.name} - ${test.error}`);
90-
});
91-
}
75+
```bash
76+
npx jest --config node_modules/@lit-protocol/e2e/dist/jest.e2e.package.config.cjs qa-epoch.spec.ts
9277
```
9378

94-
## Examples
79+
## Bundled APIs
80+
81+
Key exports now available from the package:
82+
83+
- `init(network?, logLevel?)` – prepares Lit Client, Auth Manager, PKPs, and funded accounts across local or live environments.
84+
- `createShivaClient(litClient, { baseUrl, testnetId?, createRequest? })` – talks to the Shiva testnet manager (epoch transitions, node control, epoch inspection helpers).
85+
- Auth context helpers (EOA, PKP, Custom auth) under `@lit-protocol/e2e/helper/auth-contexts`.
86+
- Payment funding utilities, PKP helpers, and assorted testing primitives.
9587

96-
See `example.js` for detailed usage examples.
88+
Refer to the source under `packages/e2e/src/helper` for additional exported functions.
9789

98-
## Networks
90+
## Troubleshooting
9991

100-
- **naga-dev** - Development network (requires LIVE_MASTER_ACCOUNT)
101-
- **naga-local** - Local development network (requires LOCAL_MASTER_ACCOUNT)
102-
- **naga-staging** - Staging network (requires LIVE_MASTER_ACCOUNT)
92+
- **Jest not found** – install it locally (`pnpm add -D jest`). The CLI wrapper will exit with a helpful message if the dependency is missing.
93+
- **Missing signatures on naga-local** – provide `NAGA_LOCAL_CONTEXT_PATH` and optional `NAGA_LOCAL_CONTEXT_NAME` so the init routine calls `nagaLocal.withLocalContext`.
94+
- **RPC connectivity** – when pointing at a private RPC, set `LIT_YELLOWSTONE_PRIVATE_RPC_URL` so the Lit Client bypasses defaults.
10395

104-
## License
96+
With these additions, QA can stay in sync with the canonical Lit Protocol E2E coverage while extending it with custom assertions tailored to fast-epoch or failure scenarios.

packages/e2e/bin/run-e2e.cjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Lightweight CLI wrapper that runs Jest with the packaged E2E configuration.
5+
* Consumers can still override CLI flags; the bundled config is injected unless
6+
* `--config` is already provided.
7+
*/
8+
const path = require('path');
9+
10+
let runJest;
11+
try {
12+
runJest = require('jest').run;
13+
} catch (error) {
14+
console.error('❌ Unable to locate Jest. Please install it in your project (e.g. `pnpm add -D jest`).');
15+
process.exit(1);
16+
}
17+
18+
const defaultConfig = path.join(__dirname, '..', 'jest.e2e.package.config.cjs');
19+
20+
const argv = process.argv.slice(2);
21+
const hasConfigFlag = argv.some((arg) => arg === '--config' || arg.startsWith('--config='));
22+
23+
if (!hasConfigFlag) {
24+
argv.unshift('--config', defaultConfig);
25+
}
26+
27+
runJest(argv);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Packaged Jest configuration for consumers of @lit-protocol/e2e.
3+
* Resolves the compiled spec shipped with the package and keeps transforms open
4+
* in case additional TypeScript-based specs are provided by QA teams.
5+
*/
6+
const config = {
7+
testEnvironment: 'node',
8+
transform: {
9+
'^.+\\.(ts|tsx|js|mjs)$': 'babel-jest',
10+
},
11+
transformIgnorePatterns: [],
12+
testMatch: ['**/node_modules/@lit-protocol/e2e/dist/specs/**/*.spec.js'],
13+
moduleFileExtensions: ['ts', 'tsx', 'js', 'mjs', 'cjs', 'json'],
14+
};
15+
16+
module.exports = config;

packages/e2e/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,25 @@
66
"module": "dist/index.mjs",
77
"type": "commonjs",
88
"types": "dist/index.d.ts",
9+
"bin": {
10+
"lit-e2e": "dist/bin/run-e2e.cjs"
11+
},
912
"exports": {
1013
".": {
1114
"import": "./dist/index.mjs",
1215
"require": "./dist/index.js"
16+
},
17+
"./specs/e2e": {
18+
"import": "./dist/specs/e2e.spec.js",
19+
"require": "./dist/specs/e2e.spec.js"
20+
},
21+
"./jest-config": {
22+
"import": "./dist/jest.e2e.package.config.cjs",
23+
"require": "./dist/jest.e2e.package.config.cjs"
24+
},
25+
"./cli": {
26+
"import": "./dist/bin/run-e2e.cjs",
27+
"require": "./dist/bin/run-e2e.cjs"
1328
}
1429
},
1530
"files": [

packages/e2e/project.json

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,36 @@
1111
"outputPath": "dist/packages/e2e",
1212
"main": "packages/e2e/src/index.ts",
1313
"tsConfig": "packages/e2e/tsconfig.lib.json",
14-
"assets": ["packages/e2e/*.md", "packages/e2e/example.js"],
14+
"assets": [
15+
"packages/e2e/*.md",
16+
"packages/e2e/example.js",
17+
"packages/e2e/jest.e2e.package.config.cjs",
18+
{
19+
"input": "packages/e2e/bin",
20+
"glob": "**/*.cjs",
21+
"output": "bin"
22+
}
23+
],
1524
"updateBuildableProjectDepsInPackageJson": true
1625
},
17-
"dependsOn": ["^build"]
26+
"dependsOn": [
27+
"^build",
28+
{
29+
"target": "build-specs"
30+
}
31+
]
32+
},
33+
"build-specs": {
34+
"executor": "@nx/js:tsc",
35+
"outputs": ["dist/packages/e2e/specs"],
36+
"options": {
37+
"outputPath": "dist/packages/e2e/specs",
38+
"main": "packages/e2e/src/e2e.spec.ts",
39+
"tsConfig": "packages/e2e/tsconfig.spec.build.json"
40+
},
41+
"dependsOn": [
42+
"^build"
43+
]
1844
},
1945
"lint": {
2046
"executor": "@nx/linter:eslint",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "../../dist/packages/e2e/specs",
6+
"module": "CommonJS",
7+
"target": "ES2022",
8+
"declaration": false,
9+
"esModuleInterop": true,
10+
"allowSyntheticDefaultImports": true,
11+
"resolveJsonModule": true,
12+
"types": ["jest"]
13+
},
14+
"include": ["src/**/*.spec.ts"],
15+
"exclude": []
16+
}

0 commit comments

Comments
 (0)