{"id":14644,"library":"jquery-test-runner","title":"jQuery Test Runner","description":"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.","status":"active","version":"0.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/jquery/jquery-test-runner","tags":["javascript","jquery-test-runner","jtr","jtr-serve","jquery","test","qunit","selenium","browserstack"],"install":[{"cmd":"npm install jquery-test-runner","lang":"bash","label":"npm"},{"cmd":"yarn add jquery-test-runner","lang":"bash","label":"yarn"},{"cmd":"pnpm add jquery-test-runner","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core for browser automation via Selenium WebDriver.","package":"selenium-webdriver","optional":false},{"reason":"Used for local testing with BrowserStack services.","package":"browserstack-local","optional":true},{"reason":"The specific JavaScript testing framework it is designed to run.","package":"qunit","optional":false}],"imports":[{"note":"This refers to an internal command runner function, not typically imported by end-users. Primary interaction is via the `jtr run` CLI command.","wrong":"const { run } = require('jquery-test-runner');","symbol":"run","correct":"import { run } from 'jquery-test-runner/lib/commands/run';"},{"note":"An internal function for setting up the test server, exposed for advanced tooling or internal testing, not a standard user import. The fix for `.js` MIME type was related to this.","wrong":"import createTestServer from 'jquery-test-runner/lib/server';","symbol":"createTestServer","correct":"import { createTestServer } from 'jquery-test-runner/lib/server';"},{"note":"Represents the core test runner class, likely used internally or for highly customized programmatic execution within specific build systems, not typical for direct application use.","wrong":"const TestRunner = require('jquery-test-runner').TestRunner;","symbol":"TestRunner","correct":"import { TestRunner } from 'jquery-test-runner/lib/testrunner';"}],"quickstart":{"code":"const { spawn } = require('child_process');\nconst path = require('path');\nconst fs = require('fs');\n\n// Create a dummy QUnit test file for demonstration\nconst testFilePath = path.join(__dirname, 'tests', 'example.js');\nconst testHtmlPath = path.join(__dirname, 'tests', 'index.html');\n\nfs.mkdirSync(path.dirname(testFilePath), { recursive: true });\nfs.writeFileSync(testFilePath, `\nQUnit.module('My Example Module');\nQUnit.test('should assert true', function(assert) {\n  assert.ok(true, 'true is truthy');\n});\n`);\nfs.writeFileSync(testHtmlPath, `\n<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"utf-8\">\n  <title>QUnit Example</title>\n  <link rel=\"stylesheet\" href=\"https://code.jquery.com/qunit/qunit-2.20.0.css\">\n</head>\n<body>\n  <div id=\"qunit\"></div>\n  <div id=\"qunit-fixture\"></div>\n  <script src=\"https://code.jquery.com/qunit/qunit-2.20.0.js\"></script>\n  <script src=\"example.js\"></script>\n</body>\n</html>\n`);\n\nconsole.log('Starting jQuery Test Runner...');\n\n// IMPORTANT: Ensure you have a ChromeDriver installed and in your PATH,\n// or specify BrowserStack credentials (e.g., via environment variables).\n// Example for BrowserStack:\n// process.env.BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME ?? '';\n// process.env.BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY ?? '';\n\nconst jtrProcess = spawn('jtr', [\n  'run',\n  '--url', 'http://localhost:8000/tests/index.html', // URL to your test HTML file\n  '--browser', 'chrome', // Specify the browser to use (e.g., 'chrome', 'firefox', 'safari', 'ie')\n  '--reporters', 'console',\n  '--test-timeout', '30000', // Max time for a test to complete\n  '--serve', '8000', // Serve local files from the current directory on port 8000\n  '--cwd', __dirname // Set current working directory for file serving\n], { stdio: 'inherit' });\n\njtrProcess.on('close', (code) => {\n  if (code === 0) {\n    console.log('jQuery Test Runner completed successfully.');\n  } else {\n    console.error(`jQuery Test Runner exited with code ${code}.`);\n    process.exit(1);\n  }\n  // Clean up dummy files\n  fs.rmSync(path.join(__dirname, 'tests'), { recursive: true, force: true });\n});\n","lang":"javascript","description":"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."},"warnings":[{"fix":"Update calls from `sendTo( console )` to `forwardTo( console )`.","message":"The `sendTo( console )` method for forwarding console messages in JSDOM environments has been renamed to `forwardTo`. Code relying on the old method will fail.","severity":"breaking","affected_versions":">=0.2.8"},{"fix":"Ensure WebDriver executables are in your system PATH or correctly configured. Verify BrowserStack `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` environment variables are set correctly.","message":"Running tests in real browsers via Selenium requires appropriate WebDriver installations (e.g., Chromedriver, Geckodriver) or active cloud service configurations (BrowserStack credentials). Misconfigured drivers or credentials will prevent tests from running.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"Upgrade `jquery-test-runner` to version `0.2.4` or newer to include global QUnit errors in the reporter output.","message":"Older versions might not fully report QUnit global errors. Ensure `jquery-test-runner` is updated for comprehensive reporting.","severity":"gotcha","affected_versions":"<0.2.4"},{"fix":"Upgrade `jquery-test-runner` to version `0.3.0` or newer to enable support for Safari Technology Preview.","message":"Safari Technology Preview support was added in version 0.3.0. If you require testing in STP, you must be on this version or higher.","severity":"gotcha","affected_versions":"<0.3.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Update ChromeDriver to match your Chrome browser version, or update Chrome.","cause":"Incompatibility between your installed Chrome browser version and the ChromeDriver version used by Selenium.","error":"WebDriverError: session not created: This version of ChromeDriver only supports Chrome version XX"},{"fix":"Start your Selenium WebDriver server or ensure `selenium.host` and `selenium.port` in your configuration are correct.","cause":"Selenium server (WebDriver hub) is not running or is not accessible at the specified address and port.","error":"Error: connect ECONNREFUSED 127.0.0.1:4444"},{"fix":"Verify network connectivity, check firewall rules, and ensure BrowserStack Local is correctly installed and configured. Try running `BrowserStackLocal.exe` manually to debug.","cause":"BrowserStack Local daemon failed to start or connect, often due to network issues, firewall, or incorrect local setup.","error":"Error: Could not connect to BrowserStack Local. Please check your network or proxy settings."},{"fix":"Upgrade to `jquery-test-runner` version `0.3.0` or newer, which includes a fix for the `.js` MIME type.","cause":"Incorrect MIME type served for JavaScript files, preventing browser from executing scripts, particularly in older browsers or strict environments.","error":"MIME type ('text/plain') is not a supported stylesheet MIME type, and stylesheet will be ignored."}],"ecosystem":"npm"}