Skip to content

Commit bf7be2c

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

File tree

5 files changed

+113
-11
lines changed

5 files changed

+113
-11
lines changed

e2e/samples.spec.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { test, expect } from '@playwright/test';
18+
import fs from 'fs';
19+
import path from 'path';
20+
import childProcess from 'child_process'; // Import childProcess
21+
22+
const samplesDir = path.join(__dirname, '..', 'samples');
23+
24+
const sampleFolders = fs.readdirSync(samplesDir).filter((file) => {
25+
return fs.statSync(path.join(samplesDir, file)).isDirectory();
26+
});
27+
28+
sampleFolders.forEach((sampleFolder) => {
29+
test(`test ${sampleFolder}`, async ({ page }) => {
30+
const url = `http://localhost:8080/samples/${sampleFolder}/`;
31+
32+
// START Build the sample
33+
const buildProcess = childProcess.spawn('npm', ['run', 'build'], {
34+
cwd: path.join(samplesDir, sampleFolder),
35+
stdio: 'inherit',
36+
});
37+
38+
await new Promise((resolve, reject) => {
39+
buildProcess.on('close', (code) => {
40+
if (code === 0) {
41+
resolve(true);
42+
} else {
43+
reject(`Build process exited with code ${code}`);
44+
}
45+
});
46+
});
47+
// END Build the sample
48+
49+
// START run the preview
50+
const viteProcess = childProcess.spawn('npm', ['run', 'preview', '--', '--port=8080'], {
51+
cwd: path.join(samplesDir, sampleFolder),
52+
stdio: 'inherit',
53+
});
54+
55+
await new Promise((resolve) => setTimeout(resolve, 1000));
56+
// END run the preview
57+
58+
try {
59+
await page.goto(url);
60+
await page.waitForLoadState('domcontentloaded');
61+
// Add your assertions here
62+
} finally {
63+
viteProcess.kill();
64+
}
65+
});
66+
});

playwright.config.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import { defineConfig, devices } from '@playwright/test';
22

3+
/*
4+
* Copyright 2024 Google LLC
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
319
/**
420
* Read environment variables from file.
521
* https://github.com/motdotla/dotenv
@@ -20,34 +36,36 @@ export default defineConfig({
2036
/* Retry on CI only */
2137
retries: process.env.CI ? 2 : 0,
2238
/* Opt out of parallel tests on CI. */
23-
workers: process.env.CI ? 1 : undefined,
39+
//workers: process.env.CI ? 1 : undefined,
40+
workers: 1,
2441
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
2542
reporter: 'html',
2643
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2744
use: {
2845
/* Base URL to use in actions like `await page.goto('/')`. */
29-
// baseURL: 'http://127.0.0.1:3000',
46+
baseURL: 'http://localhost:8080',
3047

3148
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3249
trace: 'on-first-retry',
3350
},
3451

52+
testMatch: 'e2e/samples.spec.ts', // NEW
53+
3554
/* Configure projects for major browsers */
3655
projects: [
3756
{
3857
name: 'chromium',
3958
use: { ...devices['Desktop Chrome'] },
4059
},
41-
60+
/**
4261
{
4362
name: 'firefox',
4463
use: { ...devices['Desktop Firefox'] },
4564
},
46-
4765
{
4866
name: 'webkit',
4967
use: { ...devices['Desktop Safari'] },
50-
},
68+
},*/
5169

5270
/* Test against mobile viewports. */
5371
// {
@@ -76,4 +94,4 @@ export default defineConfig({
7694
// url: 'http://127.0.0.1:3000',
7795
// reuseExistingServer: !process.env.CI,
7896
// },
79-
});
97+
});

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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
// https://vitejs.dev/config/
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
217
import { defineConfig } from 'vite';
318
import dotenv from 'dotenv';
419

520
dotenv.config();
621

722
export default defineConfig({
8-
root: '../',
23+
//root: '../',
924
build: {
1025
emptyOutDir: true,
11-
outDir: '../dist',
26+
//outDir: '../dist',
27+
outDir: './dist',
1228
},
1329

1430
define: {

0 commit comments

Comments
 (0)