Skip to content

Commit

Permalink
Merge bf03bd9 into 1051fcd
Browse files Browse the repository at this point in the history
  • Loading branch information
Bin Zhang committed Nov 1, 2016
2 parents 1051fcd + bf03bd9 commit ff374ad
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"globals": {
"beforeEach": true,
"afterEach": true,
"before": true,
"after": true,
"describe": true,
"it": true
}
Expand Down
77 changes: 77 additions & 0 deletions test/unit/chinesePath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict';

var assert = require('assert');
var fixtures = require('../fixtures');
var sharp = require('../../index');
var fs = require('fs');

var testImgPath = fixtures.path('bandbool.png');
var chineseImgPath = fixtures.path('中文名称.png');

function copyFile(source, target, cb) {
var cbCalled = false;

var rd = fs.createReadStream(source);
rd.on("error", function(err) {
done(err);
});
var wr = fs.createWriteStream(target);
wr.on("error", function(err) {
done(err);
});
wr.on("close", function(ex) {
done();
});
rd.pipe(wr);

function done(err) {
if (!cbCalled) {
cb(err);
cbCalled = true;
}
}
}

describe('File path with Chinese characters', function() {

before(function ( done ) {
if (fs.existsSync(chineseImgPath)) {
fs.unlinkSync(chineseImgPath);
}
copyFile(testImgPath, chineseImgPath, function(err) {
if (err) {
throw err;
}
done();
});
});

after( function ( done ) {
if (fs.existsSync(chineseImgPath)) {
fs.unlinkSync(chineseImgPath);
}
done();
});

it('File path without Chinese characters', function(done) {
sharp(testImgPath)
.raw()
.toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(200, info.width);
assert.strictEqual(200, info.height);
done();
});
});

it('File path with Chinese characters', function(done) {
sharp(chineseImgPath)
.raw()
.toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(200, info.width);
assert.strictEqual(200, info.height);
done();
});
});
});

0 comments on commit ff374ad

Please sign in to comment.