Ver Fonte

Add autorealod tests

simov há 7 anos atrás
pai
commit
a42326206e
2 ficheiros alterados com 71 adições e 0 exclusões
  1. 6 0
      test/index.js
  2. 65 0
      test/popup-options.js

+ 6 - 0
test/index.js

@@ -58,6 +58,7 @@ describe('markdown-viewer', () => {
     var content = await browser.newPage()
 
     await new Promise((resolve, reject) => {
+      var index = 0
       server = http.createServer()
       server.on('request', (req, res) => {
         // content-type
@@ -97,6 +98,11 @@ describe('markdown-viewer', () => {
             Array(500).fill('lorem ipsum').join(' '),
           ].join('\n\n'))
         }
+        else if (/autoreload/.test(req.url)) {
+          res.setHeader('Content-Type', 'text/markdown')
+          index += /preventCache/.test(req.url) ? 1 : 0
+          res.end(`# ${index}`)
+        }
         // csp
         else if (/csp-match-header/.test(req.url)) {
           res.setHeader('Content-Security-Policy',

+ 65 - 0
test/popup-options.js

@@ -522,4 +522,69 @@ module.exports = ({popup, advanced, content}) => {
     })
   })
 
+  describe('set content options - autoreload', () => {
+    before(async () => {
+      // popup
+      await popup.bringToFront()
+      // defaults button
+      await popup.click('button:nth-of-type(2)')
+      // content tab
+      await popup.click('.m-tabs a:nth-of-type(3)')
+
+      // go to test page
+      await content.goto('http://localhost:3000/autoreload')
+      await content.bringToFront()
+      await content.waitFor(200)
+
+      // enable autoreload
+      await content.bringToFront()
+      // autoreload switch
+      await popup.click('.m-panel:nth-of-type(3) .m-switch:nth-of-type(5)')
+      // content auto reloads
+      await content.waitFor(200)
+
+      // TODO: wait for https://github.com/GoogleChrome/puppeteer/pull/2812
+      // update autoreload interval
+      // await content.evaluate(() => state.ms = 250)
+    })
+
+    it('active tab', async () => {
+      t.equal(
+        await content.evaluate(() =>
+          parseInt(document.querySelector('h1').innerText.trim())
+        ),
+        0,
+        'first request'
+      )
+
+      // the initial interval is 1000
+      await content.waitFor(1500)
+
+      t.equal(
+        await content.evaluate(() =>
+          parseInt(document.querySelector('h1').innerText.trim())
+        ),
+        1,
+        'second request'
+      )
+    })
+
+    it('inactive tab', async () => {
+      // popup
+      await popup.bringToFront()
+
+      // the initial interval is 1000
+      await content.waitFor(1500)
+      await content.bringToFront()
+
+      t.equal(
+        await content.evaluate(() =>
+          parseInt(document.querySelector('h1').innerText.trim())
+        ),
+        2,
+        'third request'
+      )
+    })
+  })
+
 }