Skip to content

Latest commit

 

History

History
80 lines (65 loc) · 1.93 KB

state.md

File metadata and controls

80 lines (65 loc) · 1.93 KB

Metadata targets

  • Aggregated result (global metadata)
    • Test file run
  • Definitions:
    • describe blocks
    • beforeAll and afterAll hooks
    • beforeEach and afterEach hooks
    • it/test entries
  • Invocations:
    • describe blocks (when running)
      • beforeAll hook invocations
      • it/test invocations
        • beforeEach hook invocations
        • it/test function invocations
        • afterEach hook invocations
      • afterAll hook invocations

Example suite

const { metadata, $Set, $Push } = require('jest-metadata');

const $Description = (text) => $Set('vendor.description', text);
const $Maintainer = (name, email) => $Assign('vendor.maintainer', { name, email });
const $Tag = (value) => $Push(['vendor', 'labels'], value);
const $Flaky = () => $Tag('flaky');
const step = (text) => metadata.push('vendor.steps', [{ text, startedAt: now }]);

const actions = require('./actions');

$Maintainer('Jane Smith', '[email protected]');
$Description('This is a sample test suite.');
describe('Login flow', () => {
  $Description('Prepare the environment');
  beforeAll(() => {
    step('Open the browser');
    actions.openBrowser();
  });

  $Description('Visit the website');
  beforeEach(() => {
    step('Goto the URL: https://example.com');
    actions.goto('https://example.com');
  });

  $Description('Visit the website');
  afterEach(() => {
    step('Clear cookies');
    actions.clearCookies();
  });

  $Description('Tear down the environment');
  afterAll(() => {
    step('Close the browser');
    actions.closeBrowser();
  });

  $Tag('sanity');
  test('Unhappy scenario', () => {
    step('Enter invalid credentials');
    actions.sleep(100);
    step('Assert that the login failed');
  });

  $Flaky();
  $Tag('sanity');
  test('Happy scenario', () => {
    step('Enter valid credentials');
    actions.sleep(100);
    step('Assert that the login succeeded');
  });
});

Example diagram