diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000000..650c513d7e --- /dev/null +++ b/jest.config.js @@ -0,0 +1,3 @@ +module.exports = { + preset: 'ts-jest', +} diff --git a/packages/api/jest.config.js b/packages/api/jest.int.config.js similarity index 76% rename from packages/api/jest.config.js rename to packages/api/jest.int.config.js index 0f02b4d0cf..62f14f74eb 100644 --- a/packages/api/jest.config.js +++ b/packages/api/jest.int.config.js @@ -1,5 +1,5 @@ module.exports = { - preset: 'ts-jest', + ...require('../../jest.config.js'), modulePathIgnorePatterns: ['/dist'], collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}'], } diff --git a/packages/api/jest.unit.config.js b/packages/api/jest.unit.config.js new file mode 100644 index 0000000000..a0632c1c30 --- /dev/null +++ b/packages/api/jest.unit.config.js @@ -0,0 +1,20 @@ +module.exports = { + ...require('../../jest.config.js'), + testEnvironment: 'node', + verbose: true, + transform: { + '\\.ts$': ['ts-jest'], + }, + modulePathIgnorePatterns: [ + '/dist', + 'index.ts', + 'resolvers/', + '__generated__', + 'typings/', + ], + testMatch: ['**/*.test.ts'], + clearMocks: true, + collectCoverageFrom: ['/src/**/*.{ts,tsx,js,jsx}'], + coverageProvider: 'v8', + coverageDirectory: 'coverage', +} diff --git a/packages/api/package.json b/packages/api/package.json index da640250a8..e44a717a54 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -29,7 +29,11 @@ "build": "graphql-codegen --config codegen.yml && (pnpm build:cjs && pnpm build:esm)", "build:cjs": "tsc --module commonjs --moduleResolution node10 --outDir dist/cjs && copyfiles \"src/**/*.graphql\" dist/cjs", "build:esm": "tsc && copyfiles \"src/**/*.graphql\" dist/esm", - "test": "jest", + "test:int": "jest --projects jest.int.config.js", + "test:intc": "jest --projects jest.int.config.js --coverage", + "test:unit": "jest --projects jest.unit.config.js --silent", + "test:unitc": "jest --projects jest.unit.config.js --silent --coverage", + "test": "pnpm run test:unit && pnpm run test:int", "generate": "graphql-codegen --config codegen.yml" }, "dependencies": { diff --git a/packages/api/test/__snapshots__/mutations.test.ts.snap b/packages/api/test/int/__snapshots__/mutations.test.ts.snap similarity index 100% rename from packages/api/test/__snapshots__/mutations.test.ts.snap rename to packages/api/test/int/__snapshots__/mutations.test.ts.snap diff --git a/packages/api/test/__snapshots__/queries.test.ts.snap b/packages/api/test/int/__snapshots__/queries.test.ts.snap similarity index 100% rename from packages/api/test/__snapshots__/queries.test.ts.snap rename to packages/api/test/int/__snapshots__/queries.test.ts.snap diff --git a/packages/api/test/mutations.test.ts b/packages/api/test/int/mutations.test.ts similarity index 96% rename from packages/api/test/mutations.test.ts rename to packages/api/test/int/mutations.test.ts index 09dc13ccd9..f5b8327c3b 100644 --- a/packages/api/test/mutations.test.ts +++ b/packages/api/test/int/mutations.test.ts @@ -15,8 +15,8 @@ import { ValidateCartMutation, ValidCart, } from '../mocks/ValidateCartMutation' -import type { Options } from '../src' -import { getContextFactory, getSchema } from '../src' +import type { Options } from '../../src' +import { getContextFactory, getSchema } from '../../src' const apiOptions = { platform: 'vtex', @@ -71,7 +71,7 @@ function pickFetchAPICallResult( ) } -jest.mock('../src/platforms/vtex/clients/fetch.ts', () => ({ +jest.mock('../../src/platforms/vtex/clients/fetch.ts', () => ({ fetchAPI: async ( info: RequestInfo, init?: RequestInit, diff --git a/packages/api/test/queries.test.ts b/packages/api/test/int/queries.test.ts similarity index 97% rename from packages/api/test/queries.test.ts rename to packages/api/test/int/queries.test.ts index ea86829e6d..4682cc33c9 100644 --- a/packages/api/test/queries.test.ts +++ b/packages/api/test/int/queries.test.ts @@ -37,8 +37,8 @@ import { shippingSimulationFetch, ShippingSimulationQueryResult, } from '../mocks/ShippingQuery' -import type { Options } from '../src' -import { getContextFactory, getSchema } from '../src' +import type { Options } from '../../src' +import { getContextFactory, getSchema } from '../../src' const apiOptions = { platform: 'vtex', @@ -95,7 +95,7 @@ function pickFetchAPICallResult( ) } -jest.mock('../src/platforms/vtex/clients/fetch.ts', () => ({ +jest.mock('../../src/platforms/vtex/clients/fetch.ts', () => ({ fetchAPI: ( info: RequestInfo, init?: RequestInit, diff --git a/packages/api/test/schema.test.ts b/packages/api/test/int/schema.test.ts similarity index 98% rename from packages/api/test/schema.test.ts rename to packages/api/test/int/schema.test.ts index 47fa97b71d..13047c905e 100644 --- a/packages/api/test/schema.test.ts +++ b/packages/api/test/int/schema.test.ts @@ -1,7 +1,7 @@ import type { GraphQLSchema } from 'graphql' import { assertValidSchema } from 'graphql' -import { getSchema } from '../src' +import { getSchema } from '../../src' const TYPES = [ 'StoreAggregateOffer', diff --git a/packages/api/test/vtex.aggregateOffer.test.ts b/packages/api/test/int/vtex.aggregateOffer.test.ts similarity index 80% rename from packages/api/test/vtex.aggregateOffer.test.ts rename to packages/api/test/int/vtex.aggregateOffer.test.ts index 65248873f6..550b0d679a 100644 --- a/packages/api/test/vtex.aggregateOffer.test.ts +++ b/packages/api/test/int/vtex.aggregateOffer.test.ts @@ -1,5 +1,5 @@ -import { bestOfferFirst } from '../src/platforms/vtex/utils/productStock' -import type { CommertialOffer } from '../src/platforms/vtex/clients/search/types/ProductSearchResult' +import { bestOfferFirst } from '../../src/platforms/vtex/utils/productStock' +import type { CommertialOffer } from '../../src/platforms/vtex/clients/search/types/ProductSearchResult' type TestItem = Pick diff --git a/packages/api/test/vtex.cookies.test.ts b/packages/api/test/int/vtex.cookies.test.ts similarity index 97% rename from packages/api/test/vtex.cookies.test.ts rename to packages/api/test/int/vtex.cookies.test.ts index 0cb969fbef..8398b4e34c 100644 --- a/packages/api/test/vtex.cookies.test.ts +++ b/packages/api/test/int/vtex.cookies.test.ts @@ -4,9 +4,9 @@ import { getWithCookie, updatesContextStorageCookies, getStoreCookie, -} from '../src/platforms/vtex/utils/cookies' -import type { ContextForCookies } from '../src/platforms/vtex/utils/cookies' -import type { Context } from '../src/platforms/vtex' +} from '../../src/platforms/vtex/utils/cookies' +import type { ContextForCookies } from '../../src/platforms/vtex/utils/cookies' +import type { Context } from '../../src/platforms/vtex' describe('getUpdatedCookie', () => { it('Should return undefined if context has no headers', () => { diff --git a/packages/api/test/vtex.shouldUpdateShippingData.test.ts b/packages/api/test/int/vtex.shouldUpdateShippingData.test.ts similarity index 96% rename from packages/api/test/vtex.shouldUpdateShippingData.test.ts rename to packages/api/test/int/vtex.shouldUpdateShippingData.test.ts index bd2d84a520..299e0b6053 100644 --- a/packages/api/test/vtex.shouldUpdateShippingData.test.ts +++ b/packages/api/test/int/vtex.shouldUpdateShippingData.test.ts @@ -8,7 +8,7 @@ import { mockSessionInvalidDeliveryWindow, mockSessionValidDeliveryWindow, } from '../mocks/shouldUpdateShippingData' -import { shouldUpdateShippingData } from '../src/platforms/vtex/utils/shouldUpdateShippingData' +import { shouldUpdateShippingData } from '../../src/platforms/vtex/utils/shouldUpdateShippingData' describe('shouldUpdateShippingData', () => { it('For an empty items array at the OrderForm it should not update the Shipping Data', () => { diff --git a/packages/api/test/vtex.skuVariants.test.ts b/packages/api/test/int/vtex.skuVariants.test.ts similarity index 98% rename from packages/api/test/vtex.skuVariants.test.ts rename to packages/api/test/int/vtex.skuVariants.test.ts index 13614658d4..51f39336e3 100644 --- a/packages/api/test/vtex.skuVariants.test.ts +++ b/packages/api/test/int/vtex.skuVariants.test.ts @@ -9,7 +9,7 @@ import { getActiveSkuVariations, getFormattedVariations, getVariantsByName, -} from '../src/platforms/vtex/utils/skuVariants' +} from '../../src/platforms/vtex/utils/skuVariants' describe('createSlugsMap', () => { it('should return an empty object for a product that has no sku specification properties.', () => { diff --git a/packages/api/mocks/AllCollectionsQuery.ts b/packages/api/test/mocks/AllCollectionsQuery.ts similarity index 100% rename from packages/api/mocks/AllCollectionsQuery.ts rename to packages/api/test/mocks/AllCollectionsQuery.ts diff --git a/packages/api/mocks/AllProductsQuery.ts b/packages/api/test/mocks/AllProductsQuery.ts similarity index 100% rename from packages/api/mocks/AllProductsQuery.ts rename to packages/api/test/mocks/AllProductsQuery.ts diff --git a/packages/api/mocks/CollectionQuery.ts b/packages/api/test/mocks/CollectionQuery.ts similarity index 100% rename from packages/api/mocks/CollectionQuery.ts rename to packages/api/test/mocks/CollectionQuery.ts diff --git a/packages/api/mocks/ProductQuery.ts b/packages/api/test/mocks/ProductQuery.ts similarity index 100% rename from packages/api/mocks/ProductQuery.ts rename to packages/api/test/mocks/ProductQuery.ts diff --git a/packages/api/mocks/RedirectQuery.ts b/packages/api/test/mocks/RedirectQuery.ts similarity index 100% rename from packages/api/mocks/RedirectQuery.ts rename to packages/api/test/mocks/RedirectQuery.ts diff --git a/packages/api/mocks/SearchQuery.ts b/packages/api/test/mocks/SearchQuery.ts similarity index 100% rename from packages/api/mocks/SearchQuery.ts rename to packages/api/test/mocks/SearchQuery.ts diff --git a/packages/api/mocks/SellersQuery.ts b/packages/api/test/mocks/SellersQuery.ts similarity index 100% rename from packages/api/mocks/SellersQuery.ts rename to packages/api/test/mocks/SellersQuery.ts diff --git a/packages/api/mocks/ShippingQuery.ts b/packages/api/test/mocks/ShippingQuery.ts similarity index 100% rename from packages/api/mocks/ShippingQuery.ts rename to packages/api/test/mocks/ShippingQuery.ts diff --git a/packages/api/mocks/ValidateCartMutation.ts b/packages/api/test/mocks/ValidateCartMutation.ts similarity index 100% rename from packages/api/mocks/ValidateCartMutation.ts rename to packages/api/test/mocks/ValidateCartMutation.ts diff --git a/packages/api/mocks/salesChannel.ts b/packages/api/test/mocks/salesChannel.ts similarity index 100% rename from packages/api/mocks/salesChannel.ts rename to packages/api/test/mocks/salesChannel.ts diff --git a/packages/api/mocks/shouldUpdateShippingData.ts b/packages/api/test/mocks/shouldUpdateShippingData.ts similarity index 100% rename from packages/api/mocks/shouldUpdateShippingData.ts rename to packages/api/test/mocks/shouldUpdateShippingData.ts diff --git a/packages/api/mocks/skuVariants.ts b/packages/api/test/mocks/skuVariants.ts similarity index 100% rename from packages/api/mocks/skuVariants.ts rename to packages/api/test/mocks/skuVariants.ts diff --git a/packages/api/test/unit/platforms/vtex/utils/canonical.test.ts b/packages/api/test/unit/platforms/vtex/utils/canonical.test.ts new file mode 100644 index 0000000000..c8487ba696 --- /dev/null +++ b/packages/api/test/unit/platforms/vtex/utils/canonical.test.ts @@ -0,0 +1,11 @@ +import type { Product } from '../../../../../src/platforms/vtex/clients/search/types/ProductSearchResult' +import { canonicalFromProduct } from '../../../../../src/platforms/vtex/utils/canonical' + +describe('canonicalFromProduct', () => { + it('Should return proper link', () => { + const product = { + linkText: 'product-name', + } + expect(canonicalFromProduct(product as Product)).toBe('/product-name/p') + }) +}) diff --git a/packages/cli/jest.config.js b/packages/cli/jest.config.js index 8bb37208d7..d5dde2321e 100644 --- a/packages/cli/jest.config.js +++ b/packages/cli/jest.config.js @@ -1,5 +1,5 @@ /** @type {import('ts-jest').JestConfigWithTsJest} */ module.exports = { - preset: 'ts-jest', + ...require('../../jest.config.js'), testEnvironment: 'node', } diff --git a/packages/components/jest.config.js b/packages/components/jest.config.js index 06853f0d9f..4d53caffb6 100644 --- a/packages/components/jest.config.js +++ b/packages/components/jest.config.js @@ -1,6 +1,6 @@ /** @type {import('ts-jest').JestConfigWithTsJest} */ module.exports = { - preset: 'ts-jest', + ...require('../../jest.config.js'), testEnvironment: 'jest-environment-jsdom', setupFilesAfterEnv: ['/jest.setup.ts'], } diff --git a/packages/core/jest.config.js b/packages/core/jest.config.js index fbe216f6d6..3029ac5e5e 100644 --- a/packages/core/jest.config.js +++ b/packages/core/jest.config.js @@ -3,7 +3,7 @@ const { compilerOptions } = require('./tsconfig') /** @type {import('ts-jest').JestConfigWithTsJest} */ module.exports = { - preset: 'ts-jest', + ...require('../../jest.config.js'), testPathIgnorePatterns: ['/node_modules/', 'cypress/'], /** Support importing from src/ or @generated/ folders (TS path imports) */ diff --git a/packages/sdk/jest.config.js b/packages/sdk/jest.config.js index 94dd6c4303..8a7ea94641 100644 --- a/packages/sdk/jest.config.js +++ b/packages/sdk/jest.config.js @@ -1,5 +1,5 @@ module.exports = { - preset: 'ts-jest', + ...require('../../jest.config.js'), modulePathIgnorePatterns: ['/dist'], collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}'], setupFiles: ['./test/setup.ts'],