Skip to content

Commit 12537fa

Browse files
comclaude
authored andcommitted
test: replace mocha with Node.js native test runner
- Replace it() with test() from node:test - Add import {describe, test} from 'node:test' to all test files - Tests run via: node --import tsx --test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6bf7e5c commit 12537fa

4 files changed

Lines changed: 80 additions & 76 deletions

File tree

tests/Jsona.test.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as chai from 'chai';
22
import {expect} from 'chai';
3+
import {describe, test} from 'node:test';
34
import Jsona from '../src';
45

56
import {
@@ -31,95 +32,95 @@ chai.config.truncateThreshold = 0;
3132
describe('Jsona', () => {
3233
const jsona = new Jsona();
3334

34-
it('should instantiate with fallback property mappers', () => {
35+
test('should instantiate with fallback property mappers', () => {
3536
let jsona = new Jsona();
3637
});
3738

3839
describe('serialize', () => {
39-
it('should throw Error if stuff is not passed', () => {
40+
test('should throw Error if stuff is not passed', () => {
4041
expect(jsona.serialize.bind(jsona, null)).to.throw(Error);
4142
expect(jsona.serialize.bind(jsona, undefined)).to.throw(Error);
4243
expect(jsona.serialize.bind(jsona, {stuff: null})).to.throw(Error);
4344
});
4445

45-
it('should build json with item, without included', () => {
46+
test('should build json with item, without included', () => {
4647
const jsonBody = jsona.serialize({stuff: town1.model});
4748
expect(jsonBody.data).to.be.deep.equal(town1.json);
4849
expect(jsonBody.included).to.be.equal(undefined);
4950
});
5051

51-
it('should build json with collection, with included', () => {
52+
test('should build json with collection, with included', () => {
5253
const jsonBody = jsona.serialize({stuff: user2.model, includeNames: ['specialty', 'town.country']});
5354
expect(jsonBody.data).to.be.deep.equal(user2.json);
5455
expect(jsonBody.included).to.be.deep.equal([specialty1.json, specialty2.json, town2.json, country2.json]);
5556
});
5657

57-
it('should build json with collection, with included resources that do not have ids', () => {
58+
test('should build json with collection, with included resources that do not have ids', () => {
5859
const jsonBody = jsona.serialize({stuff: userWithIdlessSpecialties.model, includeNames: ['specialtyWithoutIds']});
5960
expect(jsonBody.included).to.be.deep.equal([idlessSpecialty1.json, idlessSpecialty2.json]);
6061
});
6162

62-
it('should build json and save null relationships', () => {
63+
test('should build json and save null relationships', () => {
6364
const jsonBody = jsona.serialize({stuff: withNullRelationsMock.collection});
6465
expect(jsonBody.data).to.be.deep.equal(withNullRelationsMock.json);
6566
});
6667
});
6768

6869
describe('deserialize', () => {
69-
it('should throw Error if body is not passed', () => {
70+
test('should throw Error if body is not passed', () => {
7071
expect(jsona.deserialize.bind(jsona, null)).to.throw(Error);
7172
expect(jsona.deserialize.bind(jsona, undefined)).to.throw(Error);
7273
});
7374

74-
it('should deserialize item without included', () => {
75+
test('should deserialize item without included', () => {
7576
const userModel = jsona.deserialize({data: user2.json});
7677
expect(userModel).to.be.deep.equal(user2.modelWithoutIncluded);
7778
});
7879

79-
it('should deserialize collection with included', () => {
80+
test('should deserialize collection with included', () => {
8081
const townsCollection = jsona.deserialize({
8182
data: [town1.json, town2.json],
8283
included: [country1.json, country2.json]
8384
});
8485
expect(townsCollection).to.be.deep.equal([town1.model, town2.model]);
8586
});
8687

87-
it('should deserialize json with circular relationships', () => {
88+
test('should deserialize json with circular relationships', () => {
8889
const recursiveItem = jsona.deserialize(circular.json);
8990
expect(recursiveItem).to.be.deep.equal(circular.model);
9091
});
9192

92-
it('should deserialize json with meta & circular relationships', () => {
93+
test('should deserialize json with meta & circular relationships', () => {
9394
const recursiveItem = jsona.deserialize(circularWithMeta.json);
9495
expect(recursiveItem).to.be.deep.equal(circularWithMeta.model);
9596
});
9697

97-
it('should deserialize json with duplicate relationships', () => {
98+
test('should deserialize json with duplicate relationships', () => {
9899
const duplicateItem = jsona.deserialize(duplicate.json, { preferNestedDataFromData: true });
99100
expect(duplicateItem).to.be.deep.equal(duplicate.model);
100101
});
101102

102-
it('should deserialize json with data without root ids', () => {
103+
test('should deserialize json with data without root ids', () => {
103104
const collectionWithoutRootIds = jsona.deserialize({data: withoutRootIdsMock.json});
104105
expect(collectionWithoutRootIds).to.be.deep.equal(withoutRootIdsMock.collection);
105106
});
106107

107-
it('should deserialize json and save null relationships', () => {
108+
test('should deserialize json and save null relationships', () => {
108109
const collectionWithNullRelations = jsona.deserialize({data: withNullRelationsMock.json});
109110
expect(collectionWithNullRelations).to.be.deep.equal(withNullRelationsMock.collection);
110111
});
111112

112-
it('should deserialize resource id object meta field into resourceIdObjMeta', () => {
113+
test('should deserialize resource id object meta field into resourceIdObjMeta', () => {
113114
const stuff = jsona.deserialize(resourceIdObjMetaMock.json);
114115
expect(stuff).to.be.deep.equal(resourceIdObjMetaMock.collection);
115116
});
116117

117-
it('should deserialize with different attrs for root object and related', () => {
118+
test('should deserialize with different attrs for root object and related', () => {
118119
const stuff = jsona.deserialize(differentAttrsInDataAndIncludedMock.json);
119120
expect(stuff).to.be.deep.equal(differentAttrsInDataAndIncludedMock.collection);
120121
});
121122

122-
it('should new', () => {
123+
test('should new', () => {
123124
const stuff = jsona.deserialize(differentAttrsInDataAndIncludedMock.json);
124125
expect(stuff).to.be.deep.equal(differentAttrsInDataAndIncludedMock.collection);
125126
});
@@ -128,29 +129,29 @@ describe('Jsona', () => {
128129

129130
describe('denormalizeReduxObject', () => {
130131

131-
it('should throw Error if reduxObject is not passed', () => {
132+
test('should throw Error if reduxObject is not passed', () => {
132133
const denormalizeReduxObject = jsona.denormalizeReduxObject.bind(jsona, {
133134
reduxObject: null,
134135
});
135136
expect(denormalizeReduxObject).to.throw(Error, 'reduxObject');
136137
});
137138

138-
it('should throw Error if entityType is not passed', () => {
139+
test('should throw Error if entityType is not passed', () => {
139140
const denormalizeReduxObject = jsona.denormalizeReduxObject.bind(jsona, {
140141
reduxObject: {},
141142
});
142143
expect(denormalizeReduxObject).to.throw(Error, 'entityType');
143144
});
144145

145-
it('should return null if no such entityType in reduxObject', () => {
146+
test('should return null if no such entityType in reduxObject', () => {
146147
const model = jsona.denormalizeReduxObject({
147148
reduxObject: {},
148149
entityType: 'myEntity'
149150
});
150151
expect(model).to.be.equal(null);
151152
});
152153

153-
it('should return null if no such entityId in reduxObject', () => {
154+
test('should return null if no such entityId in reduxObject', () => {
154155
const model = jsona.denormalizeReduxObject({
155156
reduxObject: reduxObject1,
156157
entityType: 'article',
@@ -159,7 +160,7 @@ describe('Jsona', () => {
159160
expect(model).to.be.equal(null);
160161
});
161162

162-
it('should return collection of models if entityIds is Array', () => {
163+
test('should return collection of models if entityIds is Array', () => {
163164
const models = jsona.denormalizeReduxObject({
164165
reduxObject: reduxObject1,
165166
returnBuilderInRelations: false,
@@ -170,7 +171,7 @@ describe('Jsona', () => {
170171
expect(models).to.be.deep.equal([town1.model, town2.model]);
171172
});
172173

173-
it('should return collection of models if entityIds is not passed', () => {
174+
test('should return collection of models if entityIds is not passed', () => {
174175
const models = jsona.denormalizeReduxObject({
175176
reduxObject: reduxObject1,
176177
returnBuilderInRelations: false,
@@ -181,7 +182,7 @@ describe('Jsona', () => {
181182
});
182183

183184

184-
it('should denormalize json with circular relationships', () => {
185+
test('should denormalize json with circular relationships', () => {
185186
const model = jsona.denormalizeReduxObject({
186187
reduxObject: reduxObjectWithCircular,
187188
returnBuilderInRelations: false,
@@ -191,7 +192,7 @@ describe('Jsona', () => {
191192
expect(model).to.be.deep.equal(circular.model);
192193
});
193194

194-
it('should denormalize model with relationships', () => {
195+
test('should denormalize model with relationships', () => {
195196
const model1 = jsona.denormalizeReduxObject({
196197
reduxObject: reduxObject1,
197198
returnBuilderInRelations: false,
@@ -208,7 +209,7 @@ describe('Jsona', () => {
208209
expect(model2['country']).to.be.deep.equal(country1.model);
209210
});
210211

211-
it('should allow to set relationships before denormalization', () => {
212+
test('should allow to set relationships before denormalization', () => {
212213
const model = jsona.denormalizeReduxObject({
213214
reduxObject: reduxObject1,
214215
returnBuilderInRelations: true,

tests/ModelsSerializer.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as chai from 'chai';
22
import {expect} from 'chai';
3+
import {describe, test} from 'node:test';
34
import ModelsSerializer from "../src/builders/ModelsSerializer";
45
import {ModelPropertiesMapper} from "../src/simplePropertyMappers";
56

@@ -24,47 +25,47 @@ describe('ModelsSerializer', () => {
2425
let builder;
2526
let propertiesMapper;
2627

27-
it('should throw Error if jsonPropertiesMapper is not passed', () => {
28+
test('should throw Error if jsonPropertiesMapper is not passed', () => {
2829
builder = new ModelsSerializer();
2930
builder.setStuff(user2.model);
3031
expect(builder.build.bind(builder)).to.throw(Error, 'propertiesMapper');
3132
});
3233

33-
it('should instantiate without errors', () => {
34+
test('should instantiate without errors', () => {
3435
propertiesMapper = new ModelPropertiesMapper();
3536
builder = new ModelsSerializer(propertiesMapper);
3637
expect(builder).to.be.an.instanceof(ModelsSerializer);
3738
});
3839

39-
it('should handle one model in setStuff', () => {
40+
test('should handle one model in setStuff', () => {
4041
builder.setStuff(user2.model);
4142
expect(builder.stuff).to.be.deep.equal(user2.model);
4243
});
4344

44-
it('should handle collection of models in setStuff', () => {
45+
test('should handle collection of models in setStuff', () => {
4546
builder.setStuff([user2.model, user1.model]);
4647
expect(builder.stuff).to.be.deep.equal([user2.model, user1.model]);
4748
});
4849

49-
it('should setIncludeNames with convertation to TJsonaNormalizedIncludeNamesTree', () => {
50+
test('should setIncludeNames with convertation to TJsonaNormalizedIncludeNamesTree', () => {
5051
builder.setIncludeNames(includeNames1.denormalized);
5152
expect(builder.includeNamesTree).to.be.deep.equal(includeNames1.normalized);
5253
});
5354

54-
it('should setIncludeNames as they are', () => {
55+
test('should setIncludeNames as they are', () => {
5556
builder.setIncludeNames(includeNames1.normalized);
5657
expect(builder.includeNamesTree).to.be.deep.equal(includeNames1.normalized);
5758
});
5859

59-
it('should build correct json with one data-item, without included', () => {
60+
test('should build correct json with one data-item, without included', () => {
6061
builder = new ModelsSerializer(propertiesMapper);
6162

6263
builder.setStuff(article1.model);
6364
const json = builder.build();
6465
expect(json).to.be.deep.equal({data: article1.json});
6566
});
6667

67-
it('should build correct json with one data-item, with included', () => {
68+
test('should build correct json with one data-item, with included', () => {
6869
builder = new ModelsSerializer(propertiesMapper);
6970

7071
builder.setStuff(user2.model);
@@ -73,7 +74,7 @@ describe('ModelsSerializer', () => {
7374
expect(json).to.be.deep.equal({data: user2.json, included: user2.included.townOnly});
7475
});
7576

76-
it('should build correct json with collection of data items, with included', () => {
77+
test('should build correct json with collection of data items, with included', () => {
7778
builder = new ModelsSerializer(propertiesMapper);
7879

7980
builder.setStuff([article1.model, article2.model]);
@@ -104,12 +105,12 @@ describe('ModelsSerializer', () => {
104105

105106
});
106107

107-
it('should build json with null data for nulled relation', () => {
108+
test('should build json with null data for nulled relation', () => {
108109
builder = new ModelsSerializer(propertiesMapper);
109110

110111
builder.setStuff(articleWithoutAuthor.model);
111112
builder.setIncludeNames(articleWithoutAuthor.includeNames);
112113
const json = builder.build();
113114
expect(json).to.be.deep.equal({ data: articleWithoutAuthor.json });
114115
});
115-
});
116+
});

0 commit comments

Comments
 (0)