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:/

118 lines (95 loc) 2.54 kB
const { vol } = require('memfs') const readCache = require('../readCache') describe('steps > readCache', () => { const semaphore = { start: jest.fn(), success: jest.fn(), error: jest.fn(), fail: jest.fn(), } let context beforeEach(() => { jest.clearAllMocks() vol.reset() }) describe("target doesn't have cache", () => { describe('not included', () => { beforeEach(() => { context = { targetPath: '/', cache: {}, options: { cache: true, }, } const dir = {} vol.fromJSON(dir, '/') }) it("doesn't modify initial context", async () => { expect.assertions(1) await expect(readCache(context, semaphore)).resolves.toEqual(context) }) }) describe('included', () => { beforeEach(() => { context = { targetPath: '/', cache: {}, options: { cache: 'include', }, } const dir = {} vol.fromJSON(dir, '/') }) it("doesn't modify initial context", async () => { expect.assertions(1) await expect(readCache(context, semaphore)).resolves.toEqual(context) }) }) }) describe('target has cache', () => { describe('not included', () => { beforeEach(() => { context = { targetPath: '/', cache: {}, options: { cache: true, }, } const dir = { '/node_modules/.cache/sharec/.eslintrc': 'foo', '/node_modules/.cache/sharec/.editorconfig': 'bar', '/node_modules/.cache/sharec/folder/.babelrc': 'baz', } vol.fromJSON(dir, '/') }) it('add cache to the context', async () => { expect.assertions(1) await expect(readCache(context, semaphore)).resolves.toEqual(context) }) }) describe('included', () => { beforeEach(() => { context = { targetPath: '/', cache: {}, options: { cache: 'include', }, } const dir = { '/.sharec/cache/.eslintrc': 'foo', '/.sharec/cache/.editorconfig': 'bar', '/.sharec/cache/folder/.babelrc': 'baz', } vol.fromJSON(dir, '/') }) it('adds cache to the context', async () => { expect.assertions(1) await expect(readCache(context, semaphore)).resolves.toEqual(context) }) }) }) })