Skip to content

feat(test-examples): update examples and tests due to type-system cha… #8

feat(test-examples): update examples and tests due to type-system cha…

feat(test-examples): update examples and tests due to type-system cha… #8

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
name: Build Package
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Type Check
run: bun run typecheck
- name: Build package
run: bun run build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7
lint:
name: Lint and Format Check
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Run Prettier Check
run: bunx prettier --check .
test-bun:
name: Test with Bun
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Run Integration Tests
run: bun run test:integration
- name: Run Coverage
run: bun run coverage
- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: coverage-bun
path: coverage/
retention-days: 5
test-node:
name: Test with Node.js
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Install dependencies
run: npm install --no-package-lock
- name: Create Node Test File
run: |
cat > node-test.js << 'EOF'
import { EventBroker } from './dist/index.js';
// Basic test to verify module loading in Node
const events = new EventBroker({ name: 'node-test' });
events.on('test:event', (data) => {
console.log(`Event received: ${JSON.stringify(data)}`);
});
events.emit('test:event', { message: 'Node.js test successful' });
console.log('Node.js compatibility test completed');
EOF
- name: Verify Node.js Compatibility
run: node node-test.js
test-deno:
name: Test with Deno
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Create Deno Test File
run: |
cat > deno-test.js << 'EOF'
import { EventBroker } from './dist/index.js';
// Basic test to verify module loading in Deno
const events = new EventBroker({ name: 'deno-test' });
events.on('test:event', (data) => {
console.log(`Event received: ${JSON.stringify(data)}`);
});
events.emit('test:event', { message: 'Deno test successful' });
console.log('Deno compatibility test completed');
EOF
- name: Verify Deno Compatibility
run: deno run --allow-read deno-test.js
test-browser:
name: Test Browser Compatibility
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Playwright
run: npm install -g playwright@latest
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Install Playwright browsers
run: playwright install --with-deps chromium
- name: Create HTML Test File
run: |
cat > browser-test.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
<title>@glandjs/events Browser Test</title>
</head>
<body>
<h1>Browser Compatibility Test</h1>
<div id="result">Running test...</div>
<script type="module">
import { EventBroker } from './dist/index.js';
try {
// Basic test to verify module loading in browser
const events = new EventBroker({ name: 'browser-test' });
events.on('test:event', (data) => {
console.log(`Event received: ${JSON.stringify(data)}`);
document.getElementById('result').innerText = 'Test successful: ' + data.message;
});
events.emit('test:event', { message: 'Browser test successful' });
console.log('Browser compatibility test completed');
} catch (error) {
document.getElementById('result').innerText = 'Test failed: ' + error.message;
console.error('Test error:', error);
}
</script>
</body>
</html>
EOF
- name: Create Playwright Test
run: |
cat > browser-test.js << 'EOF'
import { chromium } from 'playwright';
import { fileURLToPath } from 'url';
import path from 'path';
import http from 'http';
import fs from 'fs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Simple HTTP server to serve the test HTML file
const server = http.createServer((req, res) => {
const filePath = req.url === '/'
? path.join(__dirname, 'browser-test.html')
: path.join(__dirname, req.url);
try {
const content = fs.readFileSync(filePath);
const ext = path.extname(filePath);
const contentType = ext === '.html' ? 'text/html' :
ext === '.js' ? 'application/javascript' : 'text/plain';
res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
} catch (error) {
res.writeHead(404);
res.end('File not found');
}
});
(async () => {
const PORT = 3000;
server.listen(PORT);
console.log(`Server running at http://localhost:${PORT}`);
const browser = await chromium.launch();
const page = await browser.newPage();
page.on('console', msg => console.log(`Browser console: ${msg.text()}`));
await page.goto(`http://localhost:${PORT}`);
// Wait for test to complete
await page.waitForFunction(() => {
return document.getElementById('result').innerText !== 'Running test...';
}, { timeout: 5000 });
const result = await page.textContent('#result');
console.log(`Test result: ${result}`);
if (!result.includes('Test successful')) {
process.exit(1);
}
await browser.close();
server.close();
})();
EOF
- name: Install Test Dependencies
run: npm install playwright
- name: Run Browser Test
run: node browser-test.js