How to use the memfs.vol function in memfs

To help you get started, we’ve selected a few memfs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thiagodp / concordialang / dist / __tests__ / plugin / PackageBasedPluginFinder.spec.js View on Github external
beforeEach(() => {
        memfs_1.vol.mkdirpSync(currentDir, { recursive: true }); // Synchronize - IMPORTANT! - mkdirpSync, not mkdirSync
        memfs_1.vol.mkdirpSync(localModulesDir);
        memfs_1.vol.mkdirpSync(globalModulesDir); // Global modules directory
    });
    afterEach(() => {
github sapegin / mrm-core / src / formats / __tests__ / file.spec.js View on Github external
jest.mock('fs');
jest.mock('../../util/log', () => ({
	added: jest.fn(),
	removed: jest.fn(),
}));

const vol = require('memfs').vol;
const log = require('../../util/log');
const file = require('../file');

const filename = '/test.txt';
const fsJson = { '/test.txt': 'pizza' };

afterEach(() => {
	vol.reset();
});

describe('file()', () => {
	it('should return an API', () => {
		const result = file('notfound');
		expect(result).toEqual(
			expect.objectContaining({
				exists: expect.any(Function),
github sapegin / mrm-core / src / __tests__ / editorconfig.spec.js View on Github external
jest.mock('fs');

const vol = require('memfs').vol;
const editorconfig = require('../editorconfig');
const hasTrailingNewLine = editorconfig.hasTrailingNewLine;
const getIndent = editorconfig.getIndent;
const findEditorConfig = editorconfig.findEditorConfig;
const inferStyle = editorconfig.inferStyle;
const getStyleForFile = editorconfig.getStyleForFile;
const format = editorconfig.format;

afterEach(() => {
	vol.reset();
});

describe('hasTrailingNewLine()', () => {
	it('should return true if a string has a new line in the end', () => {
		const result = hasTrailingNewLine('foo\nbar\n');
		expect(result).toBe(true);
github sapegin / mrm-core / src / formats / __tests__ / lines.spec.js View on Github external
jest.mock('fs');
jest.mock('../../util/log', () => ({
	added: jest.fn(),
	removed: jest.fn(),
}));

const vol = require('memfs').vol;
const log = require('../../util/log');
const lines = require('../lines');

const filename = '/test.lines';
const data = ['one', 'two'];
const json = { '/test.lines': data.join('\n') };

afterEach(() => {
	vol.reset();
});

describe('lines()', () => {
	it('should return an API', () => {
		const file = lines('notfound');
		expect(file).toEqual(
			expect.objectContaining({
github sapegin / mrm-core / src / formats / __tests__ / template.spec.js View on Github external
jest.mock('fs');
jest.mock('../../util/log', () => ({
	added: jest.fn(),
	removed: jest.fn(),
}));

const vol = require('memfs').vol;
const log = require('../../util/log');
const template = require('../template');

afterEach(() => {
	vol.reset();
});

it('should return an API', () => {
	const file = template('notfound', 'notfound');
	expect(file).toEqual(
		expect.objectContaining({
			exists: expect.any(Function),
			get: expect.any(Function),
			apply: expect.any(Function),
			save: expect.any(Function),
		})
github thiagodp / concordialang / dist / __tests__ / plugin / PackageBasedPluginFinder.spec.js View on Github external
it('finds in a local module', () => __awaiter(this, void 0, void 0, function* () {
        memfs_1.vol.mkdirpSync(localPluginDir);
        memfs_1.vol.writeFileSync(localPluginPackageFile, JSON.stringify(pkg));
        const finder = new PackageBasedPluginFinder_1.PackageBasedPluginFinder(currentDir, memfs_1.fs);
        const pluginData = yield finder.find();
        expect(pluginData).toHaveLength(1);
        const first = pluginData[0];
        expect(first.name).toEqual(pkg.name);
    }));
    it('finds in a global module', () => __awaiter(this, void 0, void 0, function* () {
github sapegin / mrm-core / src / formats / __tests__ / yaml.spec.js View on Github external
jest.mock('fs');
jest.mock('../../util/log', () => ({
	added: jest.fn(),
	removed: jest.fn(),
}));

const vol = require('memfs').vol;
const log = require('../../util/log');
const yaml = require('../yaml');

const filename = '/test.yml';
const json = {
	'/test.yml': `bar: 42
baz:
  foo:
    43
`,
};

afterEach(() => {
	vol.reset();
});
github sapegin / mrm-core / src / formats / __tests__ / markdown.spec.js View on Github external
jest.mock('fs');
jest.mock('../../util/log', () => ({
	added: jest.fn(),
	removed: jest.fn(),
}));

const vol = require('memfs').vol;
const log = require('../../util/log');
const markdown = require('../markdown');

const md = `
# Foo

Hello.
`;

const mdWithBadge = `
# Foo

[![Example](http://example.com/badge.svg)](http://example.com/)

Hello.
`;
github sapegin / mrm-core / src / __tests__ / npm.spec.js View on Github external
jest.mock('fs');
jest.mock('../util/log', () => ({
	info: jest.fn(),
}));

const fs = require('fs-extra');
const vol = require('memfs').vol;
const log = require('../util/log');
const _npm = require('../npm');
const install = _npm.install;
const uninstall = _npm.uninstall;

const modules = ['eslint', 'babel-core'];
const options = {
	cwd: undefined,
	stdio: 'inherit',
};

const createPackageJson = (dependencies, devDependencies) => {
	fs.writeFileSync(
		'package.json',
		JSON.stringify({
			dependencies,
github sapegin / mrm-core / src / formats / __tests__ / json.spec.js View on Github external
jest.mock('fs');
jest.mock('../../util/log', () => ({
	added: jest.fn(),
	removed: jest.fn(),
}));

const vol = require('memfs').vol;
const log = require('../../util/log');
const json = require('../json');

const object = {
	bar: 42,
	baz: {
		foo: 43,
	},
};

const filename = '/test.json';
const fsJson = { '/test.json': JSON.stringify(object, null, '  ') };

afterEach(() => {
	vol.reset();
});