Skip to content

Extend `benchmarkSuite to support factory functions to create a shared function scope #302

@LayZeeDK

Description

@LayZeeDK

Extend our existing benchmarkSuite API to support factory functions in 2 places as an alternative to module-scoped variables and to support a variable scope for each benchmark function and its hooks.

  1. benchmarkSuite should support a factory as second parameter
benchmarkSuite('Suite', () => {
  // Shared scope for all benchmarks
  let projectDirectory: string;
  
  return {
    benchmarks: {
      'Test': {
        fn: () => { /* uses projectDirectory */ },
        beforeAll: () => { projectDirectory = createProject(); }
      }
    },
    setupSuite: () => { /* setup */ },
    teardownSuite: () => { /* can access projectDirectory */ }
  };
});
  1. Each benchmarks value should accept a factory function
benchmarkSuite('Suite',
{ // bencmarks
      'Test': () => {
        let projectDirectory: string;

      return {
          fn: () => { /* uses projectDirectory */ },
          beforeAll: () => { projectDirectory = createProject(); }
        }
      };
    }
  };
});

But also:

benchmarkSuite('Suite',
{ // bencmarks
      'Test': () => {
        let projectDirectory: string;

        return () => { /* uses projectDirectory */ };
      };
    }
  };
});

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions