
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
Jest for your data layer - A test runner specifically designed for testing analytics tracking implementations.
DLest provides familiar Jest-like syntax for validating data layer events in web applications. Built on top of Playwright, it allows developers to write unit tests for their analytics implementations and catch tracking bugs before they reach production.
npm install --save-dev dlest
npx dlest init
This creates:
dlest.config.js - Configuration filetests/example.test.js - Example test filetest-page.html - Sample HTML page for testing# Test local development
npx dlest
# Test with local server
npx dlest --serve
# Test remote URL (NEW!)
npx dlest https://staging.example.com
# Test with authentication
npx dlest https://staging.example.com --auth-user=admin --auth-pass=senha
# Verbose mode for debugging
npx dlest --verbose
# CI mode for pipelines
npx dlest https://production.example.com --ci
// tests/purchase-flow.test.js
const { test, expect } = require('dlest');
test.describe('Purchase Flow', () => {
test('complete purchase journey', async ({ page, dataLayer }) => {
// 1. View product
await page.goto('http://localhost:3000/products.html');
await expect(dataLayer).toHaveEvent('view_item', {
value: 99.99,
currency: 'USD'
});
// 2. Add to cart
await page.click('#add-to-cart');
await expect(dataLayer).toHaveEvent('add_to_cart', {
value: 99.99,
items: expect.arrayContaining([
expect.objectContaining({
item_id: 'prod-123',
quantity: 1
})
])
});
// 3. Complete purchase
await page.click('#checkout');
await page.waitForTimeout(1000); // Wait for async purchase
await expect(dataLayer).toHaveEvent('purchase', {
transaction_id: expect.any(String),
value: 99.99,
currency: 'USD'
});
// 4. Verify the complete sequence
await expect(dataLayer).toHaveEventSequence([
'view_item',
'add_to_cart',
'purchase'
]);
});
});
DLest uses familiar Jest-like syntax:
const { test, expect } = require('dlest');
test('page view tracking', async ({ page, dataLayer }) => {
await page.goto('http://localhost:3000');
await expect(dataLayer).toHaveEvent('page_view');
});
test('purchase tracking', async ({ page, dataLayer }) => {
await page.goto('/product/123');
await page.click('#add-to-cart');
await page.click('#checkout');
await expect(dataLayer).toHaveEvent('purchase', {
transaction_id: expect.any(String),
value: expect.any(Number),
currency: 'BRL'
});
});
Test analytics on staging or production environments:
// Test remote URL directly
npx dlest https://staging.mysite.com
// With authentication
npx dlest https://staging.mysite.com --auth-user=admin --auth-pass=senha
// Use environment variables
export DLEST_BASE_URL=https://staging.mysite.com
export DLEST_AUTH_USER=admin
export DLEST_AUTH_PASS=senha
npx dlest
// Custom test file for remote
npx dlest https://production.mysite.com --test=tests/production.test.js
// CI/CD Pipeline
npx dlest $STAGING_URL --ci
Debug with detailed event information:
npx dlest --verbose
Shows:
DLest provides specialized matchers for data layer testing:
await expect(dataLayer).toHaveEvent(eventName, eventData?) - Check if event existsawait expect(dataLayer).toHaveEventData(eventData) - Check if any event contains specific dataawait expect(dataLayer).toHaveEventCount(eventName, count) - Verify event countawait expect(dataLayer).toHaveEventSequence(eventNames[]) - Validate event sequence// Event existence
await expect(dataLayer).toHaveEvent('purchase');
// Event with specific data
await expect(dataLayer).toHaveEvent('purchase', { value: 99.90 });
// Event count
await expect(dataLayer).toHaveEventCount('page_view', 1);
// Event sequence
await expect(dataLayer).toHaveEventSequence(['page_view', 'add_to_cart', 'purchase']);
// Negation
await expect(dataLayer).not.toHaveEvent('error');
Create a dlest.config.js file in your project root:
module.exports = {
// Base URL for tests
baseURL: 'http://localhost:3000',
// Browser settings
browsers: ['chromium'], // chromium, firefox, webkit
headless: true,
// Test settings
timeout: 30000,
testDir: './tests',
testMatch: ['**/*.test.js'],
// Data layer settings
dataLayer: {
variableName: 'dataLayer', // Custom variable name
waitTimeout: 5000, // Event wait timeout
}
};
# Start development server
npx dlest serve
npx dlest serve --port 8080 # Custom port
npx dlest serve --root ./dist # Custom root directory
# Run all tests
npx dlest
# Run tests with auto-server (recommended)
npx dlest --serve
npx dlest --serve --serve-port 8080
# Run specific test file
npx dlest tests/purchase.test.js
# Use different browser
npx dlest --browser=firefox
# Run with visible browser (non-headless)
npx dlest --no-headless
# Initialize project
npx dlest init
# Initialize with e-commerce template
npx dlest init --template=ecommerce
# Install Playwright browsers
npx dlest install
# NPM Scripts (alternative to npx commands)
npm test # Run tests
npm run test:serve # Run tests with auto-server
npm run serve # Start development server
npm run serve:dev # Start server with verbose logging
DLest includes a built-in static file server for development:
# Start server on default port (3000)
npx dlest serve
# Custom port
npx dlest serve --port 8080
# Custom root directory
npx dlest serve --root ./dist
# Custom host (for network access)
npx dlest serve --host 0.0.0.0
# Verbose logging
npx dlest serve --verbose
The server provides:
DLest comes with pre-built templates:
npx dlest init --template=basic
Includes tests for:
npx dlest init --template=ecommerce
Includes tests for:
DLest supports familiar Jest patterns:
// Test suites
test.describe('E-commerce Flow', () => {
test('product view', async ({ page, dataLayer }) => {
// Test implementation
});
});
// Expect helpers
expect.any(String)
expect.arrayContaining([...])
expect.objectContaining({...})
// Hooks (planned for future releases)
beforeEach(({ page, dataLayer }) => {
// Setup
});
Analytics tracking breaks frequently due to:
DLest solves this by enabling automated testing of your data layer implementation.
Tests timing out?
timeout: 60000npx dlest serveEvents not being captured?
--no-headless to debug visuallyPort already in use?
npx dlest serve --port 8080We welcome contributions! Please see our Contributing Guide for details.
# Clone the repo
git clone https://github.com/metricasboss/dlest.git
cd dlest
# Install dependencies
npm install
# Run tests
npm test
# Start development
npm run dev
MIT © MetricasBoss
FAQs
Jest for your data layer - test runner for analytics tracking implementations
We found that dlest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.