Skip to content

Commit d534370

Browse files
committed
Replace jest and sinon with node:test
1 parent 58a2b9d commit d534370

45 files changed

Lines changed: 1514 additions & 1304 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
run: yarn lint
2727

2828
- name: Run tests
29-
run: yarn test
29+
run: yarn test:coverage

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
"scripts": {
3535
"lint": "eslint",
3636
"release": "release-it",
37-
"test": "uphold-scripts test"
37+
"test": "node --test",
38+
"test:coverage": "NODE_V8_COVERAGE=coverage node --test --experimental-test-coverage",
39+
"test:watch": "node --test --watch"
3840
},
3941
"dependencies": {
4042
"lodash": "^4.17.21",
@@ -55,7 +57,6 @@
5557
"moment": "^2.29.1",
5658
"prettier": "^3.5.3",
5759
"release-it": "^17.0.1",
58-
"sinon": "^11.1.1",
5960
"tin-validator": "^1.0.0",
6061
"uk-modulus-checking": "0.0.3",
6162
"uphold-scripts": "^0.5.0",

test/asserts/aba-routing-number-assert.test.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
const { Assert: BaseAssert, Violation } = require('validator.js');
8-
const AbaRoutingNumberAssert = require('../../src/asserts/aba-routing-number-assert');
8+
const { describe, it } = require('node:test');
9+
const AbaRoutingNumberAssert = require('../../src/asserts/aba-routing-number-assert.js');
910

1011
/**
1112
* Extend `Assert` with `AbaRoutingNumberAssert`.
@@ -20,37 +21,37 @@ const Assert = BaseAssert.extend({
2021
*/
2122

2223
describe('AbaRoutingNumberAssert', () => {
23-
it('should throw an error if the input value is not a string', () => {
24+
it('should throw an error if the input value is not a string', ({ assert }) => {
2425
[{}, []].forEach(choice => {
2526
try {
2627
Assert.abaRoutingNumber().validate(choice);
2728

28-
fail();
29+
assert.fail();
2930
} catch (e) {
30-
expect(e).toBeInstanceOf(Violation);
31-
expect(e.violation.value).toBe('must_be_a_string');
31+
assert.ok(e instanceof Violation);
32+
assert.equal(e.violation.value, 'must_be_a_string');
3233
}
3334
});
3435
});
3536

36-
it('should throw an error if the input value is not a valid ABA routing number', () => {
37+
it('should throw an error if the input value is not a valid ABA routing number', ({ assert }) => {
3738
try {
3839
Assert.abaRoutingNumber().validate('foobar');
3940

40-
fail();
41+
assert.fail();
4142
} catch (e) {
42-
expect(e).toBeInstanceOf(Violation);
43-
expect(e.show().value).toBe('foobar');
43+
assert.ok(e instanceof Violation);
44+
assert.equal(e.show().value, 'foobar');
4445
}
4546
});
4647

47-
it('should expose `assert` equal to `AbaRoutingNumber`', () => {
48+
it('should expose `assert` equal to `AbaRoutingNumber`', ({ assert }) => {
4849
try {
4950
Assert.abaRoutingNumber().validate(123);
5051

51-
fail();
52+
assert.fail();
5253
} catch (e) {
53-
expect(e.show().assert).toBe('AbaRoutingNumber');
54+
assert.equal(e.show().assert, 'AbaRoutingNumber');
5455
}
5556
});
5657

test/asserts/bank-identifier-code-assert.test.js

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
const { Assert: BaseAssert, Violation } = require('validator.js');
8-
const BankIdentifierCodeAssert = require('../../src/asserts/bank-identifier-code-assert');
8+
const { describe, it } = require('node:test');
9+
const BankIdentifierCodeAssert = require('../../src/asserts/bank-identifier-code-assert.js');
910

1011
/**
1112
* Extend `Assert` with `BankIdentifierCodeAssert`.
@@ -20,56 +21,62 @@ const Assert = BaseAssert.extend({
2021
*/
2122

2223
describe('BankIdentifierCodeAssert', () => {
23-
it('should throw an error if the input value is not a string', () => {
24+
it('should throw an error if the input value is not a string', ({ assert }) => {
2425
const choices = [[], {}];
2526

2627
choices.forEach(choice => {
2728
try {
2829
Assert.bankIdentifierCode().validate(choice);
2930

30-
fail();
31+
assert.fail();
3132
} catch (e) {
32-
expect(e).toBeInstanceOf(Violation);
33-
expect(e.violation.value).toBe('must_be_a_string');
33+
assert.ok(e instanceof Violation);
34+
assert.equal(e.violation.value, 'must_be_a_string');
3435
}
3536
});
3637
});
3738

38-
it('should expose `assert` equal to `BankIdentifierCode`', () => {
39+
it('should expose `assert` equal to `BankIdentifierCode`', ({ assert }) => {
3940
try {
4041
Assert.bankIdentifierCode().validate(123);
4142

42-
fail();
43+
assert.fail();
4344
} catch (e) {
44-
expect(e.show().assert).toBe('BankIdentifierCode');
45+
assert.equal(e.show().assert, 'BankIdentifierCode');
4546
}
4647
});
4748

48-
it('should throw an error if the input value is not a valid bic', () => {
49+
it('should throw an error if the input value is not a valid bic', ({ assert }) => {
4950
try {
5051
Assert.bankIdentifierCode().validate('BICOLETO');
5152

52-
fail();
53+
assert.fail();
5354
} catch (e) {
54-
expect(e).toBeInstanceOf(Violation);
55-
expect(e.value).toBe('BICOLETO');
55+
assert.ok(e instanceof Violation);
56+
assert.equal(e.value, 'BICOLETO');
5657
}
5758
});
5859

59-
it('should accept a valid bic without branch code', () => {
60-
Assert.bankIdentifierCode().validate('FOOBARBI');
60+
it('should accept a valid bic without branch code', ({ assert }) => {
61+
assert.doesNotThrow(() => {
62+
Assert.bankIdentifierCode().validate('FOOBARBI');
63+
});
6164
});
6265

63-
it('should accept a valid bic with branch code', () => {
64-
Assert.bankIdentifierCode().validate('FOOBARBIXXX');
66+
it('should accept a valid bic with branch code', ({ assert }) => {
67+
assert.doesNotThrow(() => {
68+
Assert.bankIdentifierCode().validate('FOOBARBIXXX');
69+
});
6570
});
6671

67-
it('should be case-insensitive', () => {
68-
Assert.bankIdentifierCode().validate('FOOBARBI');
69-
Assert.bankIdentifierCode().validate('FooBarBI');
70-
Assert.bankIdentifierCode().validate('foobarbi');
71-
Assert.bankIdentifierCode().validate('FOOBARBIXXX');
72-
Assert.bankIdentifierCode().validate('FooBarBIXXX');
73-
Assert.bankIdentifierCode().validate('foobarbixxx');
72+
it('should be case-insensitive', ({ assert }) => {
73+
assert.doesNotThrow(() => {
74+
Assert.bankIdentifierCode().validate('FOOBARBI');
75+
Assert.bankIdentifierCode().validate('FooBarBI');
76+
Assert.bankIdentifierCode().validate('foobarbi');
77+
Assert.bankIdentifierCode().validate('FOOBARBIXXX');
78+
Assert.bankIdentifierCode().validate('FooBarBIXXX');
79+
Assert.bankIdentifierCode().validate('foobarbixxx');
80+
});
7481
});
7582
});

test/asserts/big-number-assert.test.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
const { Assert: BaseAssert, Violation } = require('validator.js');
8-
const BigNumberAssert = require('../../src/asserts/big-number-assert');
8+
const { describe, it } = require('node:test');
9+
const BigNumberAssert = require('../../src/asserts/big-number-assert.js');
910

1011
/**
1112
* Extend `Assert` with `BigNumberAssert`.
@@ -24,27 +25,27 @@ describe('BigNumberAssert', () => {
2425
describe(`with option '${
2526
option ? `{ validateSignificantDigits: ${option.validateSignificantDigits} }` : undefined
2627
}'`, () => {
27-
it('should throw an error if the input value is not a big number', () => {
28+
it('should throw an error if the input value is not a big number', ({ assert }) => {
2829
const choices = [[], {}, ''];
2930

3031
choices.forEach(choice => {
3132
try {
3233
Assert.bigNumber(option).validate(choice);
3334

34-
fail();
35+
assert.fail();
3536
} catch (e) {
36-
expect(e).toBeInstanceOf(Violation);
37+
assert.ok(e instanceof Violation);
3738
}
3839
});
3940
});
4041

41-
it('should expose `assert` equal to `BigNumber`', () => {
42+
it('should expose `assert` equal to `BigNumber`', ({ assert }) => {
4243
try {
4344
Assert.bigNumber(option).validate();
4445

45-
fail();
46+
assert.fail();
4647
} catch (e) {
47-
expect(e.show().assert).toBe('BigNumber');
48+
assert.equal(e.show().assert, 'BigNumber');
4849
}
4950
});
5051

@@ -57,16 +58,17 @@ describe('BigNumberAssert', () => {
5758
});
5859

5960
if (!option || option.validateSignificantDigits === true) {
60-
it('should throw an error if a number has more than 15 significant digits', () => {
61+
it('should throw an error if a number has more than 15 significant digits', ({ assert }) => {
6162
try {
6263
// eslint-disable-next-line no-loss-of-precision
6364
Assert.bigNumber(option).validate(1.011111111111111111111111111111111111111111);
6465

65-
fail();
66+
assert.fail();
6667
} catch (e) {
67-
expect(e).toBeInstanceOf(Violation);
68-
expect(e.show().assert).toBe('BigNumber');
69-
expect(e.show().violation.message).toBe(
68+
assert.ok(e instanceof Violation);
69+
assert.equal(e.show().assert, 'BigNumber');
70+
assert.equal(
71+
e.show().violation.message,
7072
'[BigNumber Error] Number primitive has more than 15 significant digits: 1.011111111111111'
7173
);
7274
}

test/asserts/big-number-equal-to-assert.test.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66

77
const { Assert: BaseAssert, Violation } = require('validator.js');
8+
const { describe, it } = require('node:test');
89
const BigNumber = require('bignumber.js');
9-
const BigNumberEqualToAssert = require('../../src/asserts/big-number-equal-to-assert');
10+
const BigNumberEqualToAssert = require('../../src/asserts/big-number-equal-to-assert.js');
1011

1112
/**
1213
* Extend `Assert` with `BigNumberEqualToAssert`.
@@ -21,102 +22,108 @@ const Assert = BaseAssert.extend({
2122
*/
2223

2324
describe('BigNumberEqualToAssert', () => {
24-
it('should throw an error if `value` is missing', () => {
25+
it('should throw an error if `value` is missing', ({ assert }) => {
2526
try {
2627
Assert.bigNumberEqualTo();
2728

28-
fail();
29+
assert.fail();
2930
} catch (e) {
30-
expect(e.message).toBe('A value is required.');
31+
assert.equal(e.message, 'A value is required.');
3132
}
3233
});
3334

3435
[undefined, { validateSignificantDigits: true }, { validateSignificantDigits: false }].forEach(option => {
3536
describe(`with option '${
3637
option ? `{ validateSignificantDigits: ${option.validateSignificantDigits} }` : undefined
3738
}'`, () => {
38-
it('should throw an error if `value` is not a number', () => {
39+
it('should throw an error if `value` is not a number', ({ assert }) => {
3940
try {
4041
Assert.bigNumberEqualTo({}, option);
4142

42-
fail();
43+
assert.fail();
4344
} catch (e) {
44-
expect(e).toBeInstanceOf(Violation);
45-
expect(e.show().violation.message).toMatch(/Not a number/);
45+
assert.ok(e instanceof Violation);
46+
assert.ok(e.show().violation.message.match(/Not a number/));
4647
}
4748
});
4849

49-
it('should throw an error if the input value is not a number', () => {
50+
it('should throw an error if the input value is not a number', ({ assert }) => {
5051
const choices = [[], {}, ''];
5152

5253
choices.forEach(choice => {
5354
try {
5455
Assert.bigNumberEqualTo(10, option).validate(choice);
5556

56-
fail();
57+
assert.fail();
5758
} catch (e) {
58-
expect(e).toBeInstanceOf(Violation);
59+
assert.ok(e instanceof Violation);
5960
}
6061
});
6162
});
6263

63-
it('should throw an error if the input number is greater than the value', () => {
64+
it('should throw an error if the input number is greater than the value', ({ assert }) => {
6465
try {
6566
Assert.bigNumberEqualTo(10, option).validate(12);
6667

67-
fail();
68+
assert.fail();
6869
} catch (e) {
69-
expect(e).toBeInstanceOf(Violation);
70+
assert.ok(e instanceof Violation);
7071
}
7172
});
7273

73-
it('should throw an error if the input number is less than the value', () => {
74+
it('should throw an error if the input number is less than the value', ({ assert }) => {
7475
try {
7576
Assert.bigNumberEqualTo(10, option).validate(9);
7677

77-
fail();
78+
assert.fail();
7879
} catch (e) {
79-
expect(e).toBeInstanceOf(Violation);
80+
assert.ok(e instanceof Violation);
8081
}
8182
});
8283

83-
it('should expose `assert` equal to `BigNumberEqualTo`', () => {
84+
it('should expose `assert` equal to `BigNumberEqualTo`', ({ assert }) => {
8485
try {
8586
Assert.bigNumberEqualTo(1, option).validate(0.1);
8687

87-
fail();
88+
assert.fail();
8889
} catch (e) {
89-
expect(e.show().assert).toBe('BigNumberEqualTo');
90+
assert.equal(e.show().assert, 'BigNumberEqualTo');
9091
}
9192
});
9293

93-
it('should expose `assert` equal to `BigNumberEqualTo` and `message` on the violation if the input value is not a number', () => {
94+
it('should expose `assert` equal to `BigNumberEqualTo` and `message` on the violation if the input value is not a number', ({
95+
assert
96+
}) => {
9497
try {
9598
Assert.bigNumberEqualTo(10, option).validate({});
9699

97-
fail();
100+
assert.fail();
98101
} catch (e) {
99-
expect(e.show().assert).toBe('BigNumberEqualTo');
100-
expect(e.show().violation.message).toMatch(/Not a number/);
102+
assert.equal(e.show().assert, 'BigNumberEqualTo');
103+
assert.ok(e.show().violation.message.match(/Not a number/));
101104
}
102105
});
103106

104-
it('should expose `value` on the violation', () => {
107+
it('should expose `value` on the violation', ({ assert }) => {
105108
try {
106109
Assert.bigNumberEqualTo(10, option).validate(0.1);
107110

108-
fail();
111+
assert.fail();
109112
} catch (e) {
110-
expect(e.show().violation.value).toBe('10');
113+
assert.equal(e.show().violation.value, '10');
111114
}
112115
});
113116

114-
it('should accept a big number as a value', () => {
115-
Assert.bigNumberEqualTo(new BigNumber(10), option).validate(10);
117+
it('should accept a big number as a value', ({ assert }) => {
118+
assert.doesNotThrow(() => {
119+
Assert.bigNumberEqualTo(new BigNumber(10), option).validate(10);
120+
});
116121
});
117122

118-
it('should accept a number that is equal to value', () => {
119-
Assert.bigNumberEqualTo(10, option).validate(10);
123+
it('should accept a number that is equal to value', ({ assert }) => {
124+
assert.doesNotThrow(() => {
125+
Assert.bigNumberEqualTo(10, option).validate(10);
126+
});
120127
});
121128
});
122129
});

0 commit comments

Comments
 (0)