8000 Migrate from jest to vitest by jdeniau · Pull Request #2085 · immutable-js/immutable-js · GitHub
[go: up one dir, main page]

Skip to content

Migrate from jest to vitest #2085

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

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions __tests__/ArraySeq.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('ArraySequence', () => {
it('every is true when predicate is true for all entries', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/Comparator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { List, OrderedSet, Seq, type Comparator, PairSorting } from 'immutable';
import { describe, expect, it } from 'vitest';

const sourceNumbers: readonly number[] = [3, 4, 5, 6, 7, 9, 10, 12, 90, 92, 95];

Expand Down
1 change: 1 addition & 0 deletions __tests__/Conversion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fromJS, is, List, Map, OrderedMap, Record } from 'immutable';
import { describe, expect, it } from 'vitest';
import fc, { type JsonValue } from 'fast-check';

describe('Conversion', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/Equality.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { is, List, Map, Seq, Set } from 'immutable';
import { describe, expect, it } from 'vitest';
import fc from 'fast-check';

describe('Equality', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/IndexedSeq.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('IndexedSequence', () => {
it('maintains skipped offset', () => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/KeyedSeq.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Range, Seq } from 'immutable';
import { describe, expect, it } from 'vitest';
import fc from 'fast-check';

describe('KeyedSeq', () => {
it('it iterates equivalently', () => {
it('iterates equivalently', () => {
fc.assert(
fc.property(fc.array(fc.integer()), (ints) => {
const seq = Seq(ints);
Expand Down
1 change: 1 addition & 0 deletions __tests__/List.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fromJS, List, Map, Range, Seq, Set } from 'immutable';
import { describe, expect, it } from 'vitest';
import fc from 'fast-check';
import { create as createSeed } from 'random-seed';

Expand Down
1 change: 1 addition & 0 deletions __tests__/ListJS.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { List } from 'immutable';
import { describe, expect, it } from 'vitest';

const NON_NUMBERS = {
array: ['not', 'a', 'number'],
Expand Down
3 changes: 2 additions & 1 deletion __tests__/Map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fromJS, is, List, Map, Range, Record, Seq } from 'immutable';
import { describe, expect, it, vi } from 'vitest';
import fc from 'fast-check';

describe('Map', () => {
Expand Down Expand Up @@ -110,7 +111,7 @@ describe('Map', () => {

it('iterates values', () => {
const m = Map({ a: 'A', b: 'B', c: 'C' });
const iterator = jest.fn();
const iterator = vi.fn();
m.forEach(iterator);
expect(iterator.mock.calls).toEqual([
['A', 'a', m],
Expand Down
5 changes: 3 additions & 2 deletions __tests__/MultiRequire.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as Immutable1 from '../src/Immutable';
import { describe, expect, it, vi } from 'vitest';

jest.resetModules();
vi.resetModules();

const Immutable2 = jest.requireActual('../src/Immutable');
const Immutable2 = await vi.importActual('../src/Immutable');

describe('MultiRequire', () => {
it('might require two different instances of Immutable', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/ObjectSeq.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('ObjectSequence', () => {
6377 it('maps', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/OrderedMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { OrderedMap, Range, Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('OrderedMap', () => {
it('converts from object', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/OrderedSet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { OrderedSet, Map } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('OrderedSet', () => {
it('provides initial values in a mixed order', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/Predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Set,
Stack,
} from 'immutable';
import { describe, expect, it } from 'vitest';

describe('isImmutable', () => {
it('behaves as advertised', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/Range.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Range } from 'immutable';
< F438 /td> import { describe, expect, it } from 'vitest';
import fc from 'fast-check';

describe('Range', () => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/Record.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isKeyed, List, Map, Record, Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('Record', () => {
it('defines a constructor', () => {
Expand Down Expand Up @@ -78,7 +79,7 @@ describe('Record', () => {
const MyType = Record({ a: 1, b: 2, c: 3 });
const t1 = MyType({ a: 10 });
const t2 = MyType({ a: 10, b: 2 });
expect(t1.equals(t2));
expect(t1.equals(t2)).toBe(true);
});

it('if compared against undefined or null should return false', () => {
Expand Down
5 changes: 3 additions & 2 deletions __tests__/RecordJS.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Record } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('Record', () => {
it('defines a record factory', () => {
Expand Down Expand Up @@ -41,8 +42,8 @@ describe('Record', () => {
const t = new Alphabet();
const t2 = t.set('b', 200);

expect(t instanceof Record);
expect(t instanceof Alphabet);
expect(t).toBeInstanceOf(Record);
expect(t).toBeInstanceOf(Alphabet);
expect(t.soup()).toBe(6);
expect(t2.soup()).toBe(204);

Expand Down
1 change: 1 addition & 0 deletions __tests__/Repeat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Repeat } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('Repeat', () => {
it('fixed repeat', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/Seq.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isCollection, isIndexed, isKeyed, Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('Seq', () => {
it('returns undefined if empty and first is called without default argument', () => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/Set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fromJS, is, List, Map, OrderedSet, Seq, Set } from 'immutable';
import { describe, expect, it, vi } from 'vitest';

describe('Set', () => {
it('accepts array of values', () => {
Expand Down Expand Up @@ -138,7 +139,7 @@ describe('Set', () => {

it('iterates values', () => {
const s = Set([1, 2, 3]);
const iterator = jest.fn();
const iterator = vi.fn();
s.forEach(iterator);
expect(iterator.mock.calls).toEqual([
[1, 1, s],
Expand Down
1 change: 1 addition & 0 deletions __tests__/Stack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Seq, Stack } from 'immutable';
import { describe, expect, it } from 'vitest';
import fc from 'fast-check';

function arrayOfSize(s) {
Expand Down
8 changes: 4 additions & 4 deletions __tests__/__snapshots__/Record.ts.snap
A851
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Record does not accept a Record as constructor 1`] = `"Can not call \`Record\` with an immutable Record as default values. Use a plain javascript object instead."`;
exports[`Record > does not accept a Record as constructor 1`] = `[Error: Can not call \`Record\` with an immutable Record as default values. Use a plain javascript object instead.]`;

exports[`Record does not accept a non object as constructor 1`] = `"Can not call \`Record\` with a non-object as default values. Use a plain javascript object instead."`;
exports[`Record > does not accept a non object as constructor 1`] = `[Error: Can not call \`Record\` with a non-object as default values. Use a plain javascript object instead.]`;

exports[`Record does not accept an immutable object that is not a Record as constructor 1`] = `"Can not call \`Record\` with an immutable Collection as default values. Use a plain javascript object instead."`;
exports[`Record > does not accept an immutable object that is not a Record as constructor 1`] = `[Error: Can not call \`Record\` with an immutable Collection as default values. Use a plain javascript object instead.]`;
5 changes: 3 additions & 2 deletions __tests__/concat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { List, Seq, Set } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('concat', () => {
it('concats two sequences', () => {
Expand Down Expand Up @@ -189,7 +190,7 @@ describe('concat', () => {
}

expect(meta.toList().size).toBe(10000);
});
}, 20000);

it('should handle iterator on many concatenated sequences', () => {
const nbLoops = 10000;
Expand All @@ -206,7 +207,7 @@ describe('concat', () => {
done = !!result.done;
}
expect(i).toBe(nbLoops);
});
}, 20000);

it('should iterate on reverse order on concatenated sequences', () => {
let meta = Seq([1]);
Expand Down
1 change: 1 addition & 0 deletions __tests__/count.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Range, Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('count', () => {
it('counts sequences with known lengths', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/find.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('find', () => {
it('find returns notSetValue when match is not found', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/flatten.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Collection, fromJS, List, Range, Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('flatten', () => {
it('flattens sequences one level deep', () => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/fromJS.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { runInNewContext } from 'vm';

import { describe, expect, it } from 'vitest';
import { List, Map, Set, isCollection, fromJS } from 'immutable';

describe('fromJS', () => {
Expand Down Expand Up @@ -64,6 +64,7 @@ describe('fromJS', () => {
expect(isCollection(fromJS({}))).toBe(true);
});

// eslint-disable-next-line vitest/expect-expect
it('is iterable inside of a vm', () => {
runInNewContext(
`
Expand Down
1 change: 1 addition & 0 deletions __tests__/functional/get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { get, Map, List, Range } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('get', () => {
it('for immutable structure', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/functional/has.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { has, Map, List, Range } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('has', () => {
it('for immutable structure', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/functional/remove.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { remove, List, Map } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('remove', () => {
it('for immutable structure', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/functional/set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { set } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('set', () => {
it('for immutable structure', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/functional/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { update } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('update', () => {
it('for immutable structure', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Range } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('get', () => {
it('gets any index', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/getIn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fromJS, getIn, List, Map } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('getIn', () => {
it('deep get', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/groupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Set,
Stack,
} from 'immutable';
import { describe, expect, it } from 'vitest';

describe('groupBy', () => {
it.each`
Expand Down
1 change: 1 addition & 0 deletions __tests__/hasIn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fromJS, hasIn, List, Map } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('hasIn', () => {
it('deep has', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/hash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { hash } from 'immutable';
import { describe, expect, it } from 'vitest';
import fc from 'fast-check';

describe('hash', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/interpose.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Range } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('interpose', () => {
it('separates with a value', () => {
Expand Down
11 changes: 7 additions & 4 deletions __tests__/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Seq,
Set,
} from 'immutable';
import { describe, expect, it } from 'vitest';

describe('Issue #1175', () => {
it('invalid hashCode() response should not infinitly recurse', () => {
Expand All @@ -34,7 +35,7 @@ describe('Issue #1188', () => {
});
});

describe('Issue #1220 : Seq.rest() throws an exception when invoked on a single item sequence ', () => {
describe('Issue #1220 : Seq.rest() throws an exception when invoked on a single item sequence', () => {
it('should be iterable', () => {
// Helper for this test
const ITERATOR_SYMBOL =
Expand Down Expand Up @@ -122,15 +123,17 @@ describe('Issue #1643', () => {

it(`Collection#hashCode() should handle objects that return ${label} for valueOf`, () => {
const set = Set().add(new MyClass());
set.hashCode();
expect(() => set.hashCode()).not.toThrow();
});
});
});

describe('Issue #1785', () => {
const emptyRecord = Record({})();
it('merge() should not return undefined', () => {
const emptyRecord = Record({})();

expect(emptyRecord.merge({ id: 1 })).toBe(emptyRecord);
expect(emptyRecord.merge({ id: 1 })).toBe(emptyRecord);
});
});

describe('Issue #1475', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/join.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Seq } from 'immutable';
import { describe, expect, it } from 'vitest';
import fc from 'fast-check';

describe('join', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Record,
Set,
} from 'immutable';
import { describe, expect, it } from 'vitest';

describe('merge', () => {
it('merges two maps', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/minmax.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { is, Seq } from 'immutable';
import { describe, expect, it } from 'vitest';
import fc from 'fast-check';

const genHeterogeneousishArray = fc.oneof(
Expand Down
5 changes: 3 additions & 2 deletions __tests__/partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
Seq,
Set as ISet,
} from 'immutable';
import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest';

describe('partition', () => {
let isOdd: jest.Mock<unknown, [x: number]>;
let isOdd: Mock<(x: number) => number>;

beforeEach(() => {
isOdd = jest.fn((x) => x % 2);
isOdd = vi.fn((x) => x % 2);
});

it('partitions keyed sequence', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/slice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { List, Range, Seq } from 'immutable';
import { describe, expect, it } from 'vitest';
import fc from 'fast-check';

describe('slice', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/sort.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { List, OrderedMap, Range, Seq } from 'immutable';
import { describe, expect, it } from 'vitest';

describe('sort', () => {
it('sorts a sequence', () => {
Expand Down
Loading
0