Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(() => {
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),
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);
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({
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),
})
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* () {
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();
});
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.
`;
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,
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();
});