From 56912bcc1d798454deb7912ff3bed1e7dde0caa2 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 31 Mar 2017 12:02:53 -0700 Subject: [PATCH 1/3] Fix encoding test --- test/unixTerminal.test.js | 19 ++++++++++--------- test/utf8-sentence.txt | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 test/utf8-sentence.txt diff --git a/test/unixTerminal.test.js b/test/unixTerminal.test.js index 0c7e410..db2d422 100644 --- a/test/unixTerminal.test.js +++ b/test/unixTerminal.test.js @@ -33,8 +33,8 @@ describe("UnixTerminal", function() { }); it("should return a Buffer when encoding is null", function(done) { const term = new UnixTerminal(null, [ '-c', 'cat "' + __dirname + '/utf8-character.txt"' ], { - encoding: null, - }); + encoding: null, + }); term.on('data', function(data) { assert.equal(typeof data, 'object'); assert.ok(data instanceof Buffer); @@ -44,16 +44,17 @@ describe("UnixTerminal", function() { }); }); it("should support other encodings", function(done) { - const term = new UnixTerminal(null, [ '-c', 'cat "' + __dirname + '/utf8-sentence.txt"' ], { - encoding: 'base64' - }); - var buf = ''; + const text = 'test æ!'; + const term = new UnixTerminal(null, ['-c', 'echo "' + text + '"'], { + encoding: 'base64' + }); + let buffer = ''; term.on('data', function(data) { assert.equal(typeof data, 'string'); - buf += data; + buffer += data; }); - term.on('close', function() { - assert.equal(buf, 'SGV5LCDDpiEgV2hhZGR1cD8='); + term.on('exit', function() { + assert.equal(buffer, new Buffer(text + '\r').toString('base64')); done(); }); }); diff --git a/test/utf8-sentence.txt b/test/utf8-sentence.txt deleted file mode 100644 index 5e99e45..0000000 --- a/test/utf8-sentence.txt +++ /dev/null @@ -1 +0,0 @@ -Hey, æ! Whaddup? \ No newline at end of file From a136ad8d2855d039be4cbedb5b5b91808d6868fe Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 31 Mar 2017 13:32:34 -0700 Subject: [PATCH 2/3] Tweak assertion --- test/unixTerminal.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unixTerminal.test.js b/test/unixTerminal.test.js index db2d422..fc3f470 100644 --- a/test/unixTerminal.test.js +++ b/test/unixTerminal.test.js @@ -54,7 +54,7 @@ describe("UnixTerminal", function() { buffer += data; }); term.on('exit', function() { - assert.equal(buffer, new Buffer(text + '\r').toString('base64')); + assert.equal(new Buffer(buffer, 'base64').toString().replace('\r', ''), text); done(); }); }); From dafdac23ad35654bc2d679968fadf9ade8c607cf Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 31 Mar 2017 13:36:13 -0700 Subject: [PATCH 3/3] Strip \n, we don't care --- test/unixTerminal.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unixTerminal.test.js b/test/unixTerminal.test.js index fc3f470..8e41cd2 100644 --- a/test/unixTerminal.test.js +++ b/test/unixTerminal.test.js @@ -54,7 +54,7 @@ describe("UnixTerminal", function() { buffer += data; }); term.on('exit', function() { - assert.equal(new Buffer(buffer, 'base64').toString().replace('\r', ''), text); + assert.equal(new Buffer(buffer, 'base64').toString().replace('\r', '').replace('\n', ''), text); done(); }); });