UNPKG

@dynatrace/runtime-simulator

Version:

The Dynatrace JavaScript runtime simulator.

46 lines (45 loc) 1.66 kB
/// <reference path="../../src/vm.d.ts" /> /// <reference types="node" /> /// <reference types="node/vm" /> /** * @license * Copyright 2024 Dynatrace LLC * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type { JestEnvironment } from '@jest/environment'; import { LegacyFakeTimers, ModernFakeTimers } from '@jest/fake-timers'; import type { Config, Global } from '@jest/types'; import { ModuleMocker } from 'jest-mock'; import * as vm from 'vm'; export type Timer = { id: number; ref: () => Timer; unref: () => Timer; }; /** Jest runtime simulator environment */ export default class RuntimeSimulatorEnvironment implements JestEnvironment { private readonly config; private context; fakeTimers: LegacyFakeTimers<Timer> | null; fakeTimersModern: ModernFakeTimers | null; global: Global.Global; moduleMocker: ModuleMocker | null; /** Create a new test environment for the runtime simulator */ constructor(config: Config.ProjectConfig); /** @inheritDoc */ setup(): Promise<void>; /** @inheritDoc */ teardown(): Promise<void>; /** @inheritDoc */ getVmContext(): vm.Context | null; }