jQuery Test Runner

0.3.0 · active · verified Sun Apr 19

The jQuery Test Runner (jtr) is a specialized command-line interface (CLI) tool developed by the jQuery team to execute QUnit test suites across real browsers. It leverages Selenium for browser automation and integrates with BrowserStack for running tests in cloud-based environments. Currently at version 0.3.0, the project shows an active development cadence, with frequent minor releases and bug fixes addressing issues like Selenium driver compatibility (e.g., Safari Technology Preview, IE), console forwarding in JSDOM, and reporting improvements. Its key differentiator is its focus on reliable, real-browser QUnit testing, particularly useful for projects requiring broad browser compatibility testing without relying solely on headless environments.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to run QUnit tests using `jquery-test-runner` via its command-line interface, serving local files and specifying a browser. It outlines basic setup for testing with Chrome, assuming ChromeDriver is available or BrowserStack is configured.

const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');

// Create a dummy QUnit test file for demonstration
const testFilePath = path.join(__dirname, 'tests', 'example.js');
const testHtmlPath = path.join(__dirname, 'tests', 'index.html');

fs.mkdirSync(path.dirname(testFilePath), { recursive: true });
fs.writeFileSync(testFilePath, `
QUnit.module('My Example Module');
QUnit.test('should assert true', function(assert) {
  assert.ok(true, 'true is truthy');
});
`);
fs.writeFileSync(testHtmlPath, `
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>QUnit Example</title>
  <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.20.0.css">
</head>
<body>
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>
  <script src="https://code.jquery.com/qunit/qunit-2.20.0.js"></script>
  <script src="example.js"></script>
</body>
</html>
`);

console.log('Starting jQuery Test Runner...');

// IMPORTANT: Ensure you have a ChromeDriver installed and in your PATH,
// or specify BrowserStack credentials (e.g., via environment variables).
// Example for BrowserStack:
// process.env.BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME ?? '';
// process.env.BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY ?? '';

const jtrProcess = spawn('jtr', [
  'run',
  '--url', 'http://localhost:8000/tests/index.html', // URL to your test HTML file
  '--browser', 'chrome', // Specify the browser to use (e.g., 'chrome', 'firefox', 'safari', 'ie')
  '--reporters', 'console',
  '--test-timeout', '30000', // Max time for a test to complete
  '--serve', '8000', // Serve local files from the current directory on port 8000
  '--cwd', __dirname // Set current working directory for file serving
], { stdio: 'inherit' });

jtrProcess.on('close', (code) => {
  if (code === 0) {
    console.log('jQuery Test Runner completed successfully.');
  } else {
    console.error(`jQuery Test Runner exited with code ${code}.`);
    process.exit(1);
  }
  // Clean up dummy files
  fs.rmSync(path.join(__dirname, 'tests'), { recursive: true, force: true });
});

view raw JSON →