Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Nov 25, 2023
1 parent 7d6930a commit bc73ef4
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 361 deletions.
5 changes: 0 additions & 5 deletions e2e/reporters/recorder.ts → e2e/reporters/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ class E2eRecorderReporter extends JestMetadataReporter {
await debugUtils.aggregateLogs();
}
}

static onTestEnvironmentCreate(env) {
console.log('I AM ALIVE');
console.log(' ..--..');
}
}

function sleep(ms) {
Expand Down
2 changes: 1 addition & 1 deletion environment-decorator.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* Jest 27 fallback */
module.exports = require('./dist/environment-listener');
module.exports = require('./dist/environment-decorator');
2 changes: 2 additions & 0 deletions environment-listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Jest 27 fallback */
module.exports = require('./dist/environment-listener');
3 changes: 1 addition & 2 deletions src/environment-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { JestMetadataError } from './errors';
import { detectDuplicateRealms, injectRealmIntoSandbox, realm } from './realms';
import { jestUtils, logger } from './utils';

const log = logger.child({ cat: 'environment', tid: 'environment' });

const listener: EnvironmentListenerFn = (context) => {
const log = logger.child({ cat: 'environment', tid: 'environment' });
const jestEnvironment = context.env;
const jestEnvironmentConfig = context.config;
const environmentContext = context.context;
Expand Down
6 changes: 3 additions & 3 deletions src/jest-reporter/__tests__/fallback-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
MetadataFactoryImpl,
WriteMetadataEventEmitter,
} from '../../metadata';
import { SerialSyncEmitter } from '../../utils';
import { SerialEmitter } from '../../utils';
import { AssociateMetadata } from '../AssociateMetadata';
import { FallbackAPI } from '../FallbackAPI';
import { QueryMetadata } from '../QueryMetadata';
Expand All @@ -23,10 +23,10 @@ describe('Fallback API', () => {
const IPCServer = jest.requireMock('../../ipc').IPCServer;
const ipc: jest.Mocked<IPCServer> = new IPCServer();

const emitter = new SerialSyncEmitter<MetadataEvent>('core').on('*', (event: MetadataEvent) => {
const emitter = new SerialEmitter<MetadataEvent>('core').on('*', (event: MetadataEvent) => {
metadataHandler.handle(event);
}) as MetadataEventEmitter;
const setEmitter = new SerialSyncEmitter('set') as WriteMetadataEventEmitter;
const setEmitter = new SerialEmitter('set') as WriteMetadataEventEmitter;
const metadataRegistry = new GlobalMetadataRegistry();
const metadataFactory = new MetadataFactoryImpl(metadataRegistry, setEmitter);
const globalMetadata = metadataFactory.createGlobalMetadata();
Expand Down
4 changes: 2 additions & 2 deletions src/metadata/__tests__/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fixtures from '../../../e2e';

import { SerialSyncEmitter } from '../../utils';
import { SerialEmitter } from '../../utils';
import { PlantSerializer } from '../__utils__';
import {
GlobalMetadataRegistry,
Expand All @@ -13,7 +13,7 @@ describe('metadata - integration test:', () => {
test.each(Object.values(fixtures.metadata))(
`e2e/__fixtures__/%s`,
(_name: string, fixture: any[]) => {
const emitter: WriteMetadataEventEmitter = new SerialSyncEmitter('set');
const emitter: WriteMetadataEventEmitter = new SerialEmitter('set');
const metadataRegistry = new GlobalMetadataRegistry();
const metadataFactory = new MetadataFactoryImpl(metadataRegistry, emitter);
const globalMetadata = metadataFactory.createGlobalMetadata();
Expand Down
4 changes: 2 additions & 2 deletions src/metadata/__tests__/run-traversal.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fixtures from '../../../e2e';

import { SerialSyncEmitter } from '../../utils';
import { SerialEmitter } from '../../utils';
import {
GlobalMetadataRegistry,
Metadata,
Expand All @@ -15,7 +15,7 @@ describe('file metadata traversal:', () => {
});

test.each(lastFixtures)(`fixtures/%s`, (_name: string, fixture: any[]) => {
const emitter: WriteMetadataEventEmitter = new SerialSyncEmitter('set');
const emitter: WriteMetadataEventEmitter = new SerialEmitter('set');
const metadataRegistry = new GlobalMetadataRegistry();
const metadataFactory = new MetadataFactoryImpl(metadataRegistry, emitter);
const globalMetadata = metadataFactory.createGlobalMetadata();
Expand Down
8 changes: 3 additions & 5 deletions src/realms/BaseRealm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ import {
WriteMetadataEventEmitter,
} from '../metadata';

import { AggregatedEmitter, SerialSyncEmitter } from '../utils';
import { AggregatedEmitter, SerialEmitter } from '../utils';

export abstract class BaseRealm {
readonly coreEmitter = new SerialSyncEmitter<MetadataEvent>('core').on(
readonly coreEmitter = new SerialEmitter<MetadataEvent>('core').on(
'*',
(event: MetadataEvent) => {
this.metadataHandler.handle(event);
},
) as MetadataEventEmitter;
readonly setEmitter = new SerialSyncEmitter<WriteMetadataEvent>(
'set',
) as WriteMetadataEventEmitter;
readonly setEmitter = new SerialEmitter<WriteMetadataEvent>('set') as WriteMetadataEventEmitter;
readonly events = new AggregatedEmitter<MetadataEvent>('events').add(this.coreEmitter);

readonly metadataRegistry = new GlobalMetadataRegistry();
Expand Down
12 changes: 6 additions & 6 deletions src/utils/emitters/AggregatedEmitter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AggregatedEmitter } from './AggregatedEmitter';
import { SerialSyncEmitter } from './SerialSyncEmitter';
import { SerialEmitter } from './SerialEmitter';

describe('AggregatedEmitter', () => {
let emitter: AggregatedEmitter<{ type: string }>;
Expand All @@ -9,8 +9,8 @@ describe('AggregatedEmitter', () => {
});

test('should re-emit events of added #emitters', () => {
const dummy1 = new SerialSyncEmitter('dummy1');
const dummy2 = new SerialSyncEmitter('dummy2');
const dummy1 = new SerialEmitter('dummy1');
const dummy2 = new SerialEmitter('dummy2');
const listener = jest.fn();
const event1 = { type: 'test', id: 1 };
const event2 = { type: 'test', id: 2 };
Expand All @@ -26,8 +26,8 @@ describe('AggregatedEmitter', () => {
});

test('should allow subscribing to events only once', () => {
const dummy1 = new SerialSyncEmitter('dummy1');
const dummy2 = new SerialSyncEmitter('dummy2');
const dummy1 = new SerialEmitter('dummy1');
const dummy2 = new SerialEmitter('dummy2');
const listener = jest.fn();
const event1 = { type: 'test', id: 1 };
const event2 = { type: 'test', id: 2 };
Expand All @@ -42,7 +42,7 @@ describe('AggregatedEmitter', () => {
});

test('should allow unsubscribing from events', () => {
const dummy = new SerialSyncEmitter('dummy1');
const dummy = new SerialEmitter('dummy1');
const listener = jest.fn();
const event = { type: 'test', id: 1 };

Expand Down
6 changes: 3 additions & 3 deletions src/utils/emitters/AggregatedEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Emitter, ReadonlyEmitter } from '../../types';
import { SerialSyncEmitter } from './SerialSyncEmitter';
import { SerialEmitter } from './SerialEmitter';

export class AggregatedEmitter<Event extends { type: string }> implements ReadonlyEmitter<Event> {
readonly #emitters = new WeakSet<Emitter<Event>>();
readonly #rootEmitter: SerialSyncEmitter<Event>;
readonly #rootEmitter: SerialEmitter<Event>;

constructor(name: string) {
this.#rootEmitter = new SerialSyncEmitter<Event>(name);
this.#rootEmitter = new SerialEmitter<Event>(name);
}

add(emitter: Emitter<Event>): this {
Expand Down
94 changes: 0 additions & 94 deletions src/utils/emitters/ReadonlyEmitterBase.ts

This file was deleted.

62 changes: 0 additions & 62 deletions src/utils/emitters/SemiAsyncEmitter.ts

This file was deleted.

32 changes: 0 additions & 32 deletions src/utils/emitters/SerialAsyncEmitter.ts

This file was deleted.

Loading

0 comments on commit bc73ef4

Please sign in to comment.