browser-test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const fs = require('fs');
  2. const path = require('path');
  3. const puppeteer = require('puppeteer');
  4. const chai = require('chai');
  5. const mustache = fs.readFileSync(path.join(__dirname, '../../mustache.js'), 'utf8');
  6. describe('Browser usage', () => {
  7. let browser;
  8. let page;
  9. before(async function () {
  10. this.timeout(10 * 1000);
  11. // Awkward .launch() options below are needed to avoid hitting timeouts
  12. // when tests are run in GitHub Actions for some weird reason
  13. // https://github.com/GoogleChrome/puppeteer/issues/4617
  14. browser = await puppeteer.launch({ignoreDefaultArgs: ['--disable-extensions']});
  15. page = await browser.newPage();
  16. page.on('console', msg => console.log('PAGE LOG:', msg.text()));
  17. page.on('pageerror', err => console.error('PAGE ERROR:', err));
  18. });
  19. after(() => browser.close());
  20. it('is exposed on the global scope as window.Mustache', async () => {
  21. await page.goto(`file://${path.join(__dirname, '_fixtures/global-scope.html')}`);
  22. const bodyElement = await page.$('body');
  23. const textContentProperty = await bodyElement.getProperty('textContent');
  24. const value = await textContentProperty.jsonValue();
  25. chai.assert.equal(value.trim(), 'Joe spends 6');
  26. });
  27. it('is exposed as AMD and consumable via RequireJS', async function () {
  28. this.timeout(10 * 1000);
  29. await page.goto(`file://${path.join(__dirname, '_fixtures/amd.html')}`, { waitUntil: 'networkidle0' });
  30. const bodyElement = await page.$('body');
  31. const textContentProperty = await bodyElement.getProperty('textContent');
  32. const value = await textContentProperty.jsonValue();
  33. chai.assert.equal(value, 'Joe spends 6');
  34. });
  35. });