Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/mobilewright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"directory": "packages/mobilewright"
},
"files": [
"dist"
"dist",
"templates"
],
"dependencies": {
"@mobilewright/core": "^0.0.1",
Expand Down
26 changes: 25 additions & 1 deletion packages/mobilewright/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import { Command } from 'commander';
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
import { readFile, writeFile } from 'node:fs/promises';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

import { createRequire } from 'node:module';
import { MobilecliDriver, DEFAULT_URL } from '@mobilewright/driver-mobilecli';
Expand All @@ -13,6 +15,7 @@ const _require = createRequire(import.meta.url);
const _pkg = _require('../package.json') as { version: string };

const HTML_REPORT_DIR = 'mobilewright-report';
const TEMPLATES_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'templates');

const program = new Command();
program.name('mobilewright');
Expand Down Expand Up @@ -156,6 +159,27 @@ program
if (checks.some(c => c.status === 'error')) process.exitCode = 1;
});

// ── init ───────────────────────────────────────────────────────────────
program
.command('init')
.description('scaffold a mobilewright.config.ts and example test in the current directory')
.action(async () => {
const files = [
{ src: 'mobilewright.config.ts', dest: resolve(process.cwd(), 'mobilewright.config.ts') },
{ src: 'example.test.ts', dest: resolve(process.cwd(), 'example.test.ts') },
];

for (const { src, dest } of files) {
if (existsSync(dest)) {
console.log(`skipped ${src} (already exists)`);
continue;
}
const content = await readFile(resolve(TEMPLATES_DIR, src), 'utf8');
await writeFile(dest, content, 'utf8');
console.log(`created ${src}`);
}
});

function padRight(str: string, len: number): string {
return str.length >= len ? str + ' ' : str + ' '.repeat(len - str.length);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/mobilewright/templates/example.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test, expect } from '@mobilewright/test';

test('app launches and shows home screen', async ({ screen }) => {
await expect(screen.getByText('Welcome')).toBeVisible();
});
8 changes: 8 additions & 0 deletions packages/mobilewright/templates/mobilewright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'mobilewright';

export default defineConfig({
platform: 'ios',
bundleId: 'com.example.myapp',
deviceName: /iPhone 16/,
timeout: 10_000,
});
Loading