Skip to content

Commit ce0c7db

Browse files
committed
Adds Playwright testing that actually works; other minor updates.
1 parent a163ae7 commit ce0c7db

File tree

5 files changed

+66
-10
lines changed

5 files changed

+66
-10
lines changed

e2e/samples.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// e2e/samples.spec.ts
2+
import { test, expect } from '@playwright/test';
3+
import fs from 'fs';
4+
import path from 'path';
5+
import childProcess from 'child_process'; // Import childProcess
6+
7+
const samplesDir = path.join(__dirname, '..', 'samples');
8+
9+
const sampleFolders = fs.readdirSync(samplesDir).filter((file) => {
10+
return fs.statSync(path.join(samplesDir, file)).isDirectory();
11+
});
12+
13+
sampleFolders.forEach((sampleFolder) => {
14+
test(`test ${sampleFolder}`, async ({ page }) => {
15+
const url = `http://localhost:8080/samples/${sampleFolder}/`;
16+
17+
// START Build the sample
18+
const buildProcess = childProcess.spawn('npm', ['run', 'build'], {
19+
cwd: path.join(samplesDir, sampleFolder),
20+
stdio: 'inherit',
21+
});
22+
23+
await new Promise((resolve, reject) => {
24+
buildProcess.on('close', (code) => {
25+
if (code === 0) {
26+
resolve(true);
27+
} else {
28+
reject(`Build process exited with code ${code}`);
29+
}
30+
});
31+
});
32+
// END Build the sample
33+
34+
// START run the preview
35+
const viteProcess = childProcess.spawn('npm', ['run', 'preview', '--', '--port=8080'], {
36+
cwd: path.join(samplesDir, sampleFolder),
37+
stdio: 'inherit',
38+
});
39+
40+
await new Promise((resolve) => setTimeout(resolve, 1000));
41+
// END run the preview
42+
43+
try {
44+
await page.goto(url);
45+
await page.waitForLoadState('domcontentloaded');
46+
// Add your assertions here
47+
} finally {
48+
viteProcess.kill();
49+
}
50+
});
51+
});

playwright.config.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,36 @@ export default defineConfig({
2020
/* Retry on CI only */
2121
retries: process.env.CI ? 2 : 0,
2222
/* Opt out of parallel tests on CI. */
23-
workers: process.env.CI ? 1 : undefined,
23+
//workers: process.env.CI ? 1 : undefined,
24+
workers: 1,
2425
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
2526
reporter: 'html',
2627
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2728
use: {
2829
/* Base URL to use in actions like `await page.goto('/')`. */
29-
// baseURL: 'http://127.0.0.1:3000',
30+
baseURL: 'http://localhost:8080',
3031

3132
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3233
trace: 'on-first-retry',
3334
},
3435

36+
testMatch: 'e2e/samples.spec.ts', // NEW
37+
3538
/* Configure projects for major browsers */
3639
projects: [
3740
{
3841
name: 'chromium',
3942
use: { ...devices['Desktop Chrome'] },
4043
},
41-
44+
/**
4245
{
4346
name: 'firefox',
4447
use: { ...devices['Desktop Firefox'] },
4548
},
46-
4749
{
4850
name: 'webkit',
4951
use: { ...devices['Desktop Safari'] },
50-
},
52+
},*/
5153

5254
/* Test against mobile viewports. */
5355
// {
@@ -76,4 +78,4 @@ export default defineConfig({
7678
// url: 'http://127.0.0.1:3000',
7779
// reuseExistingServer: !process.env.CI,
7880
// },
79-
});
81+
});

samples/add-map/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"scripts": {
55
"build": "tsc && bash ../jsfiddle.sh add-map && bash ../app.sh add-map && bash ../docs.sh add-map && npm run build:vite --workspace=.",
66
"start": "tsc && vite build --base './' && vite",
7-
"build:vite": "vite build --base './'"
7+
"build:vite": "vite build --base './'",
8+
"preview": "vite preview"
89
},
910
"dependencies": {
1011

samples/map-simple/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "1.0.0",
44
"scripts": {
55
"build": "tsc && bash ../jsfiddle.sh map-simple && bash ../app.sh map-simple && bash ../docs.sh map-simple && vite build --base './'",
6-
"start": "tsc && vite build --base './' && vite"
6+
"start": "tsc && vite build --base './' && vite",
7+
"preview": "vite preview"
78
},
89
"dependencies": {
910

samples/vite.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import dotenv from 'dotenv';
55
dotenv.config();
66

77
export default defineConfig({
8-
root: '../',
8+
//root: '../',
99
build: {
1010
emptyOutDir: true,
11-
outDir: '../dist',
11+
//outDir: '../dist',
12+
outDir: './dist',
1213
},
1314

1415
define: {

0 commit comments

Comments
 (0)