UNPKG

sharec-core

Version:

[![.github/workflows/main.yml](https://github.com/lamartire/sharec/workflows/.github/workflows/main.yml/badge.svg)](https://github.com/lamartire/sharec/actions) [![npm](https://img.shields.io/npm/v/sharec)](https://npmjs.com/sharec) ![MIT License](https:/

75 lines (59 loc) 1.5 kB
const { vol } = require('memfs') const applyRuntimeHook = require('../applyRuntimeHook') describe('steps > applyRuntimeHook', () => { let context beforeEach(() => { vol.reset() }) describe('without runtime config', () => { beforeEach(() => { context = { targetPath: '/', cache: {}, options: { cache: true, }, } const dir = {} vol.fromJSON(dir, '/') }) it("doesn't modify initial context", async () => { expect.assertions(1) const hook = applyRuntimeHook('beforeMerge') const res = await hook(context) expect(res.mergedConfigs).toBeUndefined() }) }) describe('with runtime config', () => { beforeEach(() => { context = { targetPath: '/', cache: {}, mergedConfigs: { '/.gitignore': 'original', }, runtimeConfig: { afterMerge: context => { for (const key in context.mergedConfigs) { context.mergedConfigs[key] = 'replaced' } return context }, }, options: { cache: true, }, } const dir = {} vol.fromJSON(dir, '/') }) it('applies hook to the context', async () => { expect.assertions(1) const hook = applyRuntimeHook('afterMerge') const res = await hook(context) expect(res.mergedConfigs).toEqual({ '/.gitignore': 'replaced', }) }) }) })