Skip to content

Instantly share code, notes, and snippets.

@ryparker
Last active July 28, 2020 05:10
Show Gist options
  • Save ryparker/d3f5cc58913ba7e89b5c34eeabc7bfd9 to your computer and use it in GitHub Desktop.
Save ryparker/d3f5cc58913ba7e89b5c34eeabc7bfd9 to your computer and use it in GitHub Desktop.
Create custom Jest Circus environments using this interface. Template repo available here: https://github.com/ryparker/jest-circus-environment-template
import NodeEnvironment from 'jest-environment-node';
import type { Config, Circus } from '@jest/types';
import type {EnvironmentContext} from '@jest/environment';
export default class CircusEnvironment extends NodeEnvironment {
testPath?: string;
docblockPragmas?: Record<string, string | string[]>;
constructor(config: Config.ProjectConfig, context: EnvironmentContext) {
super(config);
this.docblockPragmas = context?.docblockPragmas;
this.testPath = context?.testPath;
}
async setup() {
await super.setup();
}
async teardown() {
await super.teardown();
}
handleTestEvent(event: Circus.Event, state: Circus.State) {
console.log(`Event: ${event.name}`);
switch (event.name) {
case 'setup':
break;
case 'add_hook':
break;
case 'add_test':
break;
case 'run_start':
break;
case 'test_skip':
break;
case 'test_todo':
break;
case 'start_describe_definition':
break;
case 'finish_describe_definition':
break;
case 'run_describe_start':
break;
case 'test_start':
break;
case 'hook_start':
break;
case 'hook_success':
break;
case 'hook_failure':
break;
case 'test_fn_start':
break;
case 'test_fn_success':
break;
case 'test_fn_failure':
break;
case 'test_done':
break;
case 'run_describe_finish':
break;
case 'run_finish':
break;
case 'teardown':
break;
case 'error':
break;
default:
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment