Skip to content
Permalink
Browse files

Convert tests to use jest

  • Loading branch information...
legastero committed Aug 25, 2019
1 parent cc95cd3 commit 8cfa5c624db3b997151cc280f0f3d8f12c015f5e

Large diffs are not rendered by default.

@@ -13,7 +13,6 @@
"@types/node": "^12.7.1",
"@types/punycode": "^2.1.0",
"@types/readable-stream": "^2.3.3",
"@types/tape": "^4.2.33",
"@types/ws": "^6.0.2",
"async": "^3.0.1",
"node-fetch": "^2.6.0",
@@ -25,16 +24,18 @@
"ws": "^7.1.1"
},
"devDependencies": {
"@types/jest": "^24.0.18",
"expect": "^24.9.0",
"husky": "^3.0.3",
"nyc": "^14.1.1",
"jest": "^24.9.0",
"jest-mock": "^24.9.0",
"prettier": "^1.18.2",
"pretty-quick": "^1.11.0",
"rimraf": "^3.0.0",
"rollup": "^1.19.4",
"rollup-plugin-node-resolve": "^5.0.1",
"rollup-plugin-visualizer": "^2.5.4",
"tap-dot": "^2.0.0",
"tape": "^4.10.2",
"ts-jest": "^24.0.2",
"ts-node": "^8.2.0",
"tslint": "^5.17.0",
"tslint-sonarts": "^1.9.0",
@@ -50,6 +51,18 @@
"pre-commit": "pretty-quick --stage && npm run lint && npm test"
}
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testRegex": "test/.*\\.ts$",
"testMatch": null,
"collectCoverage": true,
"coverageDirectory": "./coverage",
"coverageReporters": [
"text",
"html"
]
},
"keywords": [
"jingle",
"stanza",
@@ -58,21 +71,6 @@
],
"license": "MIT",
"main": "./dist/cjs/index.js",
"nyc": {
"extension": [
".ts"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"**/*.d.ts"
],
"reporter": [
"html"
],
"all": true
},
"prettier": {
"tabWidth": 4,
"printWidth": 100,
@@ -96,7 +94,7 @@
"compile:webpack": "webpack --mode production",
"license-check": "npx license-checker --production --excludePrivatePackages --summary",
"lint": "tslint -p .",
"test": "nyc ts-node --files test/index.ts | tap-dot",
"test": "jest",
"validate": "npm ls"
},
"stanzajs_env_mappings": {
@@ -319,8 +319,12 @@ export default class Parser extends EventEmitter {
case State.ATTR_NAME: {
if (!isPrintable(c) || isWhitespace(c) || c === Character.Equal) {
this.attributeName = this.endRecording(data, pos);
pos--;
this.state = State.ATTR_EQ;
if (c === Character.Equal) {
this.state = State.ATTR_QUOTE;
} else {
pos--;
this.state = State.ATTR_EQ;
}
}
break;
}
@@ -346,8 +350,11 @@ export default class Parser extends EventEmitter {
this.attributeQuote = c;
this.state = State.ATTR_VALUE;
this.recordStart = pos + 1;
break;
}
break;

this.emit('error', JXTError.notWellFormed());
return;
}

case State.ATTR_VALUE: {
@@ -1,3 +1,4 @@
import expect from 'expect';
/**
* This file is derived from prior work.
*
@@ -7,12 +8,11 @@
* - sasl-digest-md5, Copyright © 2012-2013 Jared Hanson
*/

import test from 'tape';
import { DIGEST } from '../../src/lib/sasl';

// tslint:disable no-hardcoded-credentials

test('DIGEST-MD5', t => {
test('DIGEST-MD5', () => {
const mech = new DIGEST('DIGEST-MD5');

mech.processChallenge(
@@ -31,10 +31,7 @@ test('DIGEST-MD5', t => {
})!
.toString();

t.equal(
res,
expect(res).toBe(
'username="chris",realm="elwood.innosoft.com",nonce="OA6MG9tEQGm2hh",cnonce="OA6MHXh6VqTrRk",nc=00000001,qop=auth,digest-uri="imap/elwood.innosoft.com",response=d388dad90d4bbd760a152321f2143af7,charset=utf-8'
);

t.end();
});
@@ -1,9 +1,9 @@
import test from 'tape';
import expect from 'expect';
import { SCRAM } from '../../src/lib/sasl';

// tslint:disable no-hardcoded-credentials

test('SCRAM', t => {
test('SCRAM', () => {
const mech = new SCRAM('SCRAM-SHA-1');
const initial = mech
.createResponse({
@@ -12,7 +12,7 @@ test('SCRAM', t => {
username: 'chris'
})!
.toString();
t.equal(initial, 'n,,n=chris,r=MsQUY9iw0T9fx2MUEz6LZPwGuhVvWAhc');
expect(initial).toBe('n,,n=chris,r=MsQUY9iw0T9fx2MUEz6LZPwGuhVvWAhc');

mech.processChallenge(
Buffer.from(
@@ -27,10 +27,7 @@ test('SCRAM', t => {
username: 'chris'
})!
.toString();
t.equal(
res,
expect(res).toBe(
'c=biws,r=MsQUY9iw0T9fx2MUEz6LZPwGuhVvWAhc7b276f42-009a-40e2-84ee-8d5c8b206b6a,p=WKFCdDykcs73+CG653eG721vItw='
);

t.end();
});
@@ -1,8 +1,8 @@
import test from 'tape';
import expect from 'expect';
import * as stanza from '../src';

test('Connect using WebSocket', t => {
t.plan(1);
test('Connect using WebSocket', done => {
expect.assertions(1);

const client = stanza.createClient({
jid: 'anon@anon.stanzajs.org',
@@ -12,15 +12,16 @@ test('Connect using WebSocket', t => {
});

client.on('session:started', () => {
t.pass('Connected with WebSocket');
client.disconnect();
expect(true).toBe(true);
done();
});

client.connect();
});

test('Connect using BOSH', t => {
t.plan(1);
test('Connect using BOSH', done => {
expect.assertions(1);

const client = stanza.createClient({
jid: 'anon@anon.stanzajs.org',
@@ -30,8 +31,9 @@ test('Connect using BOSH', t => {
});

client.on('session:started', () => {
t.pass('Connected with BOSH');
client.disconnect();
expect(true).toBe(true);
done();
});

client.connect();
@@ -1,4 +1,4 @@
import test from 'tape';
import expect from 'expect';
import * as JXT from '../src/jxt';

import { getHostMeta } from '../src/plugins/hostmeta';
@@ -32,58 +32,57 @@ const json = {
subject: 'http://blog.example.com/article/id/314'
};

test('XRD', t => {
t.plan(2);
test('XRD', () => {
expect.assertions(2);

const xrd = registry.import(JXT.parse(xml))!;

t.equal(xrd.subject, json.subject);
t.deepEqual(xrd.links, json.links);
t.end();
expect(xrd.subject).toBe(json.subject);
expect(xrd.links).toEqual(json.links);
});

test('retrieve JSON only', t => {
t.plan(1);
test('retrieve JSON only', done => {
expect.assertions(1);

getHostMeta(registry, {
host: 'lance.im',
json: true,
xrd: false
}).then(hostmeta => {
t.ok(hostmeta.links.length > 0);
t.end();
expect(hostmeta.links.length > 0).toBeTruthy();
done();
});
});

test('retrieve XRD only', t => {
t.plan(1);
test('retrieve XRD only', done => {
expect.assertions(1);

getHostMeta(registry, {
host: 'lance.im',
json: false,
xrd: true
}).then(hostmeta => {
t.ok(hostmeta.links.length > 0);
t.end();
expect(hostmeta.links.length > 0).toBeTruthy();
done();
});
});

test('retrieve either', t => {
t.plan(1);
test('retrieve either', done => {
expect.assertions(1);
getHostMeta(registry, 'lance.im').then(hostmeta => {
t.ok(hostmeta.links.length > 0);
t.end();
expect(hostmeta.links.length > 0).toBeTruthy();
done();
});
});

test('missing host-meta', t => {
t.plan(1);
test('missing host-meta', done => {
expect.assertions(1);
getHostMeta(registry, {
host: 'dne.lance.im',
json: true,
xrd: true
}).catch(err => {
t.ok(err);
t.end();
expect(err).toBeTruthy();
done();
});
});

This file was deleted.

0 comments on commit 8cfa5c6

Please sign in to comment.
You can’t perform that action at this time.