Skip to content

Commit c10929e

Browse files
committed
test: convert test suite from CoffeeScript to JavaScript
1 parent 1758294 commit c10929e

File tree

6 files changed

+108
-66
lines changed

6 files changed

+108
-66
lines changed

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: node_js
33
node_js:
44
- "0.10"
55
- "0.12"
6-
- "4.0"
7-
- "4.1"
6+
- "4"
7+
- "10"
88
install: make setup
9-
script: make test
9+
script: make lint test

Makefile

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
ESLINT = node_modules/.bin/eslint
12
ISTANBUL = node_modules/.bin/istanbul
23
UGLIFYJS = node_modules/.bin/uglifyjs
34
XYZ = node_modules/.bin/xyz --message X.Y.Z --tag X.Y.Z --repo [email protected]:davidchambers/Base64.js.git --script scripts/prepublish
@@ -23,6 +24,20 @@ clean:
2324
rm -f -- $(MIN)
2425

2526

27+
.PHONY: lint
28+
lint:
29+
@if [ $(shell node --version | tr -d v | cut -d . -f 1) -lt 6 ] ; then \
30+
echo 'ESLint requires a recent version of Node' ; \
31+
else \
32+
$(ESLINT) \
33+
--config node_modules/sanctuary-style/eslint-es3.json \
34+
--env node \
35+
--global describe \
36+
--global it \
37+
-- test/*.js ; \
38+
fi
39+
40+
2641
.PHONY: release-major release-minor release-patch
2742
release-major release-minor release-patch:
2843
@$(XYZ) --increment $(@:release-%=%)
@@ -35,4 +50,4 @@ setup:
3550

3651
.PHONY: test
3752
test:
38-
$(ISTANBUL) cover node_modules/.bin/_mocha -- --compilers coffee:coffee-script/register
53+
$(ISTANBUL) cover node_modules/.bin/_mocha -- --reporter spec

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
"url": "git://github.com/davidchambers/Base64.js.git"
1111
},
1212
"devDependencies": {
13-
"coffee-script": "1.8.x",
1413
"debug": "3.2.x",
14+
"eslint": "4.9.x",
1515
"istanbul": "0.2.x",
1616
"mocha": "1.18.x",
17+
"sanctuary-style": "2.0.x",
1718
"uglify-js": "2.4.x",
1819
"xyz": "1.0.x"
1920
},

test/base64.coffee

-61
This file was deleted.

test/base64.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
'use strict';
2+
3+
var assert = require ('assert');
4+
5+
var base64 = require ('..');
6+
7+
8+
var btoa = base64.btoa;
9+
var atob = base64.atob;
10+
11+
12+
describe ('Base64.js', function() {
13+
14+
it ('can encode ASCII input', function() {
15+
assert.strictEqual (btoa (''), '');
16+
assert.strictEqual (btoa ('f'), 'Zg==');
17+
assert.strictEqual (btoa ('fo'), 'Zm8=');
18+
assert.strictEqual (btoa ('foo'), 'Zm9v');
19+
assert.strictEqual (btoa ('quux'), 'cXV1eA==');
20+
assert.strictEqual (btoa ('!"#$%'), 'ISIjJCU=');
21+
assert.strictEqual (btoa ("&'()*+"), 'JicoKSor');
22+
assert.strictEqual (btoa (',-./012'), 'LC0uLzAxMg==');
23+
assert.strictEqual (btoa ('3456789:'), 'MzQ1Njc4OTo=');
24+
assert.strictEqual (btoa (';<=>?@ABC'), 'Ozw9Pj9AQUJD');
25+
assert.strictEqual (btoa ('DEFGHIJKLM'), 'REVGR0hJSktMTQ==');
26+
assert.strictEqual (btoa ('NOPQRSTUVWX'), 'Tk9QUVJTVFVWV1g=');
27+
assert.strictEqual (btoa ('YZ[\\]^_`abc'), 'WVpbXF1eX2BhYmM=');
28+
assert.strictEqual (btoa ('defghijklmnop'), 'ZGVmZ2hpamtsbW5vcA==');
29+
assert.strictEqual (btoa ('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4=');
30+
});
31+
32+
it ('cannot encode non-ASCII input', function() {
33+
assert.throws (
34+
function() { btoa ('✈'); },
35+
function(err) {
36+
return err instanceof Error &&
37+
err.name === 'InvalidCharacterError' &&
38+
err.message === ("'btoa' failed: " +
39+
'The string to be encoded contains ' +
40+
'characters outside of the Latin1 range.');
41+
}
42+
);
43+
});
44+
45+
it ('coerces input', function() {
46+
assert.strictEqual (btoa (42), btoa ('42'));
47+
assert.strictEqual (btoa (null), btoa ('null'));
48+
assert.strictEqual (btoa ({x: 1}), btoa ('[object Object]'));
49+
});
50+
51+
it ('can decode Base64-encoded input', function() {
52+
assert.strictEqual (atob (''), '');
53+
assert.strictEqual (atob ('Zg=='), 'f');
54+
assert.strictEqual (atob ('Zm8='), 'fo');
55+
assert.strictEqual (atob ('Zm9v'), 'foo');
56+
assert.strictEqual (atob ('cXV1eA=='), 'quux');
57+
assert.strictEqual (atob ('ISIjJCU='), '!"#$%');
58+
assert.strictEqual (atob ('JicoKSor'), "&'()*+");
59+
assert.strictEqual (atob ('LC0uLzAxMg=='), ',-./012');
60+
assert.strictEqual (atob ('MzQ1Njc4OTo='), '3456789:');
61+
assert.strictEqual (atob ('Ozw9Pj9AQUJD'), ';<=>?@ABC');
62+
assert.strictEqual (atob ('REVGR0hJSktMTQ=='), 'DEFGHIJKLM');
63+
assert.strictEqual (atob ('Tk9QUVJTVFVWV1g='), 'NOPQRSTUVWX');
64+
assert.strictEqual (atob ('WVpbXF1eX2BhYmM='), 'YZ[\\]^_`abc');
65+
assert.strictEqual (atob ('ZGVmZ2hpamtsbW5vcA=='), 'defghijklmnop');
66+
assert.strictEqual (atob ('cXJzdHV2d3h5ent8fX4='), 'qrstuvwxyz{|}~');
67+
});
68+
69+
it ('cannot decode invalid input', function() {
70+
assert.throws (
71+
function() { atob ('a'); },
72+
function(err) {
73+
return err instanceof Error &&
74+
err.name === 'InvalidCharacterError' &&
75+
err.message === ("'atob' failed: The string to be " +
76+
'decoded is not correctly encoded.');
77+
}
78+
);
79+
});
80+
81+
it ('coerces input', function() {
82+
assert.strictEqual (atob (42), atob ('42'));
83+
assert.strictEqual (atob (null), atob ('null'));
84+
});
85+
86+
});

0 commit comments

Comments
 (0)