| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/nami/node_modules/chai-fs/lib/assertions/ |
Upload File : |
module.exports = function (chai, utils) {
var Assertion = chai.Assertion;
var flag = utils.flag;
var assert = chai.assert;
var fs = require('fs');
//-------------------------------------------------------------------------------------------------------------
//TODO add (utf8, base64, etc) flag chain props
//TODO add Buffer compare/diff
var contentMethod = function (expected, msg) {
var preMsg = '';
if (msg) {
flag(this, 'message', msg);
preMsg = msg + ': ';
}
var obj = this._obj;
new chai.Assertion(obj, preMsg + 'value').is.a('string');
new chai.Assertion(obj, preMsg + 'value').to.be.a.path();
new chai.Assertion(obj, preMsg + 'value').to.be.a.file();
new chai.Assertion(expected, preMsg + 'expected-value').is.a('string');
var content = fs.readFileSync(obj, 'utf8');
var pass = content === expected;
this.assert(
pass
, "expected #{this} to have content #{exp} but got #{act}"
, "expected #{this} not to have content #{exp}"
, expected
, content
);
};
var chainingBehavior = function(){
utils.flag(this, 'fs.content', true);
};
Assertion.addChainableMethod('content', contentMethod, chainingBehavior);
assert.fileContent = function (val, exp, msg) {
new chai.Assertion(val).to.have.content(exp, msg);
};
assert.notFileContent = function (val, exp, msg) {
new chai.Assertion(val).to.not.have.content(exp, msg);
};
};