mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-17 19:21:20 +03:00
8797f7f363
* feat: initial typescript support * feat: typescript support * feat(plugin-helper): move files to typescript * chore: update lock files * feat: preset types * fix: build * fix: benchmark * fix: remove pnpm cache * fix: bench action * fix: pnpm recursive install * fix: nx cache * fix: lock file * fix: workflows * fix: lerna support in pnpm * fix: pnpm workspace * fix: remove unused files * fix: pnpm lock file * fix: update lerna for support pnpm * fix: lerna bootstrap * fix: rollup build * fix: update nx * fix: build * fix: add nx dep target * fix: remove nx cache * fix: workflow run on push only for master * fix: test workflow run on push only for master * fix: remove parallel for gen types * fix: benchmark * fix: benchmark imports * fix: pnpm * fix: types errors and pnpm * fix: types * fix: types * refactor: parser * fix(parser): tests * fix: preset tests * fix: react types * fix: react type declarations * fix: pnpm lock file * fix: react preset types * fix: lock file * fix: vue2 types * feat: dev container support * fix: types * fix: types * refactor: rewrite pkg-task, add nx gen-types deps, fix react/render.ts * refactor: types * fix: types * fix: rename gen-types to types * fix: nx build order * fix: nx reset * fix: define nx deps explicit * fix: build * fix: nx * fix: nx order build * fix: nx deps * fix: bbob cli tests * fix: tests * fix: cli tests and import * fix: test cover * fix: cli cover
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { createPreset, PresetTagsDefinition } from '../src';
|
|
import { BBobCoreOptions, createTree } from '@bbob/core'
|
|
|
|
describe('@bbob/preset', () => {
|
|
const presetFactory = (defTags: PresetTagsDefinition) => {
|
|
const processor = jest.fn((tags, tree, core, options) => tags)
|
|
|
|
return {
|
|
preset: createPreset(defTags, processor),
|
|
processor,
|
|
core: {} as BBobCoreOptions
|
|
}
|
|
}
|
|
|
|
test('create', () => {
|
|
const defTags = { test: () => 'test' }
|
|
const options = { foo: 'bar' }
|
|
const tree = createTree([], {})
|
|
const { preset, processor, core } = presetFactory(defTags);
|
|
|
|
expect(preset.extend)
|
|
.toBeDefined();
|
|
expect(preset)
|
|
.toBeInstanceOf(Function);
|
|
|
|
expect(preset(options)(tree)).toEqual(defTags);
|
|
|
|
expect(processor.mock.calls.length).toBe(1);
|
|
});
|
|
test('extend', () => {
|
|
const defTags = { foo: () => 'foo' }
|
|
const extendedTags = { bar: () => 'bar' }
|
|
const options = { foo: 'bar' }
|
|
const tree = createTree([], {})
|
|
const { preset, processor, core } = presetFactory(defTags);
|
|
const newPreset = preset.extend(tags => ({ ...tags, ...extendedTags }));
|
|
|
|
expect(preset)
|
|
.toBeInstanceOf(Function);
|
|
expect(newPreset)
|
|
.toBeInstanceOf(Function);
|
|
|
|
const newPresetRes = newPreset(options)
|
|
|
|
expect(newPresetRes(tree)).toEqual({...defTags, ...extendedTags});
|
|
|
|
expect(processor.mock.calls.length).toBe(1);
|
|
});
|
|
test('pass options', () => {
|
|
const { preset, processor } = presetFactory({ test: () => 'test' });
|
|
const newPreset = preset.extend((tags, options) => ({ bar: () => 'bar' }));
|
|
|
|
const instance = preset({ foo: 'bar' });
|
|
const instance2 = newPreset({ some: 'some' });
|
|
|
|
expect(instance.options)
|
|
.toEqual({ foo: 'bar' });
|
|
expect(instance2.options)
|
|
.toEqual({ some: 'some' })
|
|
});
|
|
});
|