8000 Use default tsconfig for tests by jdeniau · Pull Request #2055 · immutable-js/immutable-js · GitHub
[go: up one dir, main page]

Skip to content

Use default tsconfig for tests #2055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/ArraySeq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ArraySequence', () => {

it('efficiently chains iteration methods', () => {
const i = Seq('abcdefghijklmnopqrstuvwxyz'.split(''));
function studly(letter, index) {
function studly(letter: string, index: number): string {
return index % 2 === 0 ? letter : letter.toUpperCase();
}
const result = i
Expand Down
57 changes: 41 additions & 16 deletions __tests__/Conversion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { describe, expect, it } from '@jest/globals';
import { fromJS, is, List, Map, OrderedMap, Record } from 'immutable';
import {
type Collection,
fromJS,
is,
List,
Map,
OrderedMap,
Record,
} from 'immutable';
import fc, { type JsonValue } from 'fast-check';

describe('Conversion', () => {
Expand Down Expand Up @@ -113,29 +121,46 @@ describe('Conversion', () => {
});

it('Converts deep JSON with custom conversion', () => {
const seq = fromJS(js, function (key, sequence) {
if (key === 'point') {
// @ts-expect-error -- to convert to real typing
return new Point(sequence);
const seq = fromJS(
js,
function (
this: typeof js,
key: PropertyKey,
sequence:
| Collection.Keyed<string, unknown>
| Collection.Indexed<unknown>
) {
if (key === 'point') {
// @ts-expect-error -- to convert to real typing
return new Point(sequence);
}

// @ts-expect-error -- any type for too complex object
return Array.isArray(this[key])
? sequence.toList()
: sequence.toOrderedMap();
}
return Array.isArray(this[key])
? sequence.toList()
: sequence.toOrderedMap();
});
);
expect(seq).toEqual(immutableOrderedData);
expect(seq.toString()).toEqual(immutableOrderedDataString);
});

it('Converts deep JSON with custom conversion including keypath if requested', () => {
const paths: Array<Array<string | number> | undefined> = [];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const seq1 = fromJS(js, function (key, sequence, keypath) {
expect(arguments.length).toBe(3);
paths.push(keypath);
return Array.isArray(this[key])
? sequence.toList()
: sequence.toOrderedMap();
});
const seq1 = fromJS(
js,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function (this: typeof js, key: any, sequence, ke 8000 ypath) {
expect(arguments.length).toBe(3);
paths.push(keypath);

// @ts-expect-error -- any type for too complex object
return Array.isArray(this[key])
? sequence.toList()
: sequence.toOrderedMap();
}
);
expect(paths).toEqual([
[],
['deepList'],
Expand Down
4 changes: 2 additions & 2 deletions __tests__/Equality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { is, List, Map, Seq, Set } from 'immutable';
import fc from 'fast-check';

describe('Equality', () => {
function expectIs(left, right) {
function expectIs(left: unknown, right: unknown): void {
const comparison = is(left, right);
expect(comparison).toBe(true);
const commutative = is(right, left);
expect(commutative).toBe(true);
}

function expectIsNot(left, right) {
function expectIsNot(left: unknown, right: unknown): void {
const comparison = is(left, right);
expect(comparison).toBe(false);
const commutative = is(right, left);
Expand Down
13 changes: 11 additions & 2 deletions __tests__/KeyedSeq.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { describe, expect, it } from '@jest/globals';
import { Range, Seq } from 'immutable';
import fc from 'fast-check';
import invariant from '../src/utils/invariant';

describe('KeyedSeq', () => {
it('iterates equivalently', () => {
fc.assert(
fc.property(fc.array(fc.integer()), (ints) => {
fc.property(fc.array(fc.integer()), (ints: Array<number>) => {
const seq = Seq(ints);
const keyed = seq.toKeyedSeq();

Expand All @@ -24,7 +25,7 @@ describe('KeyedSeq', () => {
});

it('maintains keys', () => {
const isEven = (x) => x % 2 === 0;
const isEven = (x: number): boolean => x % 2 === 0;
const seq = Range(0, 100);

// This is what we expect for IndexedSequences
Expand All @@ -39,6 +40,10 @@ describe('KeyedSeq', () => {
const [indexed0, indexed1] = seq
.partition(isEven)
.map((part) => part.skip(10).take(5));

invariant(indexed0, 'indexed0 is not undefined');
invariant(indexed1, 'indexed0 is not undefined');

expect(indexed0.entrySeq().toArray()).toEqual([
[0, 21],
[1, 23],
Expand Down Expand Up @@ -67,6 +72,10 @@ describe('KeyedSeq', () => {
const [keyed0, keyed1] = keyed
.partition(isEven)
.map((part) => part.skip(10).take(5));

invariant(keyed0, 'keyed0 is not undefined');
invariant(keyed1, 'keyed1 is not undefined');

expect(keyed0.entrySeq().toArray()).toEqual([
[21, 21],
[23, 23],
Expand Down
9 changes: 6 additions & 3 deletions __tests__/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it } from '@jest/globals';
import { fromJS, List, Map, Range, Seq, Set } from 'immutable';
import fc from 'fast-check';
import { create as createSeed } from 'random-seed';
import invariant from '../src/utils/invariant';

function arrayOfSize(s: number) {
const a = new Array(s);
Expand Down Expand Up @@ -480,6 +481,8 @@ describe('List', () => {
});

it.each(['remove', 'delete'])('remove removes any index', (fn) => {
invariant(fn === 'remove' || fn === 'delete', 'Invalid function name');

let v = List.of('a', 'b', 'c')[fn](2)[fn](0);
expect(v.size).toBe(1);
expect(v.get(0)).toBe('b');
Expand Down Expand Up @@ -732,7 +735,7 @@ describe('List', () => {
expect(v5.toJS().filter((item) => item === 0)).toHaveLength(0);

// execute the same test as `v` but for the 2000 first integers
const isOkV1 = (v) =>
const isOkV1 = (v: number): boolean =>
List.of()
.set(v, v)
.push('pushed-value')
Expand Down Expand Up @@ -763,7 +766,7 @@ describe('List', () => {

it('forEach iteration terminates when callback returns false', () => {
const a: Array<number> = [];
function count(x) {
function count(x: number): void | false {
if (x > 2) {
return false;
}
Expand Down Expand Up @@ -984,7 +987,7 @@ describe('List', () => {

// Note: NaN is the only value not equal to itself. The isNaN() built-in
// function returns true for any non-numeric value, not just the NaN value.
function isNaNValue(value) {
function isNaNValue(value: unknown): boolean {
return value !== value;
}

Expand Down
2 changes: 1 addition & 1 deletion __tests__/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ describe('Map', () => {

it('uses toString on keys and values', () => {
class A extends Record({ x: null as number | null }) {
toString() {
override toString() {
return this.x;
}
}
Expand Down
2 changes: 1 addition & 1 deletion __tests__/OrderedSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('OrderedSet', () => {
* @see https://github.com/immutable-js/immutable-js/issues/1716
*/
it('handles `subtract` when Set contains >=32 elements', () => {
const fillArray = (nb) =>
const fillArray = (nb: number) =>
Array(nb)
.fill(1)
.map((el, i) => i + 1);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/Predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('isValueObject', () => {
this.v = val;
}

equals(other) {
equals(other: MyValueType) {
return Boolean(other && this.v === other.v);
}

Expand Down
5 changes: 3 additions & 2 deletions __tests__/Seq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ describe('Seq', () => {
});

it('accepts an object with a next property', () => {
expect(Seq({ a: 1, b: 2, next: (_) => _ }).size).toBe(3);
expect(Seq({ a: 1, b: 2, next: (_: unknown) => _ }).size).toBe(3);
});

it('accepts a collection string', () => {
expect(Seq('foo').size).toBe(3);
});

it('accepts arbitrary objects', () => {
function Foo() {
function Foo(this: { bar: string; baz: string }) {
this.bar = 'bar';
this.baz = 'baz';
}
// @ts-expect-error -- any type for too complex object
expect(Seq(new Foo()).size).toBe(2);
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/Set.ts
2 changes: 1 addition & 1 deletion __tests__/Stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe('Set', () => {
Symbol('a'),
Symbol('b'),
Symbol('c'),
];
] as const;

const symbolSet = Set(manySymbols);
expect(symbolSet.size).toBe(12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it } from '@jest/globals';
import { Seq, Stack } from 'immutable';
import fc from 'fast-check';

function arrayOfSize(s) {
function arrayOfSize(s: number): Array<number> {
const a = new Array(s);
for (let ii = 0; ii < s; ii++) {
a[ii] = ii;
Expand Down
7 changes: 5 additions & 2 deletions __tests__/functional/get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { get, Map, List, Range } from 'immutable';
import invariant from '../../src/utils/invariant';

describe('get', () => {
it('for immutable structure', () => {
Expand All @@ -26,8 +27,10 @@ describe('get', () => {
{
x: 'xx',
y: 'yy',
get: function (key: string) {
return `${this[key].toUpperCase()}`;
get: function (this, key: string) {
invariant(typeof this[key] === 'string', 'this[key] is a string');

return this[key].toUpperCase();
},
},
'x'
Expand Down
2 changes: 1 addition & 1 deletion __tests__/groupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('groupBy', () => {
isObject ? objectConstructor : iterableConstructor
);

const grouped = col.groupBy((v) => v);
const grouped = col.groupBy((v: unknown) => v);

// all groupBy should be instance of Map
expect(grouped).toBeInstanceOf(Map);
Expand Down
1 change: 1 addition & 0 deletions __tests__/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('Issue #1220 : Seq.rest() throws an exception when invoked on a single
(typeof Symbol === 'function' && Symbol.iterator) || '@@iterator';

const r = Seq([1]).rest();
// @ts-expect-error -- any type for too complex object
const i = r[ITERATOR_SYMBOL]();
expect(i.next()).toEqual({ value: undefined, done: true });
});
Expand Down
17 changes: 10 additions & 7 deletions __tests__/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,18 @@ describe('merge', () => {
).toBe(true);
});

const map = { type: 'Map', value: Map({ b: 5, c: 9 }) };
const object = { type: 'object', value: { b: 7, d: 12 } };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type TypeValue = { type: any; value: any };

const map: TypeValue = { type: 'Map', value: Map({ b: 5, c: 9 }) };
const object: TypeValue = { type: 'object', value: { b: 7, d: 12 } };
const RecordFactory = Record({ a: 1, b: 2 });
const record = { type: 'Record', value: RecordFactory({ b: 3 }) };
const list = { type: 'List', value: List(['5']) };
const array = { type: 'array', value: ['9'] };
const set = { type: 'Set', value: Set('3') };
const record: TypeValue = { type: 'Record', value: RecordFactory({ b: 3 }) };
const list: TypeValue = { type: 'List', value: List(['5']) };
const array: TypeValue = { type: 'array', value: ['9'] };
const set: TypeValue = { type: 'Set', value: Set('3') };

const incompatibleTypes = [
const incompatibleTypes: Array<[TypeValue, TypeValue]> = [
[map, list],
[map, array],
[map, set],
Expand Down
9 changes: 5 additions & 4 deletions __tests__/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ describe('slice', () => {
(valuesLen, args) => {
const a = Range(0, valuesLen).toArray();
const v = List(a);
const slicedV = v.slice.apply(v, args);
const slicedA = a.slice.apply(a, args);

const slicedV = v.slice(...args);
const slicedA = a.slice(...args);
expect(slicedV.toArray()).toEqual(slicedA);
}
)
Expand All @@ -251,8 +252,8 @@ describe('slice', () => {
const a: Array<number> = [];
entries.forEach((entry) => (a[entry[0]] = entry[1]));
const s = Seq(a);
const slicedS = s.slice.apply(s, args);
const slicedA = a.slice.apply(a, args);
const slicedS = s.slice(...args);
const slicedA = a.slice(...args);
expect(slicedS.toArray()).toEqual(slicedA);
}
)
Expand Down
11 changes: 7 additions & 4 deletions __tests__/splice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ describe('splice', () => {
fc.assert(
fc.property(
fc.array(fc.integer()),
fc.array(fc.sparseArray(fc.integer())),
(values, args) => {
fc.integer(),
fc.integer(),
fc.array(fc.integer()),
(values, index, removeNum, insertValues) => {
const v = List(values);
const a = values.slice(); // clone
const splicedV = v.splice.apply(v, args); // persistent
a.splice.apply(a, args); // mutative

const splicedV = v.splice(index, removeNum, ...insertValues); // persistent
a.splice(index, removeNum, ...insertValues); // mutative
expect(splicedV.toArray()).toEqual(a);
}
)
Expand Down
Loading
0