npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dynamic-import-service

v1.1.0

Published

WebdriverIO service for dynamic imports with automatic Babel transformation

Readme

Dynamic Import Service for WebdriverIO

This service automatically configures Babel to transform static imports to dynamic imports with cache busting for reliable test execution.

Features

  • 🔄 Cache busting - Forces fresh module loading on every import
  • 🔧 Automatic Babel configuration - No manual setup required
  • 🧩 Simple integration - Just add to your services
  • 🧪 Reliable testing - Ensure tests always use the latest code

Installation

npm install dynamic-import-service --save-dev

Usage

Add the service to your wdio.conf.ts file:

// wdio.conf.ts
import type { Options } from '@wdio/types';
import DynamicImportService from 'dynamic-import-service';

export const config: Options.Testrunner = {
  // Other WebdriverIO configuration...
  
  services: [
    [DynamicImportService, {
      // Configuration options (all optional)
      enableBabelTransform: true,
      include: ['.spec.ts', '.test.ts', '.e2e.ts'],
      exclude: ['node_modules', '@wdio', 'webdriverio'],
      debug: false
    }]
  ],
  
  // The service will automatically configure Babel
};

Refresh Modes

The service supports different refresh modes to control when modules are reloaded:

Command-level Refreshing ('command')

  • Refreshes modules after each WebdriverIO command
  • Provides immediate updates after interactions
  • Higher overhead but most responsive
// wdio.conf.ts
import DynamicImportService from 'dynamic-import-service';

export const config = {
  // ...
  services: [
    [DynamicImportService, {
      refreshMode: 'command'  // Refresh after each command
    }]
  ]
};

Test-level Refreshing ('test' - Default)

  • Refreshes modules before each test case
  • Good balance of freshness and performance
  • Ensures consistent module state within each test
// wdio.conf.ts
import DynamicImportService from 'dynamic-import-service';

export const config = {
  // ...
  services: [
    [DynamicImportService, {
      refreshMode: 'test'  // Refresh before each test (default)
    }]
  ]
};

Manual Refreshing ('manual')

  • Only refreshes modules when explicitly requested
  • Maximum control and performance
  • Requires manual API calls
// wdio.conf.ts
import DynamicImportService from 'dynamic-import-service';

export const config = {
  // ...
  services: [
    [DynamicImportService, {
      refreshMode: 'manual'  // Only refresh when explicitly called
    }]
  ]
};

// In test file:
describe('My Test', () => {
  it('should refresh modules at strategic points', async () => {
    // Get service instance
    const service = browser.getService('DynamicImportService');
    
    // Run tests...
    
    // Explicitly refresh modules at a strategic point
    await service.refreshModules();
    
    // Continue with fresh modules...
  });
});

Disabled Refreshing ('never')

  • Never automatically refreshes modules
  • File watching is disabled
  • Use when you only want the Babel transformation
// wdio.conf.ts
import DynamicImportService from 'dynamic-import-service';

export const config = {
  // ...
  services: [
    [DynamicImportService, {
      refreshMode: 'never'  // Disable automatic refreshing
    }]
  ]
};

How It Works

The service works in two ways:

1. Automatic Babel Transformation (Default)

When you write normal imports in your test files:

// Your test file
import { MyPage } from '../pages/MyPage';

describe('My Test', () => {
  it('should work with transformed imports', async () => {
    // Use MyPage...
  });
});

The Babel plugin transforms them to dynamic imports:

// What it's transformed to
const { MyPage } = await dynamicImport('../pages/MyPage', import.meta.url);

describe('My Test', () => {
  it('should work with transformed imports', async () => {
    // Use MyPage...
  });
});

2. Direct Dynamic Import Usage

You can also use the dynamicImport function directly:

// Direct usage
import { dynamicImport } from 'dynamic-import-service';

describe('My Test', () => {
  it('should work with direct dynamic imports', async () => {
    const { MyPage } = await dynamicImport('./pages/MyPage', import.meta.url);
    // Use MyPage...
  });
});

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | enableBabelTransform | boolean | true | Enable Babel transformation | | include | string[] | ['.spec.ts', '.test.ts', '.e2e.ts'] | File patterns to include in transformation | | exclude | string[] | ['node_modules', '@wdio', 'webdriverio'] | File patterns to exclude from transformation | | debug | boolean | false | Enable debug logging | | refreshMode | string | 'test' | When to automatically refresh modules. Options: 'command', 'test', 'manual', 'never' | | watchPaths | string[] | ['./test/**/*.ts', './src/**/*.ts'] | File patterns to watch for changes |

Benefits

  • No stale modules - Always get fresh code when tests run
  • Cross-platform compatibility - Works on Windows and Linux
  • Zero configuration - Just add the service
  • Framework agnostic - Works with Mocha, Jasmine, and Cucumber

License

MIT