Exemplo n.º 1
0
export async function open(name: string, browser: Browser, code: string, id: string = '#test'): Promise<Page> {
  const page = await browser.newPage()

  const content = `
  <!doctype html>
  <html>
    <head>
      <title>${name}</title>
    </head>
    <body>
      <div id="app"></div>
      <script>
      ${encode(await VUE_SOURCE)}
      </script>
      <script>
      ${encode(await code)}
      </script>
    </body>
  </html>`

  // Un-comment following lines to debug generated HTML.
  if (!Boolean(process.env.CI)) {
    const dir = path.join(__dirname, '../output')

    if (!await promised(fs).exists(dir)) await promised(fs).mkdir(dir)
    await promised(fs).writeFile(path.join(dir, name + '.html'), content)
  }

  await page.setContent(content)

  await page.waitFor(id)

  return page
}
Exemplo n.º 2
0
    outputCode += `\n;(function() { 
      var s = document.createElement('style'); 
      s.type = 'text/css'; 
      document.head.appendChild(s);
      s.appendChild(document.createTextNode(${JSON.stringify(style)}))
    })()` 
  }

  outputCode += `\n\n//# sourceMappingURL=data:application/json;base64,${new Buffer(JSON.stringify(output.map)).toString('base64')}\n`

  cache[cacheKey] = outputCode

  return outputCode
}

const VUE_SOURCE = promised(fs).readFile(
  path.resolve(__dirname, '../../node_modules/vue/dist/vue.min.js')
)

function encode(any: any) {
  return any.toString().replace(/<\//g, '&lt;\/')
}

export async function open(name: string, browser: Browser, code: string, id: string = '#test'): Promise<Page> {
  const page = await browser.newPage()

  const content = `
  <!doctype html>
  <html>
    <head>
      <title>${name}</title>