@sdaio/wdio-hot-reload-service
v1.0.2
Published
WebdriverIO service for transparent hot module reloading during test execution
Maintainers
Readme
@sdaio/wdio-hot-reload-service
A WebdriverIO service that provides transparent hot module reloading for test automation. Make changes to your page objects and see them reflected immediately without restarting your tests!
Features
- 🔄 Transparent hot reloading - Regular imports work automatically with hot reloading
- 🛠️ Zero configuration - Works out of the box with sensible defaults
- 📁 Configurable directories - Specify which directories get hot reloading
- 🚀 No code changes required - Engineers use standard import syntax
- ⚡ Instant updates - See changes immediately without test restarts
Installation
npm install --save-dev @sdaio/wdio-hot-reload-serviceUsage
Add the service to your wdio.conf.ts:
import HotReloadService from '@sdaio/wdio-hot-reload-service';
export const config = {
// ... other config
services: [
[HotReloadService, {
// Optional configuration
debug: true,
hotReloadDirs: ['./test/pageobjects', './src/pageobjects'],
watchPaths: ['./test/**/*.ts', './src/**/*.ts'],
exclude: ['node_modules', '@wdio', 'webdriverio']
}]
]
};How It Works
The service transparently intercepts module loading using Node's module system. When you import a page object:
import { LoginPage } from '../pageobjects/login.page';
describe('Login Test', () => {
it('should login', () => {
LoginPage.open();
LoginPage.login('user', 'pass');
// Edit login.page.ts and changes are reflected immediately!
});
});Behind the scenes, the service:
- Creates proxies for page object classes
- Watches for file changes
- Clears the module cache when files change
- Reloads the module on next access
Configuration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| debug | boolean | false | Enable debug logging |
| hotReloadDirs | string[] | ['./test/pageobjects', './src/pageobjects'] | Directories to enable hot reloading for |
| watchPaths | string[] | ['./test/**/*.ts', './src/**/*.ts'] | File patterns to watch for changes |
| exclude | string[] | ['node_modules', '@wdio', 'webdriverio'] | Patterns to exclude from watching |
Requirements
- WebdriverIO v8.0.0 or higher
- Node.js 14 or higher
Example
// login.page.ts
export class LoginPage {
static open() {
browser.url('/login');
}
static login(username: string, password: string) {
console.log('Logging in...'); // Change this while test is running!
$('#username').setValue(username);
$('#password').setValue(password);
$('#submit').click();
}
}
// login.test.ts
import { LoginPage } from '../pageobjects/login.page';
describe('Login', () => {
it('should login', async () => {
LoginPage.open();
// Pause to allow editing login.page.ts
await browser.pause(5000);
LoginPage.login('user', 'pass'); // Will use updated code!
});
});License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
