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 2, 2024
1 parent aeebe7f commit 931e7e4
Show file tree
Hide file tree
Showing 48 changed files with 734 additions and 7,694 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ codeclean: ## Code Clean
.PHONY: tests
tests: ## Run the tests
@echo " ..:: Mono Repo Testing ::.."
@yarn test
@yarn prettier --check .
@pnpm test

.PHONY: add-component
add-component: ## Create an empty structure for a new Component
Expand All @@ -63,4 +62,4 @@ add-component-compliance-files: ## Add the compliance files into all the compone
.PHONY: start-demo-app
start-demo-app: ## Start Demo App
@echo " ..:: Starting Demo App ::.."
@cd docs/react-app && npm start
@pnpm run demo
3 changes: 3 additions & 0 deletions apps/demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
build: {
chunkSizeWarningLimit: 2000,
},
});
6 changes: 0 additions & 6 deletions components/import-export-sdk/jest.config.cjs

This file was deleted.

10 changes: 3 additions & 7 deletions components/import-export-sdk/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 components/import-export-sdk/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
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 components/import-export-sdk/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
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
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 components/import-export-sdk/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
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
5 changes: 2 additions & 3 deletions components/js-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"scripts": {
"watch": "tsc -W",
"build": "rm -rf dist && tsup src/index.ts --format esm,cjs --dts",
"test": "jest",
"test:watch": "jest --watch"
"test": "vitest run"
},
"repository": {
"type": "git",
Expand All @@ -33,7 +32,7 @@
"@types/node": "^20.10.9",
"tsup": "^8.1.0",
"typescript": "^5.5.2",
"jest": "^29.7.0"
"vitest": "^1.6.0"
},
"dependencies": {
"dotenv": "^16.4.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { createClient } = require('../dist/index.js');
import { test, expect } from 'vitest';
import { createClient } from '../src';

test('callCatalogueApi: Raw fetch a product name: Bamboo Chair', async () => {
const CrystallizeClient = createClient({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { createClient, createCatalogueFetcher } = require('../dist/index.js');
const { VariableType } = require('json-to-graphql-query');
import { test, expect } from 'vitest';
import { createClient, createCatalogueFetcher } from '../src';
import { VariableType } from 'json-to-graphql-query';

test('Test with Profiling 1 ', async () => {
const variables = {
Expand All @@ -9,7 +10,7 @@ test('Test with Profiling 1 ', async () => {

const expectedQuery = `query ($language: String!, $path: String!) { catalogue (language: $language, path: $path) { ... on Product { name } } }`;

let profiledQuery = {};
let profiledQuery: any = {};

const apiClient = createClient(
{
Expand Down Expand Up @@ -42,7 +43,7 @@ test('Test with Profiling 1 ', async () => {
);

const fetcher = createCatalogueFetcher(apiClient);
const response = await fetcher(
const response = await fetcher<any>(
{
__variables: {
language: 'String!',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { catalogueFetcherGraphqlBuilder } = require('../dist/index.js');
const { jsonToGraphQLQuery } = require('json-to-graphql-query');
import { test, expect } from 'vitest';
import { catalogueFetcherGraphqlBuilder } from '../src';
import { jsonToGraphQLQuery } from 'json-to-graphql-query';

test('Catalogue Query Builder Test', () => {
const builder = catalogueFetcherGraphqlBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { CrystallizeSubscriptionContractManager } = require('../dist/index.js');
import { test } from 'vitest';
import { CrystallizeSubscriptionContractManager } from '../src';

test('catalogAPI: Test', async () => {
try {
const template =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { createClient, createProductHydrater } = require('../dist/index.js');
import { test, expect } from 'vitest';
import { createClient, createProductHydrater } from '../src';

test('Hydrate Paths', async () => {
const CrystallizeClient = createClient({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { createClient, createProductHydrater } = require('../dist/index.js');
import { test, expect } from 'vitest';
import { createClient, createProductHydrater } from '../src';

test('Hydrate Skus', async () => {
const CrystallizeClient = createClient({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { createNavigationFetcher, createClient } = require('../dist/index.js');
const { walkTree } = require('./util');
import { test, expect } from 'vitest';
import { createClient, createNavigationFetcher } from '../src';
import { walkTree } from './util';

test('Test Nav fetching Node: Shop', async () => {
const CrystallizeClient = createClient({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { createNavigationFetcher, createClient } = require('../dist/index.js');
const { walkTree } = require('./util');
import { test, expect } from 'vitest';
import { createNavigationFetcher, createClient } from '../src';
import { walkTree } from './util';

test('Test Nav fetching Topic: /', async () => {
const CrystallizeClient = createClient({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { CrystallizeOrderFetcherById, CrystallizeOrderFetcherByCustomerIdentifier } = require('../dist/index.js');
import { test, expect } from 'vitest';
import { CrystallizeOrderFetcherById, CrystallizeOrderFetcherByCustomerIdentifier } from '../src';

test('Oder By ID', async () => {
const fetcher = CrystallizeOrderFetcherById;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { CrystallizeCreateOrderPaymentUpdater } = require('../dist/index.js');
import { test, expect } from 'vitest';
import { CrystallizeCreateOrderPaymentUpdater } from '../src';

test('pimAPi: Update Order Payment: Test Validation', async () => {
// it has to fail with 404 because we don't have any credentials
Expand All @@ -7,6 +8,7 @@ test('pimAPi: Update Order Payment: Test Validation', async () => {
const result = await caller('624b2fca14fa92fb50f0b8dd', {
payment: [
{
//@ts-ignore
provider: 'custom2',
custom: {
properties: [
Expand All @@ -22,6 +24,7 @@ test('pimAPi: Update Order Payment: Test Validation', async () => {
},
},
{
//@ts-ignore
provider: 'custom',
custom: {
properties: [
Expand Down Expand Up @@ -50,6 +53,7 @@ test('pimAPi: Update Order Payment', async () => {
const result = await caller('624b2fca14fa92fb50f0b8dd', {
payment: [
{
//@ts-ignore
provider: 'custom',
custom: {
properties: [
Expand All @@ -65,6 +69,7 @@ test('pimAPi: Update Order Payment', async () => {
},
},
{
//@ts-ignore
provider: 'custom',
custom: {
properties: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { pricesForUsageOnTier } = require('../dist/index.js');
import { test, expect } from 'vitest';
import { pricesForUsageOnTier } from '../src';

const tiers1 = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const { CrystallizeOrderPusher } = require('../dist/index.js');
import { test, expect } from 'vitest';
import { CrystallizeOrderPusher } from '../src';

test('orderAPi: Test Validation', async () => {
// it has to fail with 404 because we don't have any credentials
try {
const caller = CrystallizeOrderPusher;
await caller({
customer: {
//@ts-ignore
firstName2: 'William',
lastName: 'Wallace',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { CrystallizeSubscriptionContractManager } = require('../dist/index.js');
import { test, expect } from 'vitest';
import { CrystallizeSubscriptionContractManager } from '../src';

const period = {
currency: 'eur',
Expand Down Expand Up @@ -95,6 +96,7 @@ test('pimAPi: Test Validation', async () => {
const caller = CrystallizeSubscriptionContractManager.create;
await caller({
...contract,
//@ts-ignore
initial2: {
...period,
},
Expand All @@ -110,9 +112,11 @@ test('pimAPi Push a new Contract', async () => {
const caller = CrystallizeSubscriptionContractManager.create;
await caller({
...contract,
//@ts-ignore
initial: {
...period,
},
//@ts-ignore
recurring: {
...period,
},
Expand Down
Loading

0 comments on commit 931e7e4

Please sign in to comment.