Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use chrome instead of PhantomJS #31

Open
FagnerMartinsBrack opened this issue May 21, 2016 · 8 comments
Open

Use chrome instead of PhantomJS #31

FagnerMartinsBrack opened this issue May 21, 2016 · 8 comments

Comments

@FagnerMartinsBrack
Copy link

Hi, I am a maintainer of impress.js and I was looking for a way to run the 3D transform integration tests in Google Chrome. The problem is that gulp-qunit uses PhantomJS and it doesn't have support for 3D transform, see here for what I have tried so far.

Is there any chances this plugin can use Chrome instead of PhantomJS, assuming that Chrome has a proper 3D transform support? Is anyone aware of anything that blocks it from being done in this project?

Ping @jonkemp

@jonkemp
Copy link
Owner

jonkemp commented May 23, 2016

I'm interested in how this will work.

@FagnerMartinsBrack
Copy link
Author

@jonkemp

Would that make sense for this project though? The project's description is "Run QUnit unit tests in a headless PhantomJS instance.".

@jonkemp
Copy link
Owner

jonkemp commented May 23, 2016

I see your point. It is pretty tightly coupled with PhantomJS. I think if it could be spawned the same way as a child process like PhantomJS is, maybe you could have an option to use Chrome.

@hun1ahpu
Copy link

Maybe should be easier now that chrome has headless mode (behind the flag so far): https://www.chromestatus.com/features/5678767817097216

@backflip
Copy link

A basic example:

const puppeteer = require('puppeteer');
const DataURI = require('datauri');
const chalk = require('chalk');

const datauri = new DataURI();

// Create data URI of basic HTML page
// It contains a title element where we change the content via JS
datauri.format('.html', `<!doctype html>
<html>
  <head>
    <title>Test</title>
    <meta charset="utf-8"> 
  </head>
  <body>
    <h1>Original title</h1>

    <script>
      document.querySelector('h1').innerText = 'New title';
    </script>
  </body>
</html>`);

puppeteer.launch().then(async browser => {
  const page = await browser.newPage();
  await page.goto(datauri.content);

  // Load QUnit script
  await page.addScriptTag({
    url: 'https://cdnjs.cloudflare.com/ajax/libs/qunit/2.4.1/qunit.min.js'
  });

  // Run tests and return results
  const results = await page.evaluate(() => new Promise(function (resolve, reject) {
    var details = [];

    QUnit.test('Title text', (assert) => {
      assert.ok(document.querySelector('h1').innerText === 'New title', 'Title text equals "New title"');
    });

    QUnit.testDone((result) => details.push(result));

    QUnit.done((summary) => {
      resolve({
        details: details,
        summary: summary
      });
    });
  }));

  // Very basic reporter
  results.details.forEach((test) => {
    if (test.failed === 0) {
      console.log(chalk.green(`✓ ${test.name}`));
    } else {
      console.log(chalk.red(${test.name}`));

      test.assertions.filter(function(assertion) {
        return !assertion.result;
      }).forEach(function(assertion) {
        console.log(chalk.red(`Failing assertion: ${assertion.message}`));
      });
    }
  });

  await browser.close();
});

@jonkemp
Copy link
Owner

jonkemp commented Nov 27, 2017

@backflip example of what?

@backflip
Copy link

Sorry, good point. :) I was referring to your message from above:

I'm interested in how this will work.

Just in case you wondered what running QUnit tests in Puppeteer might look like.

@Krinkle
Copy link

Krinkle commented Nov 23, 2020

There now exists a node-qunit-puppeteer package, which the grunt-contrib-qunit package has since switched over to. Perhaps gulp-qunit could use this as well?

Bumping this because I have proposed to deprecate support for PhantomJS for the next release of QUnit, to drop sometime next year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants