Skip to content

Commit

Permalink
move to vitest instead of jest to simplify everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Jul 3, 2024
1 parent 49ca82d commit d5c2523
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 24 deletions.
6 changes: 0 additions & 6 deletions jest.config.cjs

This file was deleted.

10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@
"scripts": {
"build": "rm -rf dist && tsup src/index.ts --format esm,cjs --dts",
"watch": "tsc -W",
"test": "jest",
"test:watch": "jest --watch"
"test": "vitest run"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.4",
"@types/assert": "^1.5.10",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"assert": "^2.1.0",
"bson": "^6.8.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"tsup": "^8.1.0",
"typescript": "^5.5.2"
"typescript": "^5.5.2",
"vitest": "^1.6.0"
},
"dependencies": {
"@crystallize/js-api-client": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions tests/item/item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ObjectId } from 'bson';
import { VariablesType } from '@crystallize/js-api-client';
import { Item } from '@crystallize/schema';
import { getItemQuery, item, updateFolderMutation } from '../../src/item/index.js';

import { expect, it, vi } from 'vitest';
const mockTenantId = new ObjectId().toString();
const mockItemId = new ObjectId().toString();

Expand Down Expand Up @@ -60,7 +60,7 @@ const testCases: testCase[] = [

testCases.forEach((tc) =>
it(tc.name, async () => {
let mockPimApi = jest.fn().mockResolvedValueOnce({
let mockPimApi = vi.fn().mockResolvedValueOnce({
item: {
get: tc.existingItem || null,
},
Expand Down
1 change: 1 addition & 0 deletions tests/shape/createMutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ObjectId } from 'bson';
import { CreateShapeInput } from '@crystallize/schema';
import { createShapeMutation } from '../../src/shape/mutations/create';
import { deepEqual, equal } from 'assert';
import { expect, it } from 'vitest';

const mockTenantId = new ObjectId().toString();

Expand Down
6 changes: 2 additions & 4 deletions tests/shape/shape.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ObjectId } from 'bson';
import { VariablesType } from '@crystallize/js-api-client';
import { Shape } from '@crystallize/schema';
import { createShapeMutation, getShapeQuery, shape, updateShapeMutation } from '../../src/shape';
import { expect, it, vi } from 'vitest';

const mockTenantId = new ObjectId().toString();

Expand Down Expand Up @@ -43,7 +44,6 @@ const testCases: testCase[] = [
}),
createShapeMutation({
input: {
tenantId: mockTenantId,
identifier: 'some-shape',
name: 'Some Shape',
type: 'product',
Expand Down Expand Up @@ -98,7 +98,6 @@ const testCases: testCase[] = [
}),
createShapeMutation({
input: {
tenantId: mockTenantId,
identifier: 'some-shape',
name: 'Some Shape',
type: 'product',
Expand Down Expand Up @@ -159,7 +158,6 @@ const testCases: testCase[] = [
identifier: 'some-shape',
}),
updateShapeMutation({
tenantId: mockTenantId,
identifier: 'some-shape',
input: {
name: 'Some Shape 2',
Expand All @@ -185,7 +183,7 @@ const testCases: testCase[] = [

testCases.forEach((tc) =>
it(tc.name, async () => {
let mockPimApi = jest.fn().mockResolvedValueOnce({
let mockPimApi = vi.fn().mockResolvedValueOnce({
shape: {
get: tc.existingShape || null,
},
Expand Down
3 changes: 1 addition & 2 deletions tests/shape/updateMutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ObjectId } from 'bson';
import { UpdateShapeInput } from '@crystallize/schema';
import { updateShapeMutation } from '../../src/shape/mutations/update';
import { deepEqual, equal } from 'assert';
import { expect, it } from 'vitest';

const mockTenantId = new ObjectId().toString();

Expand Down Expand Up @@ -98,7 +99,6 @@ testCases.forEach((tc) =>
updateShapeMutation({
input: tc.input,
identifier: 'shape-identifier',
tenantId: mockTenantId,
}),
).toThrow(tc.error);
return;
Expand All @@ -107,7 +107,6 @@ testCases.forEach((tc) =>
const { query, variables } = updateShapeMutation({
input: tc.input,
identifier: 'shape-identifier',
tenantId: mockTenantId,
});
const re = / /g;
equal(
Expand Down
3 changes: 2 additions & 1 deletion tests/topic/createMutation.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ZodError } from 'zod';
import { ObjectId } from 'mongodb';
import { ObjectId } from 'bson';
import { CreateTopicInput } from '@crystallize/schema';
import { deepEqual, equal } from 'assert';
import { createTopicMutation } from '../../src/topic/mutations/create';
import { expect, it } from 'vitest';

const mockTenantId = new ObjectId().toString();

Expand Down
5 changes: 3 additions & 2 deletions tests/topic/topic.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ZodError } from 'zod';
import { ObjectId } from 'mongodb';
import { ObjectId } from 'bson';
import { VariablesType } from '@crystallize/js-api-client';
import { Topic } from '@crystallize/schema';
import { getTopicQuery, createTopicMutation, updateTopicMutation, topic } from '../../src/topic';
import { expect, it, vi } from 'vitest';

interface testCase {
name: string;
Expand Down Expand Up @@ -211,7 +212,7 @@ const testCases: testCase[] = [

testCases.forEach((tc) =>
it(tc.name, async () => {
let mockPimApi = jest.fn();
let mockPimApi = vi.fn();

if (tc.existingTopic) {
mockPimApi = mockPimApi
Expand Down
1 change: 1 addition & 0 deletions tests/topic/updateMutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ZodError } from 'zod';
import { UpdateTopicInput } from '@crystallize/schema';
import { deepEqual, equal } from 'assert';
import { updateTopicMutation } from '../../src/topic/mutations/update';
import { expect, it } from 'vitest';

interface testCase {
name: string;
Expand Down

0 comments on commit d5c2523

Please sign in to comment.