Skip to content

Commit

Permalink
Fixed tests by calling fs.readFileSync to synchronously read file con…
Browse files Browse the repository at this point in the history
…tent.
  • Loading branch information
djiao committed Nov 20, 2015
1 parent 84b188b commit c5d1f14
Showing 1 changed file with 29 additions and 35 deletions.
64 changes: 29 additions & 35 deletions test/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ describe('transform', function () {
});

it('should stringify the records with callback', function(done) {
fs.readFile('test/data/PGA_2records.mrc', function(err, data) {
transform(records, function(err, output) {
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
var data = fs.readFileSync('test/data/PGA_2records.mrc');
transform(records, function(err, output) {
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
});

Expand All @@ -61,11 +60,10 @@ describe('transform', function () {
console.log(err.message);
});
transformer.on('end', function() {
fs.readFile('test/data/PGA_2records.mrc', function(err, data) {
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
var data = fs.readFileSync('test/data/PGA_2records.mrc');
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
records.forEach(function(record) {
transformer.write(record);
Expand All @@ -87,11 +85,10 @@ describe('transform', function () {
console.log(err.message);
});
transformer.on('end', function() {
fs.readFile('test/data/PGA_2records.mrc', function(err, data) {
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
var data = fs.readFileSync('test/data/PGA_2records.mrc');
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
records.forEach(function(record) {
transformer.write(record);
Expand All @@ -115,13 +112,12 @@ describe('transform', function () {
});

it('should textify the records with callback', function(done) {
fs.readFile('test/data/PGA_2records.mrk', function(err, data) {
data = data.toString().replace(/\r\n?/g, os.EOL) + os.EOL;
transform(records, {toFormat: 'text'}, function(err, output) {
expect(output.length).equal(data.length);
expect(output).equal(data);
done();
});
var data = fs.readFileSync('test/data/PGA_2records.mrk');
data = data.toString().replace(/\r\n?/g, os.EOL) + os.EOL;
transform(records, {toFormat: 'text'}, function(err, output) {
expect(output.length).equal(data.length);
expect(output).equal(data);
done();
});
});

Expand All @@ -142,12 +138,11 @@ describe('transform', function () {
console.log(err.message);
});
textifier.on('end', function() {
fs.readFile('test/data/PGA_2records.mrk', function(err, data) {
data = data.toString().replace(/\r\n?/g, os.EOL) + os.EOL;
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
var data = fs.readFileSync('test/data/PGA_2records.mrk');
data = data.toString().replace(/\r\n?/g, os.EOL) + os.EOL;
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
records.forEach(function(record) {
textifier.write(record);
Expand All @@ -169,12 +164,11 @@ describe('transform', function () {
console.log(err.message);
});
textifier.on('end', function() {
fs.readFile('test/data/PGA_2records.mrk', function(err, data) {
data = data.toString().replace(/\r\n?/g, os.EOL) + os.EOL;
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
var data = fs.readFileSync('test/data/PGA_2records.mrk');
data = data.toString().replace(/\r\n?/g, os.EOL) + os.EOL;
expect(output.length).equal(data.length);
expect(output).equal(data.toString());
done();
});
records.forEach(function(record) {
textifier.write(record);
Expand Down

0 comments on commit c5d1f14

Please sign in to comment.