-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
156 lines (138 loc) · 5.69 KB
/
Copy pathplaywright.config.ts
File metadata and controls
156 lines (138 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { defineConfig, devices } from '@playwright/test';
import { globSync } from 'glob';
import { execSync } from 'child_process';
// Get all visualizer packages at config time
let visualizerPackages: { name: string; path: string }[] = [];
try {
const pnpmOutput = execSync('pnpm m ls --json --depth -1', { encoding: 'utf8' });
const packages = JSON.parse(pnpmOutput);
visualizerPackages = packages.filter(
(pkg: any) => pkg.name?.startsWith('@kaggle-environments/') && pkg.name?.endsWith('-visualizer')
);
} catch {
console.warn('Could not list pnpm workspaces');
}
// Find the best matching package name for a given directory name
function findPackageMatch(dirName: string): string {
// Try exact match with directory name
let match = visualizerPackages.find((pkg) => pkg.name.includes(dirName));
if (match) return dirName;
// Try with hyphens instead of underscores
const kebabName = dirName.replace(/_/g, '-');
match = visualizerPackages.find((pkg) => pkg.name.includes(kebabName));
if (match) return kebabName;
// Fallback to directory name
return dirName;
}
/**
* Playwright configuration for kaggle-environments visualizer integration tests.
*
* To add tests for a visualizer:
* 1. Create a test file in your visualizer's e2e directory (e.g., visualizer/default/e2e/connectx.test.ts)
* 2. Ensure the visualizer has a `dev-with-replay` script in package.json
* 3. Add a test replay file in the replays/ directory.
* - Warning: this replay file is PUBLIC. If you are actively developing a visualizer for a simulation competition,
* you run the risk of leaks. Proceed with caution and use dummy data.
* 4. Run `pnpm test:e2e` - your tests will be automatically discovered
*/
const testPatterns = [
'kaggle_environments/envs/*/visualizer/**/*.test.ts',
'kaggle_environments/envs/open_spiel_env/games/*/visualizer/**/*.test.ts',
'web/core/e2e/**/*.test.ts',
];
const testFiles = testPatterns.flatMap((pattern) => globSync(pattern));
interface VisualizerInfo {
name: string;
testMatch: string;
port: number;
packageFilter: string;
}
function getVisualizerInfo(testFile: string): VisualizerInfo | null {
// Match standard envs: kaggle_environments/envs/{name}/visualizer/...
const standardMatch = testFile.match(/kaggle_environments\/envs\/([^/]+)\/visualizer\//);
if (standardMatch) {
const dirName = standardMatch[1];
// Package names are inconsistent - some use hyphens (kore-fleets), some underscores (llm_20_questions)
// Find the correct form that matches the actual package name
const matchingName = findPackageMatch(dirName);
return {
name: dirName,
testMatch: `kaggle_environments/envs/${dirName}/visualizer/**/*.test.ts`,
port: 0, // Placeholder — real port assigned below after sorting, so collisions can't happen.
packageFilter: matchingName,
};
}
// Match OpenSpiel games: kaggle_environments/envs/open_spiel_env/games/{name}/visualizer/{version}/...
const openSpielMatch = testFile.match(
/kaggle_environments\/envs\/open_spiel_env\/games\/([^/]+)\/visualizer\/([^/]+)\//
);
if (openSpielMatch) {
const gameName = openSpielMatch[1];
const version = openSpielMatch[2];
// Convert underscores to hyphens for kebab-case package names
const kebabGameName = gameName.replace(/_/g, '-');
// Version suffix: "default" -> "", "v2" -> "-v2"
const versionSuffix = version === 'default' ? '' : `-${version}`;
const projectName = `open-spiel-${kebabGameName}${versionSuffix}`;
return {
name: projectName,
testMatch: `kaggle_environments/envs/open_spiel_env/games/${gameName}/visualizer/${version}/**/*.test.ts`,
port: 0, // Placeholder — real port assigned below after sorting, so collisions can't happen.
packageFilter: `@kaggle-environments/open-spiel-${kebabGameName}${versionSuffix}-visualizer`,
};
}
return null;
}
// Deduplicate visualizers (multiple test files in same visualizer)
const visualizerMap = new Map<string, VisualizerInfo>();
for (const testFile of testFiles) {
const info = getVisualizerInfo(testFile);
if (info && !visualizerMap.has(info.name)) {
visualizerMap.set(info.name, info);
}
}
// Add the core package if it has test files
const coreTestFiles = testFiles.filter((f) => f.startsWith('web/core/'));
if (coreTestFiles.length > 0) {
visualizerMap.set('core', {
name: 'core',
testMatch: 'web/core/e2e/**/*.test.ts',
port: 0, // Placeholder — real port assigned below after sorting, so collisions can't happen.
packageFilter: '@kaggle-environments/core',
});
}
// Sort before assigning ports so each name gets a stable port regardless of glob order.
const visualizers = Array.from(visualizerMap.values()).sort((a, b) => a.name.localeCompare(b.name));
visualizers.forEach((viz, i) => {
viz.port = 5173 + i;
});
const projects = visualizers.map((viz) => ({
name: viz.name,
testMatch: viz.testMatch,
use: {
trace: 'on-first-retry' as const,
baseURL: `http://localhost:${viz.port}`,
...devices['Desktop Chrome'],
},
}));
const webServers = visualizers.map((viz) => ({
command:
viz.name === 'core'
? `pnpm --filter @kaggle-environments/core dev-with-replay`
: `pnpm test-server ${viz.packageFilter}`,
url: `http://localhost:${viz.port}`,
reuseExistingServer: !process.env.CI,
timeout: 120000,
env: { VITE_PORT: String(viz.port) },
}));
if (process.env.DEBUG) {
console.log('Discovered visualizers:', visualizers);
}
export default defineConfig({
testMatch: testPatterns,
fullyParallel: true,
retries: 1,
reporter: [['list'], ['json', { outputFile: 'test-results/results.json' }], ['html', { open: 'never' }]],
projects,
webServer: webServers.length > 0 ? webServers : undefined,
});