Convert Figma logo to code with AI

theintern logointern

A next-generation code testing stack for JavaScript.

4,361
309
4,361
138

Top Related Projects

46,847

Fast, easy and reliable testing for anything that runs in a browser.

88,205

JavaScript API for Chrome and Firefox

Next-gen browser and mobile automation test framework for Node.js

30,518

A browser automation framework and ecosystem.

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

44,166

Delightful JavaScript Testing.

Quick Overview

Intern is a powerful JavaScript testing framework designed for modern web applications. It provides a comprehensive suite of tools for unit testing, functional testing, and code coverage analysis, supporting both browser-based and Node.js environments.

Pros

  • Versatile testing capabilities, including unit, functional, and integration testing
  • Supports multiple testing environments (browsers, Node.js, mobile devices)
  • Built-in code coverage reporting
  • Integrates well with popular CI/CD tools

Cons

  • Steeper learning curve compared to some simpler testing frameworks
  • Documentation can be overwhelming for beginners
  • Setup process can be complex for advanced configurations
  • Limited community support compared to more popular testing frameworks

Code Examples

  1. Writing a simple unit test:
const { suite, test } = intern.getInterface('tdd');
const { expect } = intern.getPlugin('chai');

suite('Math operations', () => {
  test('addition', () => {
    expect(2 + 2).to.equal(4);
  });
});
  1. Creating a functional test for a web application:
const { suite, test } = intern.getInterface('tdd');

suite('Login functionality', () => {
  test('successful login', async ({ remote }) => {
    await remote
      .get('https://example.com/login')
      .findById('username')
      .type('testuser')
      .end()
      .findById('password')
      .type('password123')
      .end()
      .findById('submit')
      .click()
      .end()
      .findById('welcome-message')
      .getVisibleText()
      .then((text) => {
        assert.equal(text, 'Welcome, testuser!');
      });
  });
});
  1. Using async/await in tests:
const { suite, test } = intern.getInterface('tdd');
const { expect } = intern.getPlugin('chai');

suite('Async operations', () => {
  test('fetching data', async () => {
    const response = await fetch('https://api.example.com/data');
    const data = await response.json();
    expect(data).to.have.property('id');
  });
});

Getting Started

To get started with Intern, follow these steps:

  1. Install Intern in your project:

    npm install intern
    
  2. Create a configuration file intern.json in your project root:

    {
      "suites": ["tests/**/*.js"],
      "environments": ["node", "chrome"],
      "coverage": ["src/**/*.js"]
    }
    
  3. Write your tests in the tests directory.

  4. Run the tests using the Intern command:

    npx intern
    

For more detailed configuration and usage, refer to the official Intern documentation.

Competitor Comparisons

46,847

Fast, easy and reliable testing for anything that runs in a browser.

Pros of Cypress

  • More intuitive and user-friendly API, especially for beginners
  • Built-in time-travel debugging and automatic waiting
  • Extensive documentation and active community support

Cons of Cypress

  • Limited cross-browser support (primarily focused on Chrome)
  • Cannot test multiple browser tabs or windows
  • Slower test execution compared to Intern

Code Comparison

Cypress example:

describe('Login', () => {
  it('should log in successfully', () => {
    cy.visit('/login')
    cy.get('#username').type('user@example.com')
    cy.get('#password').type('password123')
    cy.get('button[type="submit"]').click()
    cy.url().should('include', '/dashboard')
  })
})

Intern example:

registerSuite('Login', {
  'should log in successfully'() {
    return this.remote
      .get('login')
      .findById('username').type('user@example.com').end()
      .findById('password').type('password123').end()
      .findByCssSelector('button[type="submit"]').click().end()
      .getCurrentUrl().then(url => {
        assert.include(url, '/dashboard')
      })
  }
})

Both Cypress and Intern are powerful testing frameworks, but they cater to different needs. Cypress offers a more modern and user-friendly approach, while Intern provides greater flexibility and cross-browser support. The choice between the two depends on specific project requirements and team preferences.

88,205

JavaScript API for Chrome and Firefox

Pros of Puppeteer

  • More powerful browser automation capabilities, including full control over Chrome/Chromium
  • Better suited for scraping and interacting with complex web applications
  • Larger community and more frequent updates

Cons of Puppeteer

  • Limited to Chrome/Chromium, while Intern supports multiple browsers
  • Steeper learning curve for those new to browser automation
  • Focused primarily on browser automation, whereas Intern is a more comprehensive testing framework

Code Comparison

Puppeteer example:

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'screenshot.png'});
await browser.close();

Intern example:

registerSuite('My Test', {
    'should load page': function () {
        return this.remote
            .get('https://example.com')
            .getPageTitle()
            .then(function (title) {
                assert.strictEqual(title, 'Example Domain');
            });
    }
});

Summary

Puppeteer excels in browser automation and scraping tasks, offering fine-grained control over Chrome/Chromium. It's well-suited for complex web interactions but has a steeper learning curve. Intern, on the other hand, provides a more comprehensive testing framework with support for multiple browsers, making it a better choice for cross-browser testing and simpler test scenarios. The choice between the two depends on the specific requirements of your project and the level of browser control needed.

Next-gen browser and mobile automation test framework for Node.js

Pros of WebdriverIO

  • More extensive and active community support
  • Broader range of integrations with testing frameworks and tools
  • Easier setup and configuration process

Cons of WebdriverIO

  • Steeper learning curve for beginners
  • Can be slower in execution compared to Intern
  • More complex syntax for certain operations

Code Comparison

Intern:

const { suite, test } = intern.getInterface('tdd');
const { assert } = intern.getPlugin('chai');

suite('My Test Suite', () => {
  test('My Test Case', () => {
    assert.strictEqual(2 + 2, 4);
  });
});

WebdriverIO:

describe('My Test Suite', () => {
  it('My Test Case', () => {
    browser.url('https://example.com');
    const title = browser.getTitle();
    expect(title).toBe('Example Domain');
  });
});

Both Intern and WebdriverIO are popular testing frameworks for JavaScript applications. Intern offers a more straightforward approach with a focus on simplicity, while WebdriverIO provides a more feature-rich environment with extensive plugin support. The choice between the two depends on project requirements, team expertise, and desired testing capabilities.

30,518

A browser automation framework and ecosystem.

Pros of Selenium

  • Wider adoption and larger community support
  • More extensive documentation and resources available
  • Supports a broader range of programming languages

Cons of Selenium

  • Can be slower and more resource-intensive
  • Setup and configuration can be more complex
  • Less integrated approach to testing (requires additional tools for certain functionalities)

Code Comparison

Selenium (Java):

WebDriver driver = new ChromeDriver();
driver.get("https://www.example.com");
WebElement element = driver.findElement(By.id("search"));
element.sendKeys("test");
element.submit();

Intern (JavaScript):

const { remote } = require('intern/lib/executors/Node');
return remote()
  .get('https://www.example.com')
  .findById('search')
  .type('test')
  .submit();

Summary

Selenium is a widely-used, multi-language testing framework with extensive support and documentation. It offers broad compatibility but can be more complex to set up and slower to execute. Intern, on the other hand, provides a more integrated JavaScript-focused testing solution with a simpler syntax and potentially faster execution. The choice between the two depends on project requirements, team expertise, and the specific testing needs of the application.

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

Pros of Playwright

  • Cross-browser support for Chromium, Firefox, and WebKit
  • Built-in auto-waiting and retry-ability for improved test stability
  • Powerful API for advanced scenarios like network interception and mocking

Cons of Playwright

  • Steeper learning curve due to more complex API
  • Larger package size and potentially slower installation
  • Limited to browser automation, not suitable for unit testing

Code Comparison

Playwright:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await browser.close();
})();

Intern:

define(['intern!object', 'intern/chai!assert'], function (registerSuite, assert) {
  registerSuite({
    name: 'example',
    'test': function () {
      return this.remote
        .get('https://example.com')
        .getPageTitle()
        .then(function (title) {
          assert.strictEqual(title, 'Example Domain');
        });
    }
  });
});

Summary

Playwright excels in browser automation with cross-browser support and advanced features, while Intern offers a more comprehensive testing solution including unit testing. Playwright's modern API and auto-waiting mechanisms can lead to more stable tests, but it comes with a steeper learning curve. Intern's modular approach and integration with various testing frameworks make it more versatile for different testing needs.

44,166

Delightful JavaScript Testing.

Pros of Jest

  • Simpler setup and configuration out of the box
  • Built-in code coverage reporting
  • Snapshot testing for easy UI component testing

Cons of Jest

  • Less flexible for complex testing scenarios
  • Limited browser testing capabilities
  • Slower test execution for large test suites

Code Comparison

Jest:

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

Intern:

registerSuite('Math', {
  'adding numbers': function () {
    assert.strictEqual(sum(1, 2), 3);
  }
});

Jest and Intern are both popular JavaScript testing frameworks, but they cater to different needs. Jest is known for its simplicity and ease of use, making it a favorite for React applications and smaller projects. It offers built-in mocking and code coverage, reducing the need for additional setup.

Intern, on the other hand, provides more flexibility and supports a wider range of testing scenarios. It excels in browser testing and can handle complex enterprise-level applications. Intern's modular architecture allows for more customization but may require more initial configuration.

While Jest's syntax is more straightforward, Intern's approach allows for more structured test organization. Jest's snapshot testing is a standout feature for UI component testing, while Intern's browser testing capabilities make it more suitable for comprehensive web application testing.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Intern

Software testing for humans

CI status codecov Average time to resolve an issue Percentage of issues still open FOSSA Status


Intern logo


Intern is a complete test system for JavaScript designed to help you write and run consistent, high-quality test cases for your JavaScript libraries and applications. It can be used to test any JavaScript code.

  • Plain JavaScript code, in any module format (or no module format!)
  • Web pages generated by server-side languages (like Java, PHP, or Ruby)
  • Native or hybrid iOS, Android, and Firefox OS applications
  • TypeScript code when running in Node, with no additional config

Intern is minimally prescriptive and enforces only a basic set of best practices designed to ensure your tests stay maintainable over time. Its extensible architecture allows you to write custom test interfaces, executors, and reporters to influence how your tests run & easily integrate with your existing coding environment. Intern also comes with Grunt tasks so it can be quickly added to existing Grunt-based workflows, and is designed to work out-of-the-box with popular continuous integration services like Jenkins and Travis CI.

If you’re into name-dropping, Intern gets used every day by teams at Twitter, Stripe, Mozilla, IBM, Marriott, Philips, Zenput, Alfresco, Esri, HSBC, ING, Intuit, and more. It’s also the testing framework of choice for growing numbers of open-source projects.

💡 If you’re an Intern user who’s new to Intern 4, see the Changes from Intern 3 document for a summary of the major differences. For Intern 3 documentation, please see the Intern 3 README.

💡 Recently updated your browser and your WebDriver tests stopped working? You may need to pin your WebDriver versions.

Quick start

  1. Install from npm

    $ cd /my/project
    $ npm install intern
    
  2. Create an intern.json file in your project root.

    {
      "suites": "tests/unit/**/*.js"
    }
    
  3. Verify that your configuration works by running Intern and checking that no errors are output.

    $ ./node_modules/.bin/intern
    
  4. Start writing tests!

TypeScript setup

Intern installs a global variable that tests may not be aware of if nothing imports the base intern package. To ensure Intern’s types are loaded, add the following to your tsconfig.json:

{
  "compilerOptions": {
    "types": ["intern"]
  }
}

Alternatively, add a triple-slash directive to the top of your suite files:

/// <reference types="intern" />

Compatibility

Intern can run unit tests in most browsers that support ECMAScript 5, including mobile browsers on Android and iOS, and in Node 6+. Note that Internet Explorer 9 is not supported.

Intern’s self-tests run against IE 10 and 11, Firefox 36 and current, Chrome 38 and current, and Safari 9 and 10, as well as the latest LTS and current versions of Node.

Intern can run functional tests using WebDriver-compatible applications and services, including Selenium, Appium, Selendroid. It has built-in support for cloud testing services from BrowserStack, CrossBrowserTesting, SauceLabs, and TestingBot.

More information

Get help

The best place to ask questions and get answers about Intern is Stack Overflow. Just tag your question with intern. If you have more immediate questions, or just want to chat with other people interested in Intern, join the Gitter room at theintern/intern. See the Help page for more information.

License

Intern is a JS Foundation project offered under the New BSD license.

FOSSA Status

© SitePen, Inc. and its contributors

Intern’s self-tests run on
BrowserStack logo

NPM DownloadsLast 30 Days