Skip to content

Commit

Permalink
use constructor signature declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
vid committed Jan 17, 2025
1 parent 18efdee commit 264c25e
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 226 deletions.
4 changes: 1 addition & 3 deletions modules/core/src/lib/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { TTag, WorkspaceBuilder } from './defs.js';

export class Context {
values: { [name: string]: any };
context: string;

constructor(context: string, initial?: { [name: string]: string }) {
this.context = context;
constructor(private context: string, initial?: { [name: string]: string }) {
this.values = initial || {};
}

Expand Down
184 changes: 104 additions & 80 deletions modules/core/src/phases/collector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,118 @@ import { TFileSystem } from '../lib/util/workspace-lib.js';
import { getFeaturesAndBackgrounds, shouldProcess } from './collector.js';

class MockFS {
files: object;
constructor(files: object) {
this.files = files;
}
constructor(private files: object) {}

existsSync(where: string) {
return !!this.files[where]
}
readFileSync(where: string) {
const e = where.split('/');
const h = e.slice(0, 3).join('/');
return this.files[h][e[3]];
}
statSync(where: string) {
return { isDirectory: () => !!this.files[where] }
}
readdirSync(where: string): string[] {
return Object.keys(this.files[where] || {});
}
existsSync(where: string) {
return !!this.files[where];
}
readFileSync(where: string) {
const e = where.split('/');
const h = e.slice(0, 3).join('/');
return this.files[h][e[3]];
}
statSync(where: string) {
return { isDirectory: () => !!this.files[where] };
}
readdirSync(where: string): string[] {
return Object.keys(this.files[where] || {});
}
}

const nfs = (files: object) => <TFileSystem>(new MockFS(files) as unknown);

describe('getFeaturesAndBackgrounds', () => {
it('directory does not exist', async () => {
expect(() => getFeaturesAndBackgrounds(['/'], [], { existsSync: () => false })).toThrow();
});
it('no features or backgrounds', async () => {
expect(() => getFeaturesAndBackgrounds(['/'], [], { existsSync: () => true })).toThrow();
});
it('no features', async () => {
expect(() => getFeaturesAndBackgrounds(['/0'], [], nfs({ '/0/backgrounds': { 'a.feature': '#' } }))).toThrow();
});
it('gets features', async () => {
expect(getFeaturesAndBackgrounds(['/0'], [], nfs({ '/0/features': { 'a.feature': '#' } }))).toEqual({ features: [{ base: '/0', path: '/features/a.feature', name: '/0/features/a', type: 'feature', content: '#' }], backgrounds: [] });
});
it('gets features and backgrounds', async () => {
const res = getFeaturesAndBackgrounds(['/0'], [], nfs({ '/0/features': { 'a.feature': '#' }, '/0/backgrounds': { 'b.feature': '#' } }));
expect(res).toEqual({
features: [{ base: '/0', path: '/features/a.feature', name: '/0/features/a', type: 'feature', content: '#' }]
, backgrounds: [{ base: '/0', path: '/backgrounds/b.feature', name: '/0/backgrounds/b', type: 'feature', content: '#' }]
});
});
it('directory does not exist', async () => {
expect(() => getFeaturesAndBackgrounds(['/'], [], { existsSync: () => false })).toThrow();
});
it('no features or backgrounds', async () => {
expect(() => getFeaturesAndBackgrounds(['/'], [], { existsSync: () => true })).toThrow();
});
it('no features', async () => {
expect(() => getFeaturesAndBackgrounds(['/0'], [], nfs({ '/0/backgrounds': { 'a.feature': '#' } }))).toThrow();
});
it('gets features', async () => {
expect(getFeaturesAndBackgrounds(['/0'], [], nfs({ '/0/features': { 'a.feature': '#' } }))).toEqual({
features: [{ base: '/0', path: '/features/a.feature', name: '/0/features/a', type: 'feature', content: '#' }],
backgrounds: [],
});
});
it('gets features and backgrounds', async () => {
const res = getFeaturesAndBackgrounds(
['/0'],
[],
nfs({ '/0/features': { 'a.feature': '#' }, '/0/backgrounds': { 'b.feature': '#' } })
);
expect(res).toEqual({
features: [{ base: '/0', path: '/features/a.feature', name: '/0/features/a', type: 'feature', content: '#' }],
backgrounds: [{ base: '/0', path: '/backgrounds/b.feature', name: '/0/backgrounds/b', type: 'feature', content: '#' }],
});
});

it('multi-base no features or backgrounds', async () => {
expect(() => getFeaturesAndBackgrounds(['/,x'], [], { existsSync: () => true })).toThrow();
});
it('multi-base gets features', async () => {
expect(getFeaturesAndBackgrounds(basesFrom('/0,/1'), [], nfs({ '/0/features': { 'a.feature': '#' }, '/1/features': { 'b.feature': '#' } }))).toEqual({
features: [{ base: '/0', path: '/features/a.feature', name: '/0/features/a', type: 'feature', content: '#' }, { base: '/1', path: '/features/b.feature', name: '/1/features/b', type: 'feature', content: '#' }]
, backgrounds: []
});
});
it('multi-base no features', async () => {
expect(() => getFeaturesAndBackgrounds('/0,/1'.split(','), [], nfs({ '/0/backgrounds': { 'a.feature': '#' }, '/1/backgrounds': { 'a.feature': '#' } }))).toThrow();
});
it('multi-base no features or backgrounds from first dir', async () => {
expect(() => getFeaturesAndBackgrounds(basesFrom('/0,/1'), [], nfs({ '/1/backgrounds': { 'a.feature': '#' } }))).toThrow();
});
it('multi-base no features or backgrounds from second dir', async () => {
expect(() => getFeaturesAndBackgrounds(basesFrom('/0,/1'), [], nfs({ '/0/backgrounds': { 'a.feature': '#' } }))).toThrow();
});
it('multi-base get features and backgrounds', async () => {
expect(getFeaturesAndBackgrounds(basesFrom('/0,/1'), [], nfs({ '/0/backgrounds': { 'a.feature': '#' }, '/1/features': { 'b.feature': '#' } })))
.toEqual({
features: [{ base: '/1', path: '/features/b.feature', name: '/1/features/b', type: 'feature', content: '#' },],
backgrounds: [{ base: '/0', path: '/backgrounds/a.feature', name: '/0/backgrounds/a', type: 'feature', content: '#' },]
});
});
it('multi-base no features or backgrounds', async () => {
expect(() => getFeaturesAndBackgrounds(['/,x'], [], { existsSync: () => true })).toThrow();
});
it('multi-base gets features', async () => {
expect(
getFeaturesAndBackgrounds(
basesFrom('/0,/1'),
[],
nfs({ '/0/features': { 'a.feature': '#' }, '/1/features': { 'b.feature': '#' } })
)
).toEqual({
features: [
{ base: '/0', path: '/features/a.feature', name: '/0/features/a', type: 'feature', content: '#' },
{ base: '/1', path: '/features/b.feature', name: '/1/features/b', type: 'feature', content: '#' },
],
backgrounds: [],
});
});
it('multi-base no features', async () => {
expect(() =>
getFeaturesAndBackgrounds(
'/0,/1'.split(','),
[],
nfs({ '/0/backgrounds': { 'a.feature': '#' }, '/1/backgrounds': { 'a.feature': '#' } })
)
).toThrow();
});
it('multi-base no features or backgrounds from first dir', async () => {
expect(() => getFeaturesAndBackgrounds(basesFrom('/0,/1'), [], nfs({ '/1/backgrounds': { 'a.feature': '#' } }))).toThrow();
});
it('multi-base no features or backgrounds from second dir', async () => {
expect(() => getFeaturesAndBackgrounds(basesFrom('/0,/1'), [], nfs({ '/0/backgrounds': { 'a.feature': '#' } }))).toThrow();
});
it('multi-base get features and backgrounds', async () => {
expect(
getFeaturesAndBackgrounds(
basesFrom('/0,/1'),
[],
nfs({ '/0/backgrounds': { 'a.feature': '#' }, '/1/features': { 'b.feature': '#' } })
)
).toEqual({
features: [{ base: '/1', path: '/features/b.feature', name: '/1/features/b', type: 'feature', content: '#' }],
backgrounds: [{ base: '/0', path: '/backgrounds/a.feature', name: '/0/backgrounds/a', type: 'feature', content: '#' }],
});
});
});

describe('shouldProcess', () => {
it('should process no type & filter', () => {
expect(shouldProcess('hi.feature', undefined, undefined)).toBe(true);
});
it('should process matching filter', () => {
expect(shouldProcess('hi.feature', undefined, ['hi'])).toBe(true);
});
it('should not process wrong type', () => {
expect(shouldProcess('hi.feature', 'wrong', undefined)).toBe(false);
});
it('should not process wrong filter', () => {
expect(shouldProcess('hi.feature', undefined, ['wrong'])).toBe(false);
});
it('should not process root filter', () => {
expect(shouldProcess('/root/hi.feature', undefined, ['root'])).toBe(false);
});
it('should process upper root filter', () => {
expect(shouldProcess('/root/root.feature', undefined, ['root'])).toBe(true);
});
it('should process no type & filter', () => {
expect(shouldProcess('hi.feature', undefined, undefined)).toBe(true);
});
it('should process matching filter', () => {
expect(shouldProcess('hi.feature', undefined, ['hi'])).toBe(true);
});
it('should not process wrong type', () => {
expect(shouldProcess('hi.feature', 'wrong', undefined)).toBe(false);
});
it('should not process wrong filter', () => {
expect(shouldProcess('hi.feature', undefined, ['wrong'])).toBe(false);
});
it('should not process root filter', () => {
expect(shouldProcess('/root/hi.feature', undefined, ['root'])).toBe(false);
});
it('should process upper root filter', () => {
expect(shouldProcess('/root/root.feature', undefined, ['root'])).toBe(true);
});
});
4 changes: 1 addition & 3 deletions modules/out-review/dashboard/web/src/reviews/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ export type TWindowRouter = {
}

export class Router {
routesFor: TRoutable;
index = '';
source = '';
group = '';
currentHash = '';

constructor(routesFor: TRoutable) {
this.routesFor = routesFor;
constructor(private routesFor: TRoutable) {
(globalThis as unknown as TWindowRouter)._router = this;
this._updateProps();
}
Expand Down
5 changes: 1 addition & 4 deletions modules/web-playwright/src/BrowserFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class BrowserFactory {
tracers: { [name: string]: PlaywrightEvents } = {};
contexts: { [name: string]: BrowserContext } = {};
pages: { [name: string]: Page | undefined } = {};
logger: ILogger;
static tracer?: PlaywrightEvents = undefined;
static configs: {
[name: string]: {
Expand All @@ -47,9 +46,7 @@ export class BrowserFactory {
} = {};
myBrowsers: { [name: string]: Browser; };

private constructor(logger: ILogger) {
this.logger = logger;
}
private constructor(private logger: ILogger) { }

static async getBrowserFactory(logger: ILogger, options: TBrowserFactoryOptions, tag = DEFAULT_CONFIG_TAG) {
options.type = options.type || 'chromium';
Expand Down
9 changes: 1 addition & 8 deletions modules/web-playwright/src/PlaywrightEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ type TEtc = {
statusText?: string;
}
export class PlaywrightEvents {
page: Page;
tag: TTag;
logger: ILogger;

constructor(logger: ILogger, page: Page, tag: TTag) {
this.logger = logger;
this.page = page;
constructor(private logger: ILogger, private page: Page, private tag: TTag) {
this.logger.log(`setPage ${JSON.stringify(tag)}`);
this.tag = tag;
page.on('request', this.logRequest.bind(this));
// eslint-disable-next-line @typescript-eslint/no-floating-promises
page.route('**/*', this.routeRequest.bind(this));
Expand Down
Loading

0 comments on commit 264c25e

Please sign in to comment.