|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 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 | + * http://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 fs from 'node:fs'; |
| 18 | +import path from 'node:path'; |
| 19 | + |
| 20 | +import { test, expect } from './fixtures'; |
| 21 | + |
| 22 | +const schemaPath = path.join(__dirname, '..', '..', 'packages', 'playwright-core', 'src', 'tools', 'mcp', 'mcp-config.schema.json'); |
| 23 | + |
| 24 | +test('schema is valid JSON and has expected structure', async () => { |
| 25 | + const content = fs.readFileSync(schemaPath, 'utf8'); |
| 26 | + const schema = JSON.parse(content); |
| 27 | + |
| 28 | + expect(schema.$schema).toBe('http://json-schema.org/draft-07/schema#'); |
| 29 | + expect(schema.type).toBe('object'); |
| 30 | + expect(schema.properties).toBeTruthy(); |
| 31 | + expect(schema.title).toContain('Playwright'); |
| 32 | +}); |
| 33 | + |
| 34 | +test('schema has all top-level config keys', async () => { |
| 35 | + const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')); |
| 36 | + const props = Object.keys(schema.properties); |
| 37 | + |
| 38 | + for (const key of [ |
| 39 | + 'browser', 'extension', 'server', 'capabilities', 'saveSession', |
| 40 | + 'saveTrace', 'sharedBrowserContext', 'secrets', 'outputDir', |
| 41 | + 'console', 'network', 'testIdAttribute', 'timeouts', |
| 42 | + 'imageResponses', 'snapshot', 'allowUnrestrictedFileAccess', 'codegen', |
| 43 | + ]) { |
| 44 | + expect(props, `missing top-level key: ${key}`).toContain(key); |
| 45 | + } |
| 46 | +}); |
| 47 | + |
| 48 | +test('schema browser.browserName is an enum', async () => { |
| 49 | + const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')); |
| 50 | + const browserName = schema.properties.browser.properties.browserName; |
| 51 | + |
| 52 | + expect(browserName.enum).toEqual(['chromium', 'firefox', 'webkit']); |
| 53 | +}); |
| 54 | + |
| 55 | +test('schema browser.launchOptions has expected properties', async () => { |
| 56 | + const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')); |
| 57 | + const launchOpts = schema.properties.browser.properties.launchOptions.properties; |
| 58 | + |
| 59 | + for (const key of ['headless', 'channel', 'executablePath', 'args', 'proxy', 'slowMo', 'timeout', 'chromiumSandbox']) { |
| 60 | + expect(Object.keys(launchOpts), `launchOptions missing: ${key}`).toContain(key); |
| 61 | + } |
| 62 | +}); |
| 63 | + |
| 64 | +test('schema browser.contextOptions has expected properties', async () => { |
| 65 | + const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')); |
| 66 | + const ctxOpts = schema.properties.browser.properties.contextOptions.properties; |
| 67 | + |
| 68 | + for (const key of ['viewport', 'locale', 'colorScheme', 'baseURL', 'storageState', 'permissions', 'geolocation']) { |
| 69 | + expect(Object.keys(ctxOpts), `contextOptions missing: ${key}`).toContain(key); |
| 70 | + } |
| 71 | +}); |
| 72 | + |
| 73 | +test('schema excludes non-JSON types (Logger, Buffer)', async () => { |
| 74 | + const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')); |
| 75 | + const launchOpts = schema.properties.browser.properties.launchOptions.properties; |
| 76 | + const ctxOpts = schema.properties.browser.properties.contextOptions.properties; |
| 77 | + |
| 78 | + expect(launchOpts.logger).toBeUndefined(); |
| 79 | + expect(ctxOpts.logger).toBeUndefined(); |
| 80 | + |
| 81 | + const clientCerts = ctxOpts.clientCertificates?.items?.properties; |
| 82 | + if (clientCerts) { |
| 83 | + expect(clientCerts.cert).toBeUndefined(); |
| 84 | + expect(clientCerts.key).toBeUndefined(); |
| 85 | + expect(clientCerts.pfx).toBeUndefined(); |
| 86 | + expect(clientCerts.certPath).toBeTruthy(); |
| 87 | + expect(clientCerts.keyPath).toBeTruthy(); |
| 88 | + expect(clientCerts.pfxPath).toBeTruthy(); |
| 89 | + } |
| 90 | +}); |
| 91 | + |
| 92 | +test('schema colorScheme allows null', async () => { |
| 93 | + const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')); |
| 94 | + const colorScheme = schema.properties.browser.properties.contextOptions.properties.colorScheme; |
| 95 | + |
| 96 | + expect(colorScheme.oneOf).toBeTruthy(); |
| 97 | + expect(colorScheme.oneOf.some((s: any) => s.type === 'null')).toBe(true); |
| 98 | + expect(colorScheme.oneOf.some((s: any) => s.enum?.includes('light'))).toBe(true); |
| 99 | +}); |
| 100 | + |
| 101 | +test('schema ignoreDefaultArgs allows boolean or string array', async () => { |
| 102 | + const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')); |
| 103 | + const prop = schema.properties.browser.properties.launchOptions.properties.ignoreDefaultArgs; |
| 104 | + |
| 105 | + expect(prop.oneOf).toBeTruthy(); |
| 106 | + expect(prop.oneOf.some((s: any) => s.type === 'boolean')).toBe(true); |
| 107 | + expect(prop.oneOf.some((s: any) => s.type === 'array')).toBe(true); |
| 108 | +}); |
| 109 | + |
| 110 | +test('schema viewport allows null or object with width/height', async () => { |
| 111 | + const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')); |
| 112 | + const viewport = schema.properties.browser.properties.contextOptions.properties.viewport; |
| 113 | + |
| 114 | + expect(viewport.oneOf).toBeTruthy(); |
| 115 | + expect(viewport.oneOf.some((s: any) => s.type === 'null')).toBe(true); |
| 116 | + const objSchema = viewport.oneOf.find((s: any) => s.type === 'object'); |
| 117 | + expect(objSchema).toBeTruthy(); |
| 118 | + expect(objSchema.properties.width.type).toBe('number'); |
| 119 | + expect(objSchema.properties.height.type).toBe('number'); |
| 120 | +}); |
0 commit comments