debitoor / chai-subset

"containSubset" object properties matcher for Chai
http://chaijs.com/plugins/chai-subset/
MIT License
82 stars 20 forks source link

Behaviour difference between platforms #77

Open theophilusx opened 4 years ago

theophilusx commented 4 years ago

I'm using chai subset in some tests which compare the output from a directory listing. Under Linux, the tests were passing fine, but under Windows (win10), the comparison was failing. The issue turned out to be due to an ordering problem.

It seems that order within containsSubset does not matter under Linux, but does matter under win32. To fix the issue, I altered the ordering within the test and it works on both platforms. As this is different behavior based on platform differences (node vesions and chai/mocha vesions the same), I thought it should be reported.

Example

The following test was passing on Linux, but failing on win32

  it('Uploaded top-level files', async function() {
    let remoteDir = makeRemotePath(config.sftpUrl, 'upload-test');
    let fileList = await sftp.list(remoteDir);
    return expect(fileList).to.containSubset([
      {name: 'file1.txt', type: '-', size: 6973257},
      {name: 'file2.txt.gz', type: '-', size: 570314},
      {name: 'sub1', type: 'd'},
      {name: 'sub3', type: 'd'}
    ]);
  });

but changing it to the following and the test works on both platforms

  it('Uploaded top-level files', async function() {
    let remoteDir = makeRemotePath(config.sftpUrl, 'upload-test');
    let fileList = await sftp.list(remoteDir);
    return expect(fileList).to.containSubset([
      {name: 'file2.txt.gz', type: '-', size: 570314},
      {name: 'sub1', type: 'd'},
      {name: 'sub3', type: 'd'},
      {name: 'file1.txt', type: '-', size: 6973257}
    ]);
  });

Node version 12.14.1

"chai": "^4.2.0", "chai-as-promised": "^7.1.1", "chai-subset": "^1.6.0", "mocha": "^7.0.0",