How to use mock-fs - 10 common examples

To help you get started, we’ve selected a few mock-fs 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 Tatamo / atcoder-cli / tests / __tests__ / template.ts View on Github external
mock({
				[DUMMY_CONFIG_DIRECTORY_PATH]: {
					...templates2files(mock_templates),
					// add directory without template.json
					"non-template": {
						"this-is-not-template.json": JSON.stringify({
							task: {
								submit: "main.cpp",
								program: ["main.cpp"]
							}
						})
					}
				}
			});
			const result = await template.getTemplates();
			mock.restore();
			// there's no template "non-template"
			expect(result).toMatchSnapshot();
		});
		test("files to be ignored", async () => {
github JustBlackBird / gulp-phpcs / test / specs / reporters / file.js View on Github external
beforeEach(function() {
            mockFs({
                '/reports/locked.log': mockFs.file({
                    mode: parseInt('444', 8)
                })
            });

            // Actually we have to replace gutil.log with a stub because its
            // current implementation uses "require" at run-time which will
            // fail after file system is mocked.
            logStub = sinon.stub(gutil, 'log');
        });
github angular / angular / tools / broccoli / tree-differ.spec.ts View on Github external
it('should ignore files with extensions listed in excludeExtensions', () => {
      let testDir = {
        'dir1': {
          'file-1.ts': mockfs.file({content: 'file-1.ts content', mtime: new Date(1000)}),
          'file-1.cs': mockfs.file({content: 'file-1.cs content', mtime: new Date(1000)}),
          'file-1d.cs': mockfs.file({content: 'file-1d.cs content', mtime: new Date(1000)}),
          'file-1.d.cs': mockfs.file({content: 'file-1.d.cs content', mtime: new Date(1000)}),
          'file-2.md': mockfs.file({content: 'file-2.md content', mtime: new Date(1000)}),
          'file-3.ts': mockfs.file({content: 'file-3.ts content', mtime: new Date(1000)}),
          'file-4.d.ts': mockfs.file({content: 'file-4.d.ts content', mtime: new Date(1000)}),
          'subdir-1': {
            'file-1.1.cc': mockfs.file({content: 'file-1.1.cc content', mtime: new Date(1000)})
          }
        }
      };
      mockfs(testDir);

      let differ = new TreeDiffer('testLabel', 'dir1', ['.ts', '.cs'], ['.d.ts', '.d.cs']);

      let diffResult = differ.diffTree();

      expect(diffResult.addedPaths).toEqual(['file-1.cs', 'file-1.ts', 'file-1d.cs', 'file-3.ts']);

      // change two files
      testDir['dir1']['file-1.ts'] = mockfs.file({content: 'new content', mtime: new Date(1000)});
github angular / angular / tools / broccoli / tree-differ.spec.ts View on Github external
it('should handle changes via symbolic links', () => {
      let testDir = {
        'orig_path': {
          'file-1.txt': mockfs.file({content: 'file-1.txt content', mtime: new Date(1000)}),
          'file-2.txt': mockfs.file({content: 'file-2.txt content', mtime: new Date(1000)}),
          'subdir-1': {
            'file-1.1.txt': mockfs.file({content: 'file-1.1.txt content', mtime: new Date(1000)})
          }
        },
        'symlinks': {
          'file-1.txt': mockfs.symlink({path: '../orig_path/file-1.txt'}),
          'file-2.txt': mockfs.symlink({path: '../orig_path/file-2.txt'}),
          'subdir-1':
              {'file-1.1.txt': mockfs.symlink({path: '../../orig_path/subdir-1/file-1.1.txt'})}
        }
      };
      mockfs(testDir);

      let differ = new TreeDiffer('testLabel', 'symlinks');

      let diffResult = differ.diffTree();

      expect(diffResult.addedPaths).toEqual([
        'file-1.txt', 'file-2.txt', 'subdir-1' + path.sep + 'file-1.1.txt'
      ]);

      // change two files
      testDir['orig_path']['file-1.txt'] =
github angular / angular / tools / broccoli / tree-differ.spec.ts View on Github external
it('should handle changes via symbolic links', () => {
      let testDir = {
        'orig_path': {
          'file-1.txt': mockfs.file({content: 'file-1.txt content', mtime: new Date(1000)}),
          'file-2.txt': mockfs.file({content: 'file-2.txt content', mtime: new Date(1000)}),
          'subdir-1': {
            'file-1.1.txt': mockfs.file({content: 'file-1.1.txt content', mtime: new Date(1000)})
          }
        },
        'symlinks': {
          'file-1.txt': mockfs.symlink({path: '../orig_path/file-1.txt'}),
          'file-2.txt': mockfs.symlink({path: '../orig_path/file-2.txt'}),
          'subdir-1':
              {'file-1.1.txt': mockfs.symlink({path: '../../orig_path/subdir-1/file-1.1.txt'})}
        }
      };
      mockfs(testDir);

      let differ = new TreeDiffer('testLabel', 'symlinks');

      let diffResult = differ.diffTree();

      expect(diffResult.addedPaths).toEqual([
        'file-1.txt', 'file-2.txt', 'subdir-1' + path.sep + 'file-1.1.txt'
      ]);

      // change two files
      testDir['orig_path']['file-1.txt'] =
          mockfs.file({content: 'new content', mtime: new Date(1000)});
      testDir['orig_path']['subdir-1']['file-1.1.txt'] =
github angular / angular / tools / broccoli / tree-differ.spec.ts View on Github external
it('should handle changes via symbolic links', () => {
      let testDir = {
        'orig_path': {
          'file-1.txt': mockfs.file({content: 'file-1.txt content', mtime: new Date(1000)}),
          'file-2.txt': mockfs.file({content: 'file-2.txt content', mtime: new Date(1000)}),
          'subdir-1': {
            'file-1.1.txt': mockfs.file({content: 'file-1.1.txt content', mtime: new Date(1000)})
          }
        },
        'symlinks': {
          'file-1.txt': mockfs.symlink({path: '../orig_path/file-1.txt'}),
          'file-2.txt': mockfs.symlink({path: '../orig_path/file-2.txt'}),
          'subdir-1':
              {'file-1.1.txt': mockfs.symlink({path: '../../orig_path/subdir-1/file-1.1.txt'})}
        }
      };
      mockfs(testDir);

      let differ = new TreeDiffer('testLabel', 'symlinks');

      let diffResult = differ.diffTree();

      expect(diffResult.addedPaths).toEqual([
        'file-1.txt', 'file-2.txt', 'subdir-1' + path.sep + 'file-1.1.txt'
      ]);

      // change two files
github theasta / grunt-assets-versioning / Gruntfile.js View on Github external
grunt.registerTask('startMocking', function () {

    mock({
      'test/fake/': {
        'file1.js': mock.file({
          content: 'file content here',
          ctime: new Date(1411609054470),
          mtime: new Date(1411609054470) //Wed Sep 24 2014 18:37:34 GMT-0700 (PDT)
        }),
        'file2.js': mock.file({
          content: 'file content here',
          ctime: new Date(1369140245000),
          mtime: new Date(1369140245000) //Tue May 21 2013 05:44:05 GMT-0700 (PDT)
        }),
        'file3.js': mock.file({
          content: 'file content here',
          ctime: new Date(1328091453000),
          mtime: new Date(1328091453000) //Wed Feb 01 2012 02:17:33 GMT-0800 (PST)
        }),
        'file4.js': mock.file({
          content: 'file content here',
          ctime: new Date(1388563200000),
          mtime: new Date(1388563200000) //Wed Jan 01 2014 00:00:00 GMT-0800 (PST)
        })
      }
    });

    // grunt is using glob that is using graceful-fs.
    // It also needs to be mocked
    _fileGlobSync = grunt.file.glob.sync;
    grunt.file.glob.sync = function (pattern, options) {
github sakuli / sakuli / packages / sakuli-legacy / src / loader / legacy-loader.class.spec.ts View on Github external
beforeEach(async function mockValidProjectLayout(done) {
            mockFs({
                'path/to/testsuites': {
                    'sakuli.properties': `
                        sakuli.environment.similarity.default=0.99
                    `,
                    'suite': {
                        'testsuite.properties': `testsuite.name=test`,
                        'testsuite.suite': stripIndent`
                            case1/sakuli_demo.js http://sahi.example.com/_s_/dyn/Driver_initialized
                            case2/sakuli_demo.js http://sahi.example.com/_s_/dyn/Driver_initialized
                        `,
                        case1: {
                            'sakuli_demo.js': '// Test'
                        },
                        case2: {
                            'sakuli_demo.js': '// Test'
                        }
github bokub / lyo / test / options.js View on Github external
test('.babelrc is detected when present', t => {
	t.is(parseOptions({}, {}).babelConfig, undefined);

	const babelrc = mock.file({content: '{"presets": ["@babel/preset-env" ]}'});
	mock({'.babelrc': babelrc});

	t.is(parseOptions({}, {}).babelConfig, process.cwd() + '/.babelrc');
	mock.restore();
});
github asvetliakov / typescript-snapshots-plugin / src / __tests__ / snapshotcache.spec.ts View on Github external
it("Picks first available file when given multiple extensions", () => {
    cache.extensions = [".story", ".snap"];
    fsMock({
        "/abc/__snapshots__/tt.ts.story": fsMock.file({
            mtime: new Date(2017, 10, 10, 10, 1, 1),
            content: "story content"
        }),
        "/abc/__snapshots__/tt.ts.snap": fsMock.file({
            mtime: new Date(2017, 10, 10, 10, 1, 1),
            content: "some content"
        })
    });
    (parseSnapshotFile as jest.Mock).mockReturnValue([
        "this is definition, not important for test"
    ]);

    const def = cache.getSnapshotForFile("/abc/tt.ts");
    expect(def).toEqual({
        file: "/abc/__snapshots__/tt.ts.story",
        definitions: ["this is definition, not important for test"]

mock-fs

A configurable mock file system. You know, for testing.

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis