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

115 lines (95 loc) 2.39 kB
const { vol } = require('memfs') const writeCache = require('../writeCache') const fixtures = { mergedConfigs: { '.eslintrc': 'foo', '.editorconfig': 'bar', '.babelrc': 'baz', }, } describe('steps > writeCache', () => { const semaphore = { start: jest.fn(), success: jest.fn(), error: jest.fn(), fail: jest.fn(), warn: jest.fn(), } let context beforeEach(() => { jest.clearAllMocks() vol.reset() }) describe("cache isn't allowed", () => { beforeEach(() => { context = { targetPath: '/target', options: { cache: false, }, mergedConfigs: fixtures.mergedConfigs, } const dir = {} vol.fromJSON(dir, '/') }) it("doesn't write cache", async () => { await writeCache(context, semaphore) expect(vol.readdirSync('/')).toHaveLength(0) }) }) describe('cache is allowed', () => { describe('not included', () => { beforeEach(() => { context = { targetPath: '/', options: { cache: true, }, mergedConfigs: fixtures.mergedConfigs, } const dir = {} vol.fromJSON(dir, '/') }) it('writes cache to `node_modules`', async () => { await writeCache(context, semaphore) expect(vol.readdirSync('/node_modules/.cache/sharec')).toHaveLength(3) }) }) describe('included', () => { beforeEach(() => { context = { targetPath: '/', options: { cache: 'include', }, cache: {}, mergedConfigs: fixtures.mergedConfigs, } const dir = {} vol.fromJSON(dir, '/') }) it("doesn't write cache", async () => { await writeCache(context, semaphore) expect(vol.readdirSync('/.sharec/cache')).toHaveLength(3) }) }) describe('nothing to save', () => { beforeEach(() => { context = { targetPath: '/', options: { cache: 'include', }, cache: {}, mergedConfigs: {}, } const dir = {} vol.fromJSON(dir, '/') }) it("doesn't write cache", async () => { await writeCache(context, semaphore) expect(vol.readdirSync('/')).not.toContain('.sharec') }) }) }) })