Skip to content

Latest commit

 

History

History
105 lines (78 loc) · 2.74 KB

README.md

File metadata and controls

105 lines (78 loc) · 2.74 KB

Sea Otter

Project Status: Pre-Alpha npm version License: MIT

Getting started

🌊 Dive into testing with SeaOtter

Step 1: Create a configuration object with details about your test environment. Here's an example:

  1. npm i -D seaotter
  2. Get the accompanying vscode extension for a superior experience (not yet published)
const config = {
  testDirectory: "/Absolute/Path/To/Test/Directory",
  fastFail: true,
  random: false,
  tests: ["asyncTest.js"],
};

Adjust the testDirectory to the absolute path of your test directory. Specify the tests you want to run in the tests array. Set fastFail to true for quicker test termination on the first failure, and toggle random to shuffle test execution order.

Step 2: Write a test

otter.explore`Create new User ${ MyTag }`(() => {
  otter.test`Login with valid credentials`(async () => {
    await simulateLogin("validUsername", "validPassword");
    await verifyOnHomePage();
  });

  test`Login with invalid credentials`(async () => {
    await simulateLogin(
      "invalidUsername",
      "invalidPassword"
    );

  const a = 10;
  const b = 20;
  const c = 5;
  
  expect`${a} toEqual ${a}`;
  expect`${a} toBeGreaterThan ${b}`;
  expect`${c} toBeLessThan ${a}`;
});

Step 3: Run your tests

import { otter } from "seaotter";
import config from "./config";

otter.wadeIn(config);

(async function () {
  await otter.dive();
})();

This method offers a straightforward way to run your tests.

Custom Test Execution using Generator (Alternative Approach)

If you prefer more control over the test execution process, you can have the otter cruise through a generator. This approach allows you to perform additional processing after each test and before the next one begins. The generator provides valuable metadata about each test so that you can customize your workflow!

(async function () {
  for await (const test of otter.cruise()) {
    // do something with metadata
  }
})();

If running the former way, and running tests in quiet mode you can listen for the failure events

   otter.on('testFailure', (error) => {
     doSomething(error)
   });

Using the CLI

You'll need to setup some env variables
npm i -g seaotter
export TEST_DIR="/absolute/path/to/test/dir"

# This is where your dive/cruise methods are used
export TEST_ENTRY="/absolute/path/to/entry"

otter <test(s)>