(metadataKey: string)
| 136 | }; |
| 137 | |
| 138 | function seedInitialMetadata(metadataKey: string): () => void { |
| 139 | // Enforcing this to make sure that even if we start to adopt more concurrent |
| 140 | // tests through Vitest (or similar), there's no risk of global state causing |
| 141 | // weird, hard-to-test false positives/negatives with other tests |
| 142 | if (metadataKey === DEFAULT_METADATA_KEY) { |
| 143 | throw new Error( |
| 144 | "Please ensure that the key you provide does not match the key used throughout the majority of the application", |
| 145 | ); |
| 146 | } |
| 147 | |
| 148 | const trackedNodes = new Set<Element>(); |
| 149 | allAppendedNodes.add(trackedNodes); |
| 150 | |
| 151 | for (const metadataName in mockDataForTags) { |
| 152 | // Serializing first because that's the part that can fail; want to fail |
| 153 | // early if possible |
| 154 | const value = mockDataForTags[metadataName as keyof typeof mockDataForTags]; |
| 155 | const serialized = JSON.stringify(value); |
| 156 | |
| 157 | const newNode = document.createElement("meta"); |
| 158 | newNode.setAttribute(metadataKey, metadataName); |
| 159 | newNode.setAttribute("content", serialized); |
| 160 | document.head.append(newNode); |
| 161 | |
| 162 | trackedNodes.add(newNode); |
| 163 | } |
| 164 | |
| 165 | return () => { |
| 166 | for (const node of trackedNodes) { |
| 167 | node.remove(); |
| 168 | } |
| 169 | }; |
| 170 | } |
| 171 | |
| 172 | function renderMetadataHook(metadataKey: string) { |
| 173 | const manager = new MetadataManager(metadataKey); |
no test coverage detected