-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add a basic snapshot generator test (#33123)
- Loading branch information
1 parent
4b1fbde
commit b421bd8
Showing
18 changed files
with
211 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ This project incorporates components from the projects listed below. The origina | |
- [email protected] (https://github.com/tapjs/stack-utils) | ||
- [email protected] (https://github.com/npm/wrappy) | ||
- [email protected] (https://github.com/websockets/ws) | ||
- [email protected] (https://github.com/eemeli/yaml) | ||
- [email protected] (https://github.com/thejoshwolfe/yauzl) | ||
- [email protected] (https://github.com/thejoshwolfe/yazl) | ||
|
||
|
@@ -1121,6 +1122,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
========================================= | ||
END OF [email protected] AND INFORMATION | ||
|
||
%% [email protected] NOTICES AND INFORMATION BEGIN HERE | ||
========================================= | ||
Copyright Eemeli Aro <[email protected]> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose | ||
with or without fee is hereby granted, provided that the above copyright notice | ||
and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
THIS SOFTWARE. | ||
========================================= | ||
END OF [email protected] AND INFORMATION | ||
|
||
%% [email protected] NOTICES AND INFORMATION BEGIN HERE | ||
========================================= | ||
The MIT License (MIT) | ||
|
@@ -1175,6 +1194,6 @@ END OF [email protected] AND INFORMATION | |
|
||
SUMMARY BEGIN HERE | ||
========================================= | ||
Total Packages: 46 | ||
Total Packages: 47 | ||
========================================= | ||
END OF SUMMARY |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { AriaTemplateNode } from './injected/ariaSnapshot'; | ||
import { yaml } from '../utilsBundle'; | ||
|
||
export function parseAriaSnapshot(text: string): AriaTemplateNode { | ||
type YamlNode = Record<string, Array<YamlNode> | string>; | ||
|
||
const parseKey = (key: string): AriaTemplateNode => { | ||
if (!key) | ||
return { role: '' }; | ||
|
||
const match = key.match(/^([a-z]+)(?:\s+(?:"([^"]*)"|\/([^\/]*)\/))?$/); | ||
|
||
if (!match) | ||
throw new Error(`Invalid key ${key}`); | ||
|
||
const role = match[1]; | ||
if (role && role !== 'text' && !allRoles.includes(role)) | ||
throw new Error(`Invalid role ${role}`); | ||
|
||
if (match[2]) | ||
return { role, name: match[2] }; | ||
if (match[3]) | ||
return { role, name: new RegExp(match[3]) }; | ||
return { role }; | ||
}; | ||
|
||
const valueOrRegex = (value: string): string | RegExp => { | ||
return value.startsWith('/') && value.endsWith('/') ? new RegExp(value.slice(1, -1)) : value; | ||
}; | ||
|
||
const convert = (object: YamlNode | string): AriaTemplateNode | RegExp | string => { | ||
const key = typeof object === 'string' ? object : Object.keys(object)[0]; | ||
const value = typeof object === 'string' ? undefined : object[key]; | ||
const parsed = parseKey(key); | ||
if (parsed.role === 'text') { | ||
if (typeof value !== 'string') | ||
throw new Error(`Generic role must have a text value`); | ||
return valueOrRegex(value as string); | ||
} | ||
if (Array.isArray(value)) | ||
parsed.children = value.map(convert); | ||
else if (value) | ||
parsed.children = [valueOrRegex(value)]; | ||
return parsed; | ||
}; | ||
const fragment = yaml.parse(text) as YamlNode[]; | ||
return convert({ '': fragment }) as AriaTemplateNode; | ||
} | ||
|
||
const allRoles = [ | ||
'alert', 'alertdialog', 'application', 'article', 'banner', 'blockquote', 'button', 'caption', 'cell', 'checkbox', 'code', 'columnheader', 'combobox', 'command', | ||
'complementary', 'composite', 'contentinfo', 'definition', 'deletion', 'dialog', 'directory', 'document', 'emphasis', 'feed', 'figure', 'form', 'generic', 'grid', | ||
'gridcell', 'group', 'heading', 'img', 'input', 'insertion', 'landmark', 'link', 'list', 'listbox', 'listitem', 'log', 'main', 'marquee', 'math', 'meter', 'menu', | ||
'menubar', 'menuitem', 'menuitemcheckbox', 'menuitemradio', 'navigation', 'none', 'note', 'option', 'paragraph', 'presentation', 'progressbar', 'radio', 'radiogroup', | ||
'range', 'region', 'roletype', 'row', 'rowgroup', 'rowheader', 'scrollbar', 'search', 'searchbox', 'section', 'sectionhead', 'select', 'separator', 'slider', | ||
'spinbutton', 'status', 'strong', 'structure', 'subscript', 'superscript', 'switch', 'tab', 'table', 'tablist', 'tabpanel', 'term', 'textbox', 'time', 'timer', | ||
'toolbar', 'tooltip', 'tree', 'treegrid', 'treeitem', 'widget', 'window' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,7 +155,6 @@ This project incorporates components from the projects listed below. The origina | |
- [email protected] (https://github.com/nodejs/undici) | ||
- [email protected] (https://github.com/browserslist/update-db) | ||
- [email protected] (https://github.com/isaacs/yallist) | ||
- [email protected] (https://github.com/eemeli/yaml) | ||
|
||
%% @ampproject/[email protected] NOTICES AND INFORMATION BEGIN HERE | ||
========================================= | ||
|
@@ -4398,26 +4397,8 @@ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
========================================= | ||
END OF [email protected] AND INFORMATION | ||
|
||
%% [email protected] NOTICES AND INFORMATION BEGIN HERE | ||
========================================= | ||
Copyright Eemeli Aro <[email protected]> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose | ||
with or without fee is hereby granted, provided that the above copyright notice | ||
and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
THIS SOFTWARE. | ||
========================================= | ||
END OF [email protected] AND INFORMATION | ||
|
||
SUMMARY BEGIN HERE | ||
========================================= | ||
Total Packages: 152 | ||
Total Packages: 151 | ||
========================================= | ||
END OF SUMMARY |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.