Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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');
});
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)});
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) {
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();
});
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"]
content: "another content"
})
});
(parseSnapshotFile as jest.Mock).mockReturnValue([
"this is definition, not important for test"
]);
let def = cache.getSnapshotForFile("/abc/tt.ts");
expect(def).toEqual({
file: "/abc/__my__/tt.ts.snap",
definitions: ["this is definition, not important for test"]
});
expect(parseSnapshotFile).toBeCalledWith(ts, "/abc/__my__/tt.ts.snap", "some content");
fsMock({
"/abc/tt.ts.snap": fsMock.file({
mtime: new Date(),
content: "some content"
}),
});
cache.dir = "";
(parseSnapshotFile as jest.Mock).mockClear();
def = cache.getSnapshotForFile("/abc/tt.ts");
expect(def).toEqual({
file: "/abc/tt.ts.snap",
definitions: ["this is definition, not important for test"]
});
expect(parseSnapshotFile).toBeCalledWith(ts, "/abc/tt.ts.snap", "some content");
cache.dir = "./";
(parseSnapshotFile as jest.Mock).mockClear();
def = cache.getSnapshotForFile("/abc/tt.ts");
beforeEach(function() {
mock({
src: {
js: {
'a.js': mock.file({
mtime: new Date(100)
}),
'b.js': mock.file({
mtime: new Date(200)
}),
'c.js': mock.file({
mtime: new Date(300)
})
},
less: {
'one.less': mock.file({mtime: new Date(100)}),
'two.less': mock.file({mtime: new Date(200)})
}
},
dest: {
js: {
'abc.min.js': mock.file({
mtime: new Date(200)
})
before(function () {
var test_file = mock.file({ content: content });
mock({ test_file: test_file });
});
it('should read a file', function () {
beforeEach(function() {
mock({
file1: mock.file({
content: 'file1 content',
mtime: new Date(200),
ctime: new Date(200)
}),
file2: mock.file({
content: 'file2 content',
mtime: new Date(100),
ctime: new Date(100)
}),
file3: mock.file({
content: 'file3 content',
mtime: new Date(100),
ctime: new Date(100)
}),
dest: {
output: mock.file({