To run tests for the Screenly/Chrome-Extension project, follow the detailed steps below:

Step 1: Set Up the Environment

Ensure that your development environment is ready with the required dependencies. If you are using Docker, you can build your environment using the following commands in the project’s root directory.

docker build -t screenly-chrome-extension .

This command prepares a Docker image that includes all the necessary dependencies for headless Chrome, as listed in the Dockerfile.

Step 2: Execute the Test Script

Using the provided script, run the tests. Navigate to the project root and execute:

./bin/run_tests.sh

Running this script performs the following actions:

  • Builds the extension in development mode.
  • Loads the extension as an unpacked extension from the dist folder.
  • Opens the test suite in Chrome via the following URL: chrome-extension://extension-id/test/tests.html. Replace extension-id with the actual ID of your loaded extension.

Step 3: Execute Tests Via Jasmine

The tests for the project are managed using Jasmine. The main test entry point is located in the src/test/spec/all.js file. This file imports the relevant test files you will want to execute. Here’s how it’s structured:

import './test-main';
import './test-popup';

To run the tests, you’ll need to access the HTML file created for testing:

  1. Open the Chrome browser.
  2. Navigate to the test page by entering the URL defined in the previous step.

Step 4: Understanding the Test Structure

The test implementation includes functions and test cases that evaluate different behaviors. Below is an example of a test case from src/test/spec/test-main.js:

describe("State.simplifyUrl", function() {
    const behaviours = [
        ['https://example.com', 'example.com'],
        ['https://www.example.com', 'example.com'],
        ['https://example.com/', 'example.com'],
        ['https://example.com//', 'example.com'],
        ['https://example.com/hello/', 'example.com/hello'],
        ['https://www.example.com/a?hat=1&cat=2', 'example.com/a?cat=2&hat=1'],
    ];

    for (const behaviour of behaviours) {
        let k, v;
        [k, v] = behaviour;

        it(`for ${k} returns ${v}`, () => {
            expect(State.simplifyUrl(k)).toBe(v);
        });
    }
});

In this example, the State.simplifyUrl function is tested across different URL inputs to ensure it returns the expected simplified URL.

Step 5: Reviewing Test Results

After all tests are executed, the results will be summarized in the Jasmine test runner interface. Here, you can inspect any failed test cases along with error messages to facilitate debugging.

By following these steps, you can effectively run and manage tests within the Screenly/Chrome-Extension project.

Source: README.md, src/test/spec/all.js, src/test/spec/test-main.js