mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-08 17:22:26 +03:00
f87822f3a3
* feat: add ability to prepublish canary versions * fix: ci * fix: pr comment * fix: ci pr * fix: ci pr env * fix: github env name * fix: github file ignoring * fix: yml syntax * fix: codeql * fix: syntax error * fix: pnpm version * fix: remove node 16.x support * fix: workspace name * fix: workspace pnpm * fix: workspace with pnpm * ci: changeset publish * ci: changeset pr name * ci: pr * ci: fix pr.yml * ci: fix pr.yml workspaces * ci: fix steps order in pr.yml * ci: fix pr publish error * ci: fix npm publish tag to alpha * ci: npm publish tag * ci: npm publish tag * ci: fix tag with PR number
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { createPreset } from '../src';
|
|
import { createTree } from '@bbob/core'
|
|
import type { PresetTagsDefinition, BBobCoreOptions } from '@bbob/types';
|
|
|
|
describe('@bbob/preset', () => {
|
|
const presetFactory = <Tags extends PresetTagsDefinition = PresetTagsDefinition>(defTags: Tags) => {
|
|
const processor = jest.fn((tags, tree, core, options) => tags)
|
|
const preset = createPreset<Tags>(defTags, processor)
|
|
|
|
return {
|
|
preset,
|
|
processor,
|
|
core: {} as BBobCoreOptions
|
|
}
|
|
}
|
|
|
|
test('create', () => {
|
|
const defTags = { test: () => ({ tag: 'test' }) }
|
|
const options = { foo: 'bar' }
|
|
const tree = createTree([], {})
|
|
const { preset, processor } = 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: () => ({ tag: 'foo'}) }
|
|
const extendedTags = { bar: () =>({tag: '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 } = presetFactory({ test: () => ({tag: 'test'}) });
|
|
const newPreset = preset.extend((tags, options) => ({ bar: () => ({tag: 'bar'}) }));
|
|
|
|
const instance = preset({ foo: 'bar' });
|
|
const instance2 = newPreset({ some: 'some' });
|
|
|
|
expect(instance.options)
|
|
.toEqual({ foo: 'bar' });
|
|
expect(instance2.options)
|
|
.toEqual({ some: 'some' })
|
|
});
|
|
});
|