Skip to content

Commit 361e36f

Browse files
Say hello to Vitest
1 parent 714b7b8 commit 361e36f

20 files changed

+822
-769
lines changed

package.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,8 @@
6363
"@semantic-release/changelog": "^6.0.3",
6464
"@semantic-release/git": "^10.0.1",
6565
"@types/base64-js": "^1.3.0",
66-
"@types/chai": "^4.2.15",
67-
"@types/chai-arrays": "^2.0.0",
68-
"@types/chai-as-promised": "^7.1.4",
69-
"@types/chai-like": "^1.1.1",
70-
"@types/mocha": "^10.0.10",
71-
"@types/node": "^22.13.5",
7266
"@types/sinon": "^10.0.6",
7367
"@types/uuid": "^10.0.0",
74-
"chai": "^4.3.4",
75-
"chai-arrays": "^2.2.0",
76-
"chai-as-promised": "^7.1.1",
77-
"chai-like": "^1.1.1",
78-
"chai-sorted": "^0.2.0",
7968
"concurrently": "^9.1.2",
8069
"conventional-changelog-conventionalcommits": "^8.0.0",
8170
"dotenv": "^8.2.0",
@@ -85,16 +74,15 @@
8574
"globals": "^16.0.0",
8675
"husky": "^4.3.8",
8776
"lint-staged": "^15.2.2",
88-
"mocha": "^11.1.0",
8977
"nyc": "^15.1.0",
9078
"prettier": "^3.5.2",
9179
"semantic-release": "^24.2.3",
9280
"sinon": "^12.0.1",
93-
"ts-node": "^10.9.2",
9481
"tslib": "^2.8.1",
9582
"typescript": "^5.7.3",
9683
"typescript-eslint": "^8.25.0",
97-
"uuid": "^11.1.0"
84+
"uuid": "^11.1.0",
85+
"vitest": "^3.0.7"
9886
},
9987
"scripts": {
10088
"build": "rm -rf dist && yarn bundle",
@@ -110,7 +98,7 @@
11098
"test": "yarn test-unit",
11199
"testwatch": "NODE_ENV=test nodemon ./node_modules/.bin/mocha --timeout 20000 --require test-entry.js test/test.js",
112100
"test-types": "node test/typescript/index.js && tsc --esModuleInterop true --noEmit true --strictNullChecks true --noImplicitAny true --strict true test/typescript/*.ts",
113-
"test-unit": "NODE_ENV=test TS_NODE_PROJECT=tsconfig.test.json mocha test/unit/*.{js,test.ts}",
101+
"test-unit": "vitest test/unit/* --run",
114102
"test-coverage": "nyc yarn test-unit",
115103
"fix-staged": "lint-staged --config .lintstagedrc.fix.json --concurrent 1",
116104
"semantic-release": "semantic-release",
Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import chai from 'chai';
21
import { v4 as uuidv4 } from 'uuid';
32

43
import { generateChannel } from './test-utils/generateChannel';
@@ -13,7 +12,7 @@ import { mockChannelQueryResponse } from './test-utils/mockChannelQueryResponse'
1312
import { ChannelState, StreamChat } from '../../src';
1413
import { DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE } from '../../src/constants';
1514

16-
const expect = chai.expect;
15+
import { describe, beforeEach, it, expect } from 'vitest';
1716

1817
describe('Channel count unread', function () {
1918
let lastRead;
@@ -845,77 +844,68 @@ describe('Uninitialized Channel', () => {
845844
describe('Channels - Constructor', function () {
846845
const client = new StreamChat('key', 'secret');
847846

848-
it('canonical form', function (done) {
847+
it('canonical form', function () {
849848
const channel = client.channel('messaging', '123', { cool: true });
850849
expect(channel.cid).to.eql('messaging:123');
851850
expect(channel.id).to.eql('123');
852851
expect(channel.data).to.eql({ cool: true });
853-
done();
854852
});
855853

856-
it('custom data merges to the right with current data', function (done) {
854+
it('custom data merges to the right with current data', function () {
857855
let channel = client.channel('messaging', 'brand_new_123', { cool: true });
858856
expect(channel.cid).to.eql('messaging:brand_new_123');
859857
expect(channel.id).to.eql('brand_new_123');
860858
expect(channel.data).to.eql({ cool: true });
861859
channel = client.channel('messaging', 'brand_new_123', { custom_cool: true });
862860
console.log(channel.data);
863861
expect(channel.data).to.eql({ cool: true, custom_cool: true });
864-
done();
865862
});
866863

867-
it('default options', function (done) {
864+
it('default options', function () {
868865
const channel = client.channel('messaging', '123');
869866
expect(channel.cid).to.eql('messaging:123');
870867
expect(channel.id).to.eql('123');
871-
done();
872868
});
873869

874-
it('null ID no options', function (done) {
870+
it('null ID no options', function () {
875871
const channel = client.channel('messaging', null);
876872
expect(channel.id).to.eq(undefined);
877-
done();
878873
});
879874

880-
it('undefined ID no options', function (done) {
875+
it('undefined ID no options', function () {
881876
const channel = client.channel('messaging', undefined);
882877
expect(channel.id).to.eql(undefined);
883878
expect(channel.data).to.eql({});
884-
done();
885879
});
886880

887-
it('short version with options', function (done) {
881+
it('short version with options', function () {
888882
const channel = client.channel('messaging', { members: ['tommaso', 'thierry'] });
889883
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
890884
expect(channel.id).to.eql(undefined);
891-
done();
892885
});
893886

894-
it('null ID with options', function (done) {
887+
it('null ID with options', function () {
895888
const channel = client.channel('messaging', null, {
896889
members: ['tommaso', 'thierry'],
897890
});
898891
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
899892
expect(channel.id).to.eql(undefined);
900-
done();
901893
});
902894

903-
it('empty ID with options', function (done) {
895+
it('empty ID with options', function () {
904896
const channel = client.channel('messaging', '', {
905897
members: ['tommaso', 'thierry'],
906898
});
907899
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
908900
expect(channel.id).to.eql(undefined);
909-
done();
910901
});
911902

912-
it('empty ID with options', function (done) {
903+
it('empty ID with options', function () {
913904
const channel = client.channel('messaging', undefined, {
914905
members: ['tommaso', 'thierry'],
915906
});
916907
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
917908
expect(channel.id).to.eql(undefined);
918-
done();
919909
});
920910
});
921911

@@ -1242,13 +1232,10 @@ describe('Channel search', async () => {
12421232
await channel.search('query', { sort: [{ custom_field: -1 }] });
12431233
});
12441234
it('sorting and offset works', async () => {
1245-
await expect(channel.search('query', { offset: 1, sort: [{ custom_field: -1 }] })).to
1246-
.be.fulfilled;
1235+
await expect(channel.search('query', { offset: 1, sort: [{ custom_field: -1 }] }));
12471236
});
12481237
it('next and offset fails', async () => {
1249-
await expect(channel.search('query', { offset: 1, next: 'next' })).to.be.rejectedWith(
1250-
Error,
1251-
);
1238+
await expect(channel.search('query', { offset: 1, next: 'next' })).rejects.toThrow();
12521239
});
12531240
});
12541241

0 commit comments

Comments
 (0)