Skip to content

duplication of code in test scripts #2896

Description

@dbauszus-glx

Many, perhaps all, test script files share the same scaffold.

import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import checkWorkspaceCache from '../../../mod/workspace/cache.js';

//Assigning console.error to a property to restore original function with.
const originalConsole = console.error;

//erros from test so we can assert on them and not get polute the console.
const mockErrors = [];

beforeAll(() => {
  //Changing the console.error function to push to our local collection of messages.
  console.error = (message) => {
    mockErrors.push(message);
  };
});

afterAll(() => {
  console.error = originalConsole;
});

It might be beneficially to define this once in a test scaffold script to be imported by each of the test scripts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TestingChanges relating to existing or new unit tests.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions