npm package: @sdaio/wdio-hot-reload-service
Description: WebdriverIO service for transparent hot module reloading during test execution
Author: Your Name
Latest version: 1.0.2

# @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

```bash
npm install --save-dev @sdaio/wdio-hot-reload-service
```

## Usage

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

```typescript
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:

```typescript
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:
1. Creates proxies for page object classes
2. Watches for file changes
3. Clears the module cache when files change
4. 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

```typescript
// 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.