'use strict'

const puppeteer = require('puppeteer')

const expect = require('chai').expect
const fs = require('fs')

describe('BroccoliLivereload', () => {
    let browser = null
    let page = null
    before(() => {
        fs.writeFileSync('test/fixtures/app/test.html', fs.readFileSync('test/fixtures/index-hi.html'));
    })
    before(function () {
        this.timeout(10000);
        return puppeteer.launch().then((b) => {
            browser = b
            return browser.newPage()
        }).then((p) => {
            page = p
        })
    })
    after(() => {
        fs.writeFileSync('test/fixtures/test.html', fs.readFileSync('test/fixtures/index-hi.html'));
        return browser.close()
    })

    it('should notify the browser of updates', () => {
        return page.goto('http://localhost:4200/test.html')
            .then(() => {
                return page.evaluate(() => {
                    return document.querySelector("h1").textContent;
                })
            }).then((text) => {
                expect(text).to.equal('Hi!')
            })
            .then(() => {
                fs.writeFileSync('test/fixtures/app/test.html', fs.readFileSync('test/fixtures/index-hello.html'));
                return new Promise((resolve) => setTimeout(resolve, 500)) // wait because we debounce changes
            })
                return page.evaluate(() => {
                    return document.querySelector("h1").textContent;
                })
            }).then((text) => {
                expect(text).to.equal('Hello!')
            })
    })
})
@@ -352,51 +352,15 @@
 ore(
-function () %7B%0D%0A        this.timeout(10000);
+() =%3E %7B
 %0D%0A  
@@ -389,16 +389,34 @@
 .launch(
+%7B headless: true %7D
 ).then((
@@ -665,33 +665,32 @@
 index-hi.html'))
-;
 %0D%0A        return
@@ -1355,32 +1355,59 @@
             %7D)%0D%0A
+            .then(() =%3E %7B%0D%0A
                 

remove timeout definitions