Skip to content
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
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
coverage/
*.snap.ts
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "vtex",
"root": true,
"env": {
"node": true,
"jest": true,
"es6": true
}
}
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @vtex-apps/intelligent-search-apps
58 changes: 54 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
node/**/!(main).js
node/**/*.js.map
.vscode/
jspm_packages

# Optional npm cache directory
.npm

# webpack
.happypack/
webpack_cache/

# Optional REPL history
.node_repl_history

# Generate directory
render_build
accounts

.vscode

lib

entrypoints.json
jsconfig.json

.DS_Store
node/package-lock.json

**/yarn-error.log
7 changes: 1 addition & 6 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"jsxBracketSameLine": true
}
"@vtex/prettier-config"
5 changes: 3 additions & 2 deletions .vtexignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
node_modules/
node/node_modules/
node/tslint.json
react/node_modules/
.vscode/
.gitignore
node/**/__tests__/**
node/**/__mocks__/**
node/**/__snapshots__/**
node/**/*.test.js
node/**/*.test.ts
node/**/*.test.tsx
node/**/*.test.tsx
node/coverage/*
node/mocks
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Bump node builder to v7.

## [1.72.0] - 2024-08-20

### Added
Expand Down
1 change: 0 additions & 1 deletion CODEOWNERS

This file was deleted.

21 changes: 21 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// dangerfile.js
const { verify } = require('@vtex/danger')

const config = {
// Set to true to enforce keepachangelog rules.
keepachangelog: {
changeVersion: false,
},
rules: {
description: ['fail', { minLength: 20 }],
assignee: 'fail',
reviewers: 'fail',
pr_size: ['warn', { additionLimit: 800, deletionLimit: -1 }],
lock_file: 'warn',
no_ignored_test: ['fail', { pattern: /test|spec/i }],
no_debugger: ['fail', { pattern: /\.[tj]sx?$/i }],
enforce_graphql_provider: 'off',
},
}

verify(config)
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "GraphQL resolvers for the VTEX API for the catalog and orders.",
"credentialType": "absolute",
"builders": {
"node": "6.x",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main change

"node": "7.x",
"docs": "0.x"
},
"dependencies": {
Expand Down
19 changes: 0 additions & 19 deletions node/.eslintrc

This file was deleted.

43 changes: 32 additions & 11 deletions node/__mocks__/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
const promisify = (obj: any) => {
return new Promise(resolve => resolve(obj))
return new Promise((resolve) => resolve(obj))
}

const searchClientMock = {
Expand All @@ -16,10 +17,20 @@ const searchClientMock = {
categories: jest.fn(),
crossSelling: jest.fn(),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
productById: jest.fn((_id: string, _cacheable: boolean = true) => promisify(null)),
productById: jest.fn((_id: string, _cacheable = true) => promisify(null)),
filtersInCategoryFromId: jest.fn(),
}

const isClientMock = {
productSearch: jest.fn((params: any) => {
const { query, map } = params

return promisify({
translatedArgs: { query, map },
})
}),
}

const messagesGraphQLClientMock = {
translate: (str: string) => promisify(str),
}
Expand All @@ -35,10 +46,12 @@ const segmentClientMock = {
}),
}

export const getBindingLocale = () => mockContext.vtex.binding.locale
const generateDeepCopy = (obj: any) => JSON.parse(JSON.stringify(obj))

const rewriterClientMock: any = {
getRoute: jest.fn((id: string, type: string, bindingId: string) => promisify(`${id}-${type}-${bindingId}-${getBindingLocale()}`))
getRoute: jest.fn((id: string, type: string, bindingId: string) =>
promisify(`${id}-${type}-${bindingId}-${getBindingLocale()}`)
),
}

const getLocale = () => mockContext.vtex.locale
Expand All @@ -49,11 +62,9 @@ const initialCtxState = {
platform: 'vtex',
locale: 'pt-BR',
tenant: { locale: 'pt-BR' },
binding: { id: 'abc', locale: 'pt-BR' }
binding: { id: 'abc', locale: 'pt-BR' },
}

const generateDeepCopy = (obj: any) => JSON.parse(JSON.stringify(obj))

export const mockContext: any = {
vtex: {
...generateDeepCopy(initialCtxState),
Expand All @@ -63,15 +74,25 @@ export const mockContext: any = {
segment: segmentClientMock,
messagesGraphQL: messagesGraphQLClientMock,
rewriter: rewriterClientMock,
vbase: { getJSON: jest.fn() },
intelligentSearchApi: isClientMock,
},
state: {
messagesBindingLanguage: {
loadMany: jest.fn((messages: any) => messages.map((message: any) => `${message.content}-${getLocale()}`))
loadMany: jest.fn((messages: any) =>
messages.map((message: any) => `${message.content}-${getLocale()}`)
),
},
messagesTenantLanguage: {
load: jest.fn((message: any) => `${message.content}-${getTenantLocale()}`)
}
load: jest.fn(
(message: any) => `${message.content}-${getTenantLocale()}`
),
},
},
}

export const resetContext = () => {mockContext.vtex = { ...generateDeepCopy(initialCtxState) }}
export const getBindingLocale = () => mockContext.vtex.binding.locale

export const resetContext = () => {
mockContext.vtex = { ...generateDeepCopy(initialCtxState) }
}
12 changes: 3 additions & 9 deletions node/globals.ts → node/global.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import {
import type {
IOContext,
MetricsAccumulator,
ParamsContext,
RecorderState,
SegmentData,
ServiceContext,
MessagesLoaderV2,
} from '@vtex/api'

import { Clients } from './clients'

if (!global.metrics) {
console.error('No global.metrics at require time')
global.metrics = new MetricsAccumulator()
}
import type { Clients } from './clients'

declare global {
type Context = ServiceContext<Clients, State, CustomContext>
Expand All @@ -23,7 +17,7 @@ declare global {
messagesBindingLanguage?: MessagesLoaderV2
}

interface StaleRevalidateData<T>{
interface StaleRevalidateData<T> {
ttl: Date
data: T
}
Expand Down
6 changes: 2 additions & 4 deletions node/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import './globals'

import { Cached, LRUCache, RecorderState, Service, method } from '@vtex/api'
import type { Cached, RecorderState } from '@vtex/api'
import { LRUCache, Service, method } from '@vtex/api'
import schema from 'vtex.search-graphql/graphql'

import { Clients } from './clients'
Expand All @@ -24,7 +23,6 @@ const messagesCache = new LRUCache<string, Cached>({ max: 3000 })
const vbaseCache = new LRUCache<string, Cached>({ max: 3000 })
const appsCache = new LRUCache<string, Cached>({ max: 3000 })


metrics.trackCache('segment', segmentCache)
metrics.trackCache('search', searchCache)
metrics.trackCache('messages', messagesCache)
Expand Down
24 changes: 24 additions & 0 deletions node/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',
preset: 'ts-jest',
transform: {
'^.+\\.ts?$': 'ts-jest',
},
testRegex: '(.*(test|spec)).ts?$',
testEnvironment: 'node',
}
Loading
Loading