Browse Source

fix(test): e2e fails
refactor(e2e): print logs when error

Andelf 3 years ago
parent
commit
ec43dd7ee1
3 changed files with 15 additions and 12 deletions
  1. 2 2
      e2e-tests/basic.spec.ts
  2. 8 7
      e2e-tests/fixtures.ts
  3. 5 3
      src/main/frontend/handler/ui.cljs

+ 2 - 2
e2e-tests/basic.spec.ts

@@ -105,7 +105,6 @@ test('delete and backspace', async ({ page }) => {
   await createRandomPage(page)
 
   await page.fill('textarea >> nth=0', 'test')
-
   expect(await page.inputValue('textarea >> nth=0')).toBe('test')
 
   // backspace
@@ -114,7 +113,8 @@ test('delete and backspace', async ({ page }) => {
   expect(await page.inputValue('textarea >> nth=0')).toBe('te')
 
   // refill
-  await page.fill('textarea >> nth=0', 'test')
+  await enterNextBlock(page)
+  await page.type('textarea >> nth=0', 'test')
   await page.keyboard.press('ArrowLeft')
   await page.keyboard.press('ArrowLeft')
 

+ 8 - 7
e2e-tests/fixtures.ts

@@ -17,18 +17,19 @@ if (fs.existsSync(testTmpDir)) {
 
 export let graphDir = path.resolve(testTmpDir, "e2e-test", repoName)
 
-// NOTE: This is a console log watcher for error logs.
+// NOTE: This following is a console log watcher for error logs.
+// Save and print all logs when error happens.
+let logs: string
 const consoleLogWatcher = (msg: ConsoleMessage) => {
-    // console.log(msg.text())
-  let msgText = msg.text()
-  expect(msgText).not.toMatch(/^Failed to/)
+  // console.log(msg.text())
+  logs += msg.text() + '\n'
+    expect(msg.text(), logs).not.toMatch(/^(Failed to|Uncaught)/)
 
   // youtube video
-  if (!msgText.match(/^Error with Permissions-Policy header: Unrecognized feature/)) {
-    expect(msgText).not.toMatch(/^Error/)
+  if (!logs.match(/^Error with Permissions-Policy header: Unrecognized feature/)) {
+    expect(logs).not.toMatch(/^Error/)
   }
 
-  expect(msgText).not.toMatch(/^Uncaught/)
   // NOTE: React warnings will be logged as error.
   // expect(msg.type()).not.toBe('error')
 }

+ 5 - 3
src/main/frontend/handler/ui.cljs

@@ -232,9 +232,11 @@
   (let [[matched {:keys [on-chosen-open-link]}] (:rum/args state)
         current-idx (get state :frontend.ui/current-idx)]
     (util/stop e)
-    (when (and (seq matched)
-             (> (count matched)
-                @current-idx))
+    ;; FIXME: on-chosen-open-link might be nil
+    (when (and on-chosen-open-link
+               (seq matched)
+               (> (count matched)
+                  @current-idx))
       (on-chosen-open-link (nth matched @current-idx) false))))
 
 ;; date-picker