chaijs / chai-fs Goto Github PK
View Code? Open in Web Editor NEWChai assertions for Node.js filesystem
License: MIT License
Chai assertions for Node.js filesystem
License: MIT License
Any chance this could be updated to work with Chai 3.4.0 please?
Thanks
The comment on
claims that/
is hard-coded to make test portable. This, in fact, makes the test less portable as we use path.join
in our tests. This should be documented.
I disagree with the stance taken, but I understand why it was done. Instead of changing it (a breaking change), I propose making it overridable with an option - e.g. usePathSep
or something to that effect (whose default value would result in the current behavior).
In addition Further, the current behavior should be documented.
The comment on
claims that/
is hard-coded to make tests portable. (In our case, this actually makes our tests less portable as we use path.join
in our tests to get behavior closer to the OS we're running on.)
This choice should be documented (it was a surprise when it failed in Windows tests during CI).
Bonus points: making this overridable with a configuration option somewhere (e.g. usePathSep
or something to that effect, whose default value would result in the current behavior) would ensure existing tests still work, but people writing code intended for multiple OSes can write tests more easily if they choose to use path.join
in their test code.
βοΈ Important announcement: Greenkeeper will be saying goodbye π and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io
1.0.4
to 1.1.0
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
grunt is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 8 commits.
d5cdac0
Merge pull request #1706 from gruntjs/tag-neew
4674c59
v1.1.0
6124409
Merge pull request #1705 from gruntjs/mkdirp-update
0a66968
Fix up Buffer usage
4bfa98e
Support versions of node >= 8
f1898eb
Update to mkdirp ~1.0.3
75da17b
HTTPS link to gruntjs.com (#1683)
6795d31
Update js-yaml dependecy to ~3.13.1 (#1680)
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
I'm trying to write an assertion checking that a directory exists and contains some files. Here's what I have:
expect(path).to.be.a.directory().and.include.files(fileList);
When the tests run, it throws a TypeError:
Uncaught TypeError: expect(...).to.be.a.directory(...).and.include.files is not a function
at Test.<anonymous> (test/integration/site.spec.js:47:58)
at Test.assert (node_modules/supertest/lib/test.js:161:6)
at Server.assert (node_modules/supertest/lib/test.js:131:12)
at emitCloseNT (net.js:1525:8)
at _combinedTickCallback (internal/process/next_tick.js:71:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
When I remove the additional .and.include.files
chain, the test passes successfully:
expect(path).to.be.a.directory();
It seems there may have been some kind of regression around the directory()
function. I pulled down the project and ran the tests manually. It stopped after 32 failed tests and they all seem to relate to the directory function.
-> failed 32 and passed 967 of 999 tests, left 28 pending (723ms)
Is this a problem with my local environment? Can anyone else reproduce this behavior?
Thanks
When using both chai-fs and chai-as-promised, promises start returning before being handled, kind of like when you run an async test without done
.
I'm not sure which side the issues sits with so have raised it on both
Example test:
const chai = require('chai')
const expect = chai.expect
chai.should()
chai.use(require('chai-as-promised'))
chai.use(require('chai-fs'))
describe('resolve', function(){
it('expect', function(){
return expect( Promise.resolve('two') ).to.eventually.equal('one')
})
it('should', function(){
return Promise.resolve('two').should.eventually.equal('one')
})
})
Results in promises being rejected but not handled by mocha:
β β mocha
resolve
β shouldn't resolve
(node:79302) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: expected 'two' to equal 'one'
β shouldn't resolve
(node:79302) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): AssertionError: expected 'two' to equal 'one'
2 passing (16ms)
Swapping the order and loading chai-fs
first:
chai.use(require('chai-fs'))
chai.use(require('chai-as-promised'))
Results in the normal promise handling behaviour:
β β mocha
resolve
1) expect
2) should
0 passing (16ms)
2 failing
1) resolve expect:
AssertionError: expected 'two' to equal 'one'
+ expected - actual
-two
+one
at getBasePromise.then.then.newArgs (node_modules/chai-as-promised/lib/chai-as-promised.js:302:22)
2) resolve should:
AssertionError: expected 'two' to equal 'one'
+ expected - actual
-two
+one
at getBasePromise.then.then.newArgs (node_modules/chai-as-promised/lib/chai-as-promised.js:302:22)
The current version on npm is 0.1.0 which still has a peer dependency on chai < 2. Chai is up to 3.5 now. I know I can just reference the master branch, but updating npm would be value add for developers.
The package chai does not satisfy its siblings' peerDependencies requirements!
peerinvalid Peer [email protected] wants chai@>= 1.6.1 < 2
I'll look into fixing this up with a pull request right now.
A check for symlinks could be useful. As a starting point, this is what I'm currently using (CoffeeScript):
fs = require('fs')
module.exports = (chai, utils) ->
# expect(path).to.be.a.symlink()
# expect(path).not.to.be.a.symlink()
chai.Assertion.addMethod 'symlink', ->
try
isSymlink = fs.lstatSync(this._obj).isSymbolicLink()
catch err
# If it doesn't exist, it's clearly not a symlink
if err.code == 'ENOENT'
isSymlink = false
else
throw err
this.assert(
isSymlink,
'expected #{this} to be a symlink',
'expected #{this} not to be a symlink'
)
βοΈ Important announcement: Greenkeeper will be saying goodbye π and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io
1.9.2
to 1.10.0
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
underscore is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 46 commits.
985fce6
Underscore.js v1.10.0
fa2c1f8
Merge pull request #2834 from jashkenas/prepare-1.10
e8da73c
Add source map of the uncompressed UMD bundle to the publication files
44cfe25
Update the license date range
6b09e0e
Remove the context parameter from the rollup config
accd8b1
Add link to source map of uncompressed UMD bundle in Download section
7b32e0b
Update the weight in the Downloads section
e1a5518
Bump the version number in the documentation and source code
d18f67f
Mention the removal of Component support
361a352
Include #2826 in the changelog, installation and noConflict sections
948f3c9
Include #2831 in the changelog and the installation section
5a4d81f
Include #2829 in the changelog
c92e961
Include #2825 in the changelog
4990d19
Include #2820 in the changelog
2552702
Fix the documentation link of the previous changelog entry
There are 46 commits in total.
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
So for one of my test cases, my setup process (before() hook) is to copy a directory from one place to another. My application code is then supposed to analyze the copied location and either modify files in that directory or not based on params, so I'm working on testing behavior against a range of inputs.
Without actually running my application code yet, I decided to test chai-fs's behavior to make sure that I am using the right assertion, so that if I don't get what I expect I at least know it's my app code and not the assertion library that's causing me grief.
Well... here's how that worked out.
As I said I did a full directory copy from 'a' to a new directory 'b'. I visually inspected to make sure file 'filename' exists in both directories and it looks identical visually. If I run:
expect('./a/filename').to.be.a.file('It is a file').and.equal('./b/filename', 'Nope, files are not the same');
I get an assertion error that the expectation failed (and the second message is the one that shows up). Not sure how these two files can have different content when the one file was copied unmodified from the other file just before the test.
Any idea how to debug this, or is this feature not fully implemented yet?
In my case, this is causing issues with chai-spies
. For example, this passes fine:
let spies = require("chai-spies");
let fs = require("chai-fs");
let chai = require("chai");
chai.use(fs).use(spies);
let { spy, expect } = chai;
it("should still let me use chai-spies' .with() assertions", async () => {
let fn = spy((arg) => arg + 1);
let x = fn(2);
expect(x).to.equal(3);
expect(fn).to.have.been.called.once;
expect(fn).to.have.been.called.with(2);
});
But this fails:
let spies = require("chai-spies");
let fs = require("chai-fs");
let chai = require("chai");
chai.use(spies).use(fs); // <--- the only change is the order on this line
let { spy, expect } = chai;
it("should still let me use chai-spies' .with() assertions", async () => {
let fn = spy((arg) => arg + 1);
let x = fn(2);
expect(x).to.equal(3);
expect(fn).to.have.been.called.once;
expect(fn).to.have.been.called.with(2);
});
Output:
1) should still let me use chai-spies' .with() assertions:
TypeError: expect(...).to.have.been.called.with is not a function
at Context.it (spec.js:18:37)
The chai-fs
package on npm hasn't been updated since the project was transferred from @Bartvds to @chaijs/chai two years ago. π©
@keithamus - Not sure what exactly needs to be done to get the npm package updated. I'm happy to help if I can.
Hi Guys,
This is not actually an issue, just wondering what am I suppose to pass in data in this code?
expect(path).to.be.a.file(?msg).with.content(data, ?msg);
correct me if I'm wrong:
I can't see it in the documentation, if it is there, I'm sorry please send me the link.
Thanks!
When using the following line, Webstorm's debugging of mocha tests fails with an exit code of 130.
chai.use(require('chai-fs'))
The only workaround I've found thus far is to remove chai-fs from my unit tests.
Logs:
/usr/local/bin/node --debug-brk=54452 /usr/local/lib/node_modules/mocha/bin/_mocha --timeout 259200000 --ui bdd --reporter /Applications/WebStorm.app/Contents/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js /Users/username/Documents/project/test/simple-test.js --grep "simple test$"
Debugger listening on port 54452
Process finished with exit code 130
Node: v5.6.0
Chai: v3.5.0
Chai-fs: v0.1.0
.to.not.be.a.file()
does not work, returns true, even if the file is not existing, example:
expect( path.join( __dirname, './tmp/lessReduce/root.css' ) ).to.not.be.a.file();
... but the file is definitely not there ... but throws an asserting exception.
Is this the right behavior ?
// existentDir is a directory that exists
expect(existentDir).to.be.a.directory() => true, ok
// nonExistentDir is a directory that doesn't exists
expect(nonExistentDir).to.not.be.a.path() => true, ok
expect(nonExistentDir).to.not.be.a.directory() => false ?
If a directory doesn't exist shouldn't "to.not.be.a.directory()" gives false?
Thanks !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.