File: test.js

package info (click to toggle)
node-file-sync-cmp 0.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 120 kB
  • sloc: javascript: 74; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';

var fileSyncCmp = require('../');

var assert = require('assert');
var fs = require('fs');

var tmp = require('tmp');
tmp.setGracefulCleanup();

var Q = require('q');

var fsWrite = Q.nfbind(fs.write);
var tmpFile = Q.nfbind(tmp.file);

function write (fd, buf) {
    return fsWrite(fd, buf, 0, buf.length, null);
}


describe('equalFiles', function () {
    var pathA, pathB;
    var fdA, fdB;

    beforeEach(function () {
        return Q.all([tmpFile(), tmpFile()]).spread(function (a, b) {
            pathA = a[0];
            pathB = b[0];
            fdA = a[1];
            fdB = b[1];
        });
    });

    it('should handle empty files', function () {
        assert(fileSyncCmp.equalFiles(pathA, pathB));
    });

    it('should handle equal content', function () {
        var buf = new Buffer.from('File content\n');
        var writes = [write(fdA, buf), write(fdB, buf)];
        return Q.all(writes).then(function () {
            assert(fileSyncCmp.equalFiles(pathA, pathB));
        });
    });

    it('should handle non-equal content', function () {
        var bufA = new Buffer.from('Some text\n');
        var bufB = new Buffer.from('Other text\n');
        var writes = [write(fdA, bufA), write(fdB, bufB)];
        return Q.all(writes).then(function () {
            assert(!fileSyncCmp.equalFiles(pathA, pathB));
        });
    });
});