Skip to content

Commit

Permalink
Fixes tests in windows (fixed mochajs#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
tswaters committed Feb 8, 2016
1 parent 2a85944 commit 06911ab
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 120 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@
"browser-stdout": "^1.2.0",
"browserify": "10.2.4",
"coffee-script": "~1.8.0",
"cross-spawn": "^2.1.5",
"eslint": "^1.2.1",
"os-tmpdir": "^1.0.1",
"should": "~8.0.0",
"through2": "~0.6.5"
},
Expand Down
4 changes: 3 additions & 1 deletion test/acceptance/fs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var fs = require('fs');
var path = require('path');
var osTmpDir = require('os-tmpdir');

describe('fs.readFile()', function(){
describe('when the file exists', function(){
it('should succeed', function(done){
fs.writeFile('/tmp/mocha', 'wahoo', done)
fs.writeFile(path.join(osTmpDir(), 'mocha'), 'wahoo', done)
})
})

Expand Down
27 changes: 16 additions & 11 deletions test/acceptance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,26 +373,31 @@ describe('lib/utils', function () {
describe('lookupFiles', function () {
var fs = require('fs'),
path = require('path'),
existsSync = fs.existsSync || path.existsSync;
osTmpDir = require('os-tmpdir'),
tmpDir = osTmpDir(),
existsSync = fs.existsSync || path.existsSync,
tmpFile = function (fileName) {
return path.join(tmpDir, fileName);
};

beforeEach(function () {
fs.writeFileSync('/tmp/mocha-utils.js', 'yippy skippy ying yang yow');
fs.symlinkSync('/tmp/mocha-utils.js', '/tmp/mocha-utils-link.js');
fs.writeFileSync(tmpFile('mocha-utils.js'), 'yippy skippy ying yang yow');
fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));
});

it('should not choke on symlinks', function () {
utils.lookupFiles('/tmp', ['js'], false)
.should.containEql('/tmp/mocha-utils-link.js')
.and.containEql('/tmp/mocha-utils.js')
utils.lookupFiles(tmpDir, ['js'], false)
.should.containEql(tmpFile('mocha-utils-link.js'))
.and.containEql(tmpFile('mocha-utils.js'))
.and.have.lengthOf(2);
existsSync('/tmp/mocha-utils-link.js').should.be.true();
fs.renameSync('/tmp/mocha-utils.js', '/tmp/bob');
existsSync('/tmp/mocha-utils-link.js').should.be.false();
utils.lookupFiles('/tmp', ['js'], false).should.eql([]);
existsSync(tmpFile('mocha-utils-link.js')).should.be.true();
fs.renameSync(tmpFile('mocha-utils.js'), tmpFile('bob'));
existsSync(tmpFile('mocha-utils-link.js')).should.be.false();
utils.lookupFiles(tmpDir, ['js'], false).should.eql([]);
});

afterEach(function () {
['/tmp/mocha-utils.js', '/tmp/mocha-utils-link.js', '/tmp/bob'].forEach(function (path) {
[tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'), tmpFile('bob')].forEach(function (path) {
try {
fs.unlinkSync(path);
}
Expand Down
2 changes: 1 addition & 1 deletion test/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('Mocha', function() {
this.timeout(1000);

it('should not output colors to pipe', function(cb) {
var command = 'bin/mocha --grep missing-test';
var command = 'node bin/mocha --grep missing-test';
child_process.exec(command, function(err, stdout, stderr) {
if (err) return cb(err);

Expand Down
78 changes: 39 additions & 39 deletions test/integration/fixtures/hooks/multiple.hook.async.error.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,54 @@ describe('1', function () {
console.log('1 before each');
});

describe('1.1', function () {
describe('1-1', function () {
before(function () {
console.log('1.1 before');
console.log('1-1 before');
});
beforeEach(function (done) {
console.log('1.1 before each');
console.log('1-1 before each');
process.nextTick(function () {
throw new Error('1.1 before each hook failed');
throw new Error('1-1 before each hook failed');
});
});
it('1.1 test 1', function () {
console.log('1.1 test 1');
it('1-1 test 1', function () {
console.log('1-1 test 1');
});
it('1.1 test 2', function () {
console.log('1.1 test 2');
it('1-1 test 2', function () {
console.log('1-1 test 2');
});
afterEach(function () {
console.log('1.1 after each');
console.log('1-1 after each');
});
after(function (done) {
console.log('1.1 after');
console.log('1-1 after');
process.nextTick(function () {
throw new Error('1.1 after hook failed');
throw new Error('1-1 after hook failed');
});
});
});

describe('1.2', function () {
describe('1-2', function () {
before(function () {
console.log('1.2 before');
console.log('1-2 before');
});
beforeEach(function () {
console.log('1.2 before each');
console.log('1-2 before each');
});
it('1.2 test 1', function () {
console.log('1.2 test 1');
it('1-2 test 1', function () {
console.log('1-2 test 1');
});
it('1.2 test 2', function () {
console.log('1.2 test 2');
it('1-2 test 2', function () {
console.log('1-2 test 2');
});
afterEach(function (done) {
console.log('1.2 after each');
console.log('1-2 after each');
process.nextTick(function () {
throw new Error('1.2 after each hook failed');
throw new Error('1-2 after each hook failed');
});
});
after(function () {
console.log('1.2 after');
console.log('1-2 after');
});
});

Expand All @@ -77,45 +77,45 @@ describe('2', function () {
});
});

describe('2.1', function () {
describe('2-1', function () {
before(function () {
console.log('2.1 before');
console.log('2-1 before');
});
beforeEach(function () {
console.log('2.1 before each');
console.log('2-1 before each');
});
it('2.1 test 1', function () {
console.log('2.1 test 1');
it('2-1 test 1', function () {
console.log('2-1 test 1');
});
it('2.1 test 2', function () {
console.log('2.1 test 2');
it('2-1 test 2', function () {
console.log('2-1 test 2');
});
afterEach(function () {
console.log('2.1 after each');
console.log('2-1 after each');
});
after(function () {
console.log('2.1 after');
console.log('2-1 after');
});
});

describe('2.2', function () {
describe('2-2', function () {
before(function () {
console.log('2.2 before');
console.log('2-2 before');
});
beforeEach(function () {
console.log('2.2 before each');
console.log('2-2 before each');
});
it('2.2 test 1', function () {
console.log('2.2 test 1');
it('2-2 test 1', function () {
console.log('2-2 test 1');
});
it('2.2 test 2', function () {
console.log('2.2 test 2');
it('2-2 test 2', function () {
console.log('2-2 test 2');
});
afterEach(function () {
console.log('2.2 after each');
console.log('2-2 after each');
});
after(function () {
console.log('2.2 after');
console.log('2-2 after');
});
});

Expand Down
78 changes: 39 additions & 39 deletions test/integration/fixtures/hooks/multiple.hook.error.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,48 @@ describe('1', function () {
console.log('1 before each');
});

describe('1.1', function () {
describe('1-1', function () {
before(function () {
console.log('1.1 before');
console.log('1-1 before');
});
beforeEach(function () {
console.log('1.1 before each');
throw new Error('1.1 before each hook failed');
console.log('1-1 before each');
throw new Error('1-1 before each hook failed');
});
it('1.1 test 1', function () {
console.log('1.1 test 1');
it('1-1 test 1', function () {
console.log('1-1 test 1');
});
it('1.1 test 2', function () {
console.log('1.1 test 2');
it('1-1 test 2', function () {
console.log('1-1 test 2');
});
afterEach(function () {
console.log('1.1 after each');
console.log('1-1 after each');
});
after(function () {
console.log('1.1 after');
throw new Error('1.1 after hook failed');
console.log('1-1 after');
throw new Error('1-1 after hook failed');
});
});

describe('1.2', function () {
describe('1-2', function () {
before(function () {
console.log('1.2 before');
console.log('1-2 before');
});
beforeEach(function () {
console.log('1.2 before each');
console.log('1-2 before each');
});
it('1.2 test 1', function () {
console.log('1.2 test 1');
it('1-2 test 1', function () {
console.log('1-2 test 1');
});
it('1.2 test 2', function () {
console.log('1.2 test 2');
it('1-2 test 2', function () {
console.log('1-2 test 2');
});
afterEach(function () {
console.log('1.2 after each');
throw new Error('1.2 after each hook failed');
console.log('1-2 after each');
throw new Error('1-2 after each hook failed');
});
after(function () {
console.log('1.2 after');
console.log('1-2 after');
});
});

Expand All @@ -69,45 +69,45 @@ describe('2', function () {
throw new Error('2 before each hook failed');
});

describe('2.1', function () {
describe('2-1', function () {
before(function () {
console.log('2.1 before');
console.log('2-1 before');
});
beforeEach(function () {
console.log('2.1 before each');
console.log('2-1 before each');
});
it('2.1 test 1', function () {
console.log('2.1 test 1');
it('2-1 test 1', function () {
console.log('2-1 test 1');
});
it('2.1 test 2', function () {
console.log('2.1 test 2');
it('2-1 test 2', function () {
console.log('2-1 test 2');
});
afterEach(function () {
console.log('2.1 after each');
console.log('2-1 after each');
});
after(function () {
console.log('2.1 after');
console.log('2-1 after');
});
});

describe('2.2', function () {
describe('2-2', function () {
before(function () {
console.log('2.2 before');
console.log('2-2 before');
});
beforeEach(function () {
console.log('2.2 before each');
console.log('2-2 before each');
});
it('2.2 test 1', function () {
console.log('2.2 test 1');
it('2-2 test 1', function () {
console.log('2-2 test 1');
});
it('2.2 test 2', function () {
console.log('2.2 test 2');
it('2-2 test 2', function () {
console.log('2-2 test 2');
});
afterEach(function () {
console.log('2.2 after each');
console.log('2-2 after each');
});
after(function () {
console.log('2.2 after');
console.log('2-2 after');
});
});

Expand Down
12 changes: 9 additions & 3 deletions test/integration/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var spawn = require('child_process').spawn;
var spawn = require('cross-spawn');
var path = require('path');
var fs = require('fs');
var baseReporter = require('../../lib/reporters/base');

module.exports = {
/**
Expand Down Expand Up @@ -142,14 +143,19 @@ module.exports = {
return diffs.map(function(diff) {
return diff.slice(1, -3).join('\n');
});
}
},

/**
* regular expression used for splitting lines based on new line / dot symbol.
*/
splitRegExp: new RegExp('[\n' + baseReporter.symbols.dot + ']+')
};

function invokeMocha(args, fn) {
var output, mocha, listener;

output = '';
mocha = spawn('./bin/mocha', args);
mocha = spawn('bin/mocha', args);

listener = function(data) {
output += data;
Expand Down
Loading

0 comments on commit 06911ab

Please sign in to comment.