How to check if two files have the same content?

前端 未结 6 577
说谎
说谎 2021-02-05 10:35

I am using mocha/supertest/should.js to test my Rest Service

GET /files/ returns file as stream.

How can I assert in should.js

6条回答
  •  借酒劲吻你
    2021-02-05 10:44

    Solution using file-compare and node-temp:

    it('should return test2.json as a stream', function (done) {
        var writeStream = temp.createWriteStream();
        temp.track();
    
        var req = api.get('/files/7386afde8992');
    
        req.on('end', function() {
            comparator.compare(writeStream.path, TEST2_JSON_FILE, function(result, err) {
                if (err) {
                    return done(err);
                }
    
                result.should.true;
                done();
            });
        });
    
        req.pipe(writeStream);
    });
    

提交回复
热议问题