-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-e2e.js
More file actions
55 lines (42 loc) · 1.76 KB
/
test-e2e.js
File metadata and controls
55 lines (42 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
function run(cmd, cwd) {
console.log(`\n> Running: ${cmd}`);
execSync(cmd, { stdio: 'inherit', cwd: cwd });
}
console.log('--- E2E Package Usage Tests ---');
try {
// 1. Build the project
run('npm run build', __dirname);
// 2. Pack the project
const packOutput = execSync('npm pack', { cwd: __dirname }).toString().trim();
const tarballLines = packOutput.split('\n');
const tarball = tarballLines[tarballLines.length - 1].trim();
const tarballPath = path.join(__dirname, tarball);
console.log(`\n> Packed: ${tarball}`);
// 3. Setup e2e container
const e2eDir = path.join(__dirname, 'e2e-tests');
const e2eNodeModules = path.join(e2eDir, 'node_modules', 'x402sdk');
if (fs.existsSync(e2eNodeModules)) {
fs.rmSync(e2eNodeModules, { recursive: true, force: true });
}
fs.mkdirSync(e2eNodeModules, { recursive: true });
// 4. Extract tarball manually
console.log('\n> Extracting tarball manually to avoid NPM locking...');
const tarDestFolder = e2eNodeModules.replace(/\\/g, '/');
run(`tar -xf "${tarball}" -C "${tarDestFolder}" --strip-components=1`, __dirname);
// 5. Build and Test Consumer Scripts
console.log('\n> Testing CJS Loader');
run('node test-cjs.js', e2eDir);
console.log('\n> Testing ESM Loader');
run('node test-esm.mjs', e2eDir);
console.log('\n> Testing Typescript Declarations');
run('npx tsc --noEmit', e2eDir);
console.log('\n✅ E2E Package Usage Validation Passed Successfully!');
// Cleanup
fs.rmSync(tarballPath, { force: true });
} catch (error) {
console.error('\n❌ E2E Validation Failed: ', error.message);
process.exit(1);
}