@@ -27,16 +27,15 @@ async function getPersistedJavaScriptCode(page: Page): Promise<string> {
2727}
2828
2929async function getPersistedExplorerState ( page : Page ) : Promise < string > {
30- const persistedValue = await page . evaluate (
31- key => window . localStorage . getItem ( key ) ,
32- storageKey ,
33- ) ;
30+ return page . evaluate ( key => {
31+ const storedValue = window . localStorage . getItem ( key ) ;
3432
35- if ( ! persistedValue ) {
36- throw new Error ( "Expected explorer state to be persisted " ) ;
37- }
33+ if ( ! storedValue ) {
34+ throw new Error ( "No persisted state found in localStorage " ) ;
35+ }
3836
39- return persistedValue ;
37+ return storedValue ;
38+ } , storageKey ) ;
4039}
4140
4241async function getStoredHashValue ( page : Page ) : Promise < string > {
@@ -163,3 +162,37 @@ test("should fall back to localStorage when a v2 hash is malformed", async ({
163162
164163 await expect ( codeEditor ) . toContainText ( fallbackCode ) ;
165164} ) ;
165+
166+ test ( "should patch legacy Markdown options without math" , async ( { page } ) => {
167+ await page . addInitScript ( key => {
168+ window . localStorage . setItem (
169+ key ,
170+ JSON . stringify ( {
171+ state : {
172+ language : "markdown" ,
173+ markdownOptions : {
174+ markdownMode : "commonmark" ,
175+ markdownFrontmatter : "off" ,
176+ } ,
177+ } ,
178+ version : 0 ,
179+ } ) ,
180+ ) ;
181+ } , storageKey ) ;
182+ await page . goto ( "/" ) ;
183+
184+ await expect
185+ . poll ( async ( ) => {
186+ const explorerState = JSON . parse (
187+ await getPersistedExplorerState ( page ) ,
188+ ) ;
189+ return explorerState . state . markdownOptions . markdownMath ;
190+ } )
191+ . toBe ( false ) ;
192+
193+ await page . getByRole ( "button" , { name : "Language Options" } ) . click ( ) ;
194+
195+ await expect (
196+ page . getByRole ( "switch" , { exact : true , name : "Math" } ) ,
197+ ) . toHaveAttribute ( "aria-checked" , "false" ) ;
198+ } ) ;
0 commit comments