Skip to content

Commit bf66a0f

Browse files
committed
chore: adds work in progress
1 parent 3571581 commit bf66a0f

File tree

19 files changed

+924
-13
lines changed

19 files changed

+924
-13
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ coverage.xml
1010
*.swp
1111
*.swo
1212
.phpunit.cache
13+
14+
# Playwright
15+
node_modules/
16+
/test-results/
17+
/playwright-report/
18+
/blob-report/
19+
/playwright/.cache/

.temp/e2e/.gitkeep

Whitespace-only changes.

.temp/e2e/runtime.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('runtime', async ({ page }) => {
4+
await page.goto('https://laravel.com');
5+
await expect(page).toHaveTitle(/Laravel/);
6+
});

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
"require": {
1515
"php": "^8.2",
1616
"pestphp/pest": "^3.0.0",
17-
"pestphp/pest-plugin": "^3.0.0"
17+
"pestphp/pest-plugin": "^3.0.0",
18+
"symfony/process": "^7.2"
1819
},
1920
"autoload": {
2021
"psr-4": {
21-
"Pest\\PluginName\\": "src/"
22+
"Pest\\Browser\\": "src/"
2223
},
2324
"files": [
2425
"src/Autoload.php"

package-lock.json

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "pest-plugin-browser",
3+
"version": "1.0.0",
4+
"description": "This repository contains the Pest Plugin Browser.",
5+
"main": "index.js",
6+
"directories": {
7+
"test": "tests"
8+
},
9+
"scripts": {},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/pestphp/pest-plugin-browser.git"
13+
},
14+
"keywords": [],
15+
"author": "",
16+
"license": "ISC",
17+
"bugs": {
18+
"url": "https://github.com/pestphp/pest-plugin-browser/issues"
19+
},
20+
"homepage": "https://github.com/pestphp/pest-plugin-browser#readme",
21+
"devDependencies": {
22+
"@playwright/test": "^1.50.1",
23+
"@types/node": "^22.13.1"
24+
}
25+
}

playwright.config.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// @ts-check
2+
import { defineConfig, devices } from '@playwright/test';
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// import dotenv from 'dotenv';
9+
// import path from 'path';
10+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
11+
12+
/**
13+
* @see https://playwright.dev/docs/test-configuration
14+
*/
15+
export default defineConfig({
16+
testDir: './.temp/e2e',
17+
/* Run tests in files in parallel */
18+
fullyParallel: true,
19+
/* Fail the build on CI if you accidentally left test.only in the source code. */
20+
forbidOnly: !!process.env.CI,
21+
/* Retry on CI only */
22+
retries: process.env.CI ? 2 : 0,
23+
/* Opt out of parallel tests on CI. */
24+
workers: process.env.CI ? 1 : undefined,
25+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
26+
reporter: 'html',
27+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
28+
use: {
29+
/* Base URL to use in actions like `await page.goto('/')`. */
30+
// baseURL: 'http://127.0.0.1:3000',
31+
32+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
33+
trace: 'on-first-retry',
34+
},
35+
36+
/* Configure projects for major browsers */
37+
projects: [
38+
{
39+
name: 'chromium',
40+
use: { ...devices['Desktop Chrome'] },
41+
},
42+
43+
/*
44+
45+
{
46+
name: 'firefox',
47+
use: { ...devices['Desktop Firefox'] },
48+
},
49+
50+
{
51+
name: 'webkit',
52+
use: { ...devices['Desktop Safari'] },
53+
},
54+
55+
/* Test against mobile viewports. */
56+
// {
57+
// name: 'Mobile Chrome',
58+
// use: { ...devices['Pixel 5'] },
59+
// },
60+
// {
61+
// name: 'Mobile Safari',
62+
// use: { ...devices['iPhone 12'] },
63+
// },
64+
65+
/* Test against branded browsers. */
66+
// {
67+
// name: 'Microsoft Edge',
68+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
69+
// },
70+
// {
71+
// name: 'Google Chrome',
72+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
73+
// },
74+
],
75+
76+
/* Run your local dev server before starting the tests */
77+
// webServer: {
78+
// command: 'npm run start',
79+
// url: 'http://127.0.0.1:3000',
80+
// reuseExistingServer: !process.env.CI,
81+
// },
82+
});
83+

src/Autoload.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Pest\PluginName;
5+
namespace Pest\Browser;
66

77
use Pest\Plugin;
8-
use PHPUnit\Framework\TestCase;
98

109
Plugin::uses(Example::class);
1110

12-
/**
13-
* @return TestCase
14-
*/
15-
function example(string $argument)
11+
function visit(string $url): PendingTest
1612
{
17-
return test()->example(...func_get_args()); // @phpstan-ignore-line
13+
return (new PendingTest)->visit($url);
1814
}

src/Compiler.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Pest\Browser;
6+
7+
use Pest\Browser\Contracts\Operation;
8+
9+
/**
10+
* @internal
11+
*/
12+
final class Compiler
13+
{
14+
/**
15+
* The path to the tests.
16+
*/
17+
private const TEST_PATH = __DIR__.'/../.temp/e2e/runtime.spec.js';
18+
19+
/**
20+
* @param array<int, Operation> $operations
21+
*/
22+
public function __construct(
23+
private array $operations
24+
) {
25+
//
26+
}
27+
28+
/**
29+
* Compiles the operations.
30+
*/
31+
public function compile(): void
32+
{
33+
$content = implode(
34+
"\n",
35+
array_map(
36+
static fn (Operation $operation): string => $operation->compile(),
37+
$this->operations,
38+
),
39+
);
40+
41+
file_put_contents(self::TEST_PATH, <<<JS
42+
import { test, expect } from '@playwright/test';
43+
44+
test('runtime', async ({ page }) => {
45+
$content
46+
});
47+
JS,
48+
);
49+
}
50+
}

src/Contracts/Operation.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Pest\Browser\Contracts;
6+
7+
/**
8+
* @internal
9+
*/
10+
interface Operation
11+
{
12+
/**
13+
* Compile the operation to JavaScript code.
14+
*/
15+
public function compile(): string;
16+
}

0 commit comments

Comments
 (0)