GithubHelp home page GithubHelp logo

chai-fs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chai-fs's Issues

`chai-fs` destroys any existing assertion handler for `.with()`

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)

chai-fs impacts promise handling when loaded after chai-as-promised

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)

An in-range update of grunt is breaking the build 🚨


☝️ 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


The devDependency grunt was updated from 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.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v1.1.0
  • Update to mkdirp ~1.0.3
  • Only support versions of Node >= 8
Commits

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

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Behavior of to.be.a.directory()

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 !

Symlink check

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'
    )

Document that / is used instead of path.sep and allow using path.sep

The comment on

sep: '/' // Always use "/" path separators, so tests work consistently across platforms
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.

An in-range update of underscore is breaking the build 🚨


☝️ 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


The devDependency underscore was updated from 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.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

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

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Chai 3.4.0

Any chance this could be updated to work with Chai 3.4.0 please?

Thanks

Allow using path.sep as a path separator for directory contents assertions

The comment on

sep: '/' // Always use "/" path separators, so tests work consistently across platforms
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.

.to.not.be.a.file() not working

.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.

file().and.equal() not working as expected

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?

Can you push a new version to npm?

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.

Breaks Debugging on Webstorm

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

TypeError when chaining assertions after directory()

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

File with content

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:

  1. path - file path
  2. ?msg - text that I'm looking for
  3. data - ?

I can't see it in the documentation, if it is there, I'm sorry please send me the link.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.