index
int64
0
0
repo_id
stringlengths
16
181
file_path
stringlengths
28
270
content
stringlengths
1
11.6M
__index_level_0__
int64
0
10k
0
petrpan-code/sanity-io/sanity/packages/sanity/test/validation
petrpan-code/sanity-io/sanity/packages/sanity/test/validation/__snapshots__/array.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`array exact length constraint: exact length: too long 1`] = ` Array [ Object { "item": ValidationError { "children": undefined, "message": "Must have exactly 2 items", "operation": undefined, "paths": Array [], }, "level": "error...
4,500
0
petrpan-code/sanity-io/sanity/packages/sanity/test/validation
petrpan-code/sanity-io/sanity/packages/sanity/test/validation/__snapshots__/children.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`child rules all() rules - multiple failures: all() rules - match 1`] = `Array []`; exports[`child rules all() rules - multiple failures: all() rules - multiple failures, custom messages 1`] = ` Array [ Object { "item": ValidationError { "children": Array...
4,501
0
petrpan-code/sanity-io/sanity/packages/sanity/test/validation
petrpan-code/sanity-io/sanity/packages/sanity/test/validation/__snapshots__/generics.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`generics can customize error messages 1`] = ` Array [ Object { "item": ValidationError { "children": undefined, "message": "Dude it needs to be a string", "operation": undefined, "paths": Array [], }, "level": "error", "path"...
4,502
0
petrpan-code/sanity-io/sanity/packages/sanity/test/validation
petrpan-code/sanity-io/sanity/packages/sanity/test/validation/__snapshots__/numbers.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`number greater than constraint: gt: too low 1`] = ` Array [ Object { "item": ValidationError { "children": undefined, "message": "Must be greater than 10", "operation": undefined, "paths": Array [], }, "level": "error", "path...
4,503
0
petrpan-code/sanity-io/sanity/packages/sanity/test/validation
petrpan-code/sanity-io/sanity/packages/sanity/test/validation/__snapshots__/strings.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`string custom async rule with string: not a palindrome 1`] = ` Array [ Object { "item": ValidationError { "children": undefined, "message": "Must be a palindrome!", "operation": undefined, "paths": Array [], }, "level": "error", ...
4,504
0
petrpan-code/sanity-io/sanity/packages/sanity/test/validation
petrpan-code/sanity-io/sanity/packages/sanity/test/validation/helpers/createSchema.ts
import {Schema as SchemaBuilder} from '@sanity/schema' import {validateSchema, groupProblems} from '@sanity/schema/_internal' import type {Schema} from '@sanity/types' export function createSchema(schemaDef: {name?: string; types: any[]}): Schema { const validated = validateSchema(schemaDef.types).getTypes() const...
4,505
0
petrpan-code/sanity-io/sanity/packages/sanity/test/validation
petrpan-code/sanity-io/sanity/packages/sanity/test/validation/mocks/mockSanityClient.ts
export function createMockSanityClient() { const _client = { fetch: jest.fn((query: string) => Promise.resolve(null)) as jest.Mock< Promise<any>, [query: string] >, withConfig: () => _client, } return _client }
4,506
0
petrpan-code/sanity-io/sanity/packages/sanity/test/validation
petrpan-code/sanity-io/sanity/packages/sanity/test/validation/util/normalizeValidationRules.test.ts
import type {NumberSchemaType, SchemaType, StringSchemaType} from '@sanity/types' import {Rule as RuleClass} from '../../../src/core/validation' import {normalizeValidationRules} from '../../../src/core/validation/util/normalizeValidationRules' describe('normalizeValidationRules', () => { // see `infer.test.ts` for ...
4,507
0
petrpan-code/sanity-io/sanity/packages/sanity/test/validation
petrpan-code/sanity-io/sanity/packages/sanity/test/validation/util/typeString.test.ts
import {typeString} from '../../../src/core/validation/util/typeString' describe('typeString', () => { it('returns the a type string of built in types', () => { expect(typeString({})).toBe('Object') expect( typeString(function () { // intentionally blank }), ).toBe('Function') exp...
4,508
0
petrpan-code/sanity-io/sanity/packages/sanity
petrpan-code/sanity-io/sanity/packages/sanity/typings/css.d.ts
declare module '*.module.css' { const styles: Record<string, string> export = styles export default styles }
4,509
0
petrpan-code/sanity-io/sanity/packages/sanity
petrpan-code/sanity-io/sanity/packages/sanity/typings/exif-component.d.ts
declare module 'exif-component' { const exifComponent: (buf: string | ArrayBuffer | null) => unknown export default exifComponent }
4,510
0
petrpan-code/sanity-io/sanity/packages/sanity
petrpan-code/sanity-io/sanity/packages/sanity/typings/export.d.ts
declare module '@sanity/export' { const sanityExport: (options: any) => Promise<void> export = sanityExport }
4,511
0
petrpan-code/sanity-io/sanity/packages/sanity
petrpan-code/sanity-io/sanity/packages/sanity/typings/global.d.ts
declare const __DEV__: boolean
4,512
0
petrpan-code/sanity-io/sanity/packages/sanity
petrpan-code/sanity-io/sanity/packages/sanity/typings/import.d.ts
declare module '@sanity/import' { interface ImportWarning { type: string url?: string documents?: { documentId: string path: string }[] } const sanityImport: ( stream: any, options: any, ) => Promise<{numDocs: number; warnings: ImportWarning[]}> export = sanityImport }
4,513
0
petrpan-code/sanity-io/sanity/packages/sanity
petrpan-code/sanity-io/sanity/packages/sanity/typings/jsdom-global.d.ts
declare module 'jsdom-global' { const jsdomGlobal: (defaultHtml: string, options: {url: string}) => () => void export default jsdomGlobal }
4,514
0
petrpan-code/sanity-io/sanity/packages/sanity
petrpan-code/sanity-io/sanity/packages/sanity/typings/sanity-ui.d.ts
import {Theme} from '@sanity/ui' declare module 'styled-components' { // eslint-disable-next-line interface DefaultTheme extends Theme {} }
4,515
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/.depcheckignore.json
{ "ignore": ["@sanity/uuid", "dotenv", "sanity", "typescript", "styled-components", "react"] }
4,516
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/.env.example
# Example .env file for setting environment variables needed by e2e and perf tests locally. # # Copy this file to .env (`cp .env.example .env`) and fill inn the values there (`.env` is ignored by git) # This is a write token that allows playwright to interact with the perf studio as an authenticated user # You can gen...
4,517
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/cli.ts
import {parseArgs} from 'node:util' import globby from 'globby' import {config} from 'dotenv' import {createClient} from '@sanity/client' import {run} from './runner/runner' import {findEnv, readEnv} from './config/envVars' import * as queries from './queries' import {getCurrentBranchSync, getGitInfoSync} from './runne...
4,518
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/codegen.ts
import {createSanitySessionCookie} from './runner/utils/createSanitySessionCookie' import {STUDIO_PROJECT_ID} from './config/constants' import {readEnv} from './config/envVars' const {chromium} = require('@playwright/test') async function run({projectId, token, url}: {projectId: string; token: string; url: string}) {...
4,519
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/jest.config.cjs
'use strict' const {createJestConfig} = require('../test/config.cjs') module.exports = createJestConfig({ // ignore performance tests testPathIgnorePatterns: ['tests'], displayName: require('./package.json').name, })
4,520
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/package.json
{ "name": "sanity-perf-tests", "version": "3.20.1", "private": true, "description": "Sanity Studio perf tests", "license": "MIT", "author": "Sanity.io <hello@sanity.io>", "scripts": { "build": "yarn build:cli && (cd studio && yarn build)", "perf:codegen": "ts-node --files -r dotenv/config codegen"...
4,521
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/perf-studio.d.ts
import * as perfHelpers from './tests/helpers' declare global { interface Window { perf: typeof perfHelpers } }
4,522
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/queries.ts
/** * Get all recent deployments for a given branch */ export const branchDeploymentsQuery = `*[_type=='branch' && name == $branch] { "branchId": _id, "baseBranchId": *[_type=='branch' && name == ^.base][0]._id } { "deployments": [ ...*[_type == 'deployment' && name=="performance-studio" && status=="succeed...
4,523
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/readme.md
# Perf tracking for studio ## Overview - **Perf Studio** - (`perf/studio`) this is the Sanity Studio that we run the test suite against (using playwright). This studio is set up to capture various cases that we want to measure performance of (e.g. a very large document) - **Performance Test Runner** (`perf/runner.ts`...
4,524
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/perf/tsconfig.json
{ "extends": "../tsconfig.settings.json", "include": ["./**/*"], "compilerOptions": { "esModuleInterop": true, "module": "CommonJS", "noEmit": true, "resolveJsonModule": true } }
4,525
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/config/constants.ts
export const STUDIO_PROJECT_ID = 'qk0wb6qx' export const STUDIO_DATASET = 'test'
4,526
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/config/envVars.ts
type KnownEnvVar = | 'PERF_TEST_HEADLESS' | 'PERF_TEST_BRANCH' | 'PERF_TEST_METRICS_TOKEN' | 'PERF_TEST_SANITY_TOKEN' | 'COMMIT_SHA' | 'BRANCH_DEPLOYMENT_URL' | 'SANITY_STUDIO_DATASET' export function readEnv(name: KnownEnvVar): string { const val = findEnv(name) if (val === undefined) { throw ne...
4,527
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/runner/runner.ts
/* eslint-disable no-console */ import {chromium, BrowserContext, Page} from '@playwright/test' import {concatMap, from, lastValueFrom, range} from 'rxjs' import {tap, toArray} from 'rxjs/operators' import {SanityClient} from '@sanity/client' import {capitalize} from 'lodash' import {Deployment, PerformanceTestProps} f...
4,528
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/runner/types.ts
import {Page} from '@playwright/test' import {SanityClient} from '@sanity/client' import {ValidTestId} from './utils/testIds' export interface Deployment { _id: string deploymentId: string url: string label: string } export interface PerformanceTestContext { page: Page url: string client: SanityClient } ...
4,529
0
petrpan-code/sanity-io/sanity/perf/runner
petrpan-code/sanity-io/sanity/perf/runner/__tests__/parseDecoratedRefs.test.ts
import {parseDecoratedRefs} from '../utils/gitUtils' test('parseDecoratedRefs', () => { expect(parseDecoratedRefs('')).toEqual({branches: [], tags: []}) expect(parseDecoratedRefs('HEAD -> ')).toEqual({branches: [], tags: []}) expect(parseDecoratedRefs('HEAD, origin/perf-testing')).toEqual({ branches: ['perf-...
4,530
0
petrpan-code/sanity-io/sanity/perf/runner
petrpan-code/sanity-io/sanity/perf/runner/utils/bundlePerfHelpers.ts
import * as esbuild from 'esbuild' export async function bundle(file: string) { const result = await esbuild.build({ entryPoints: [file], bundle: true, write: false, }) return result.outputFiles[0].text }
4,531
0
petrpan-code/sanity-io/sanity/perf/runner
petrpan-code/sanity-io/sanity/perf/runner/utils/createSanitySessionCookie.ts
export function createSanitySessionCookie(projectId: string, token: string) { return { name: 'sanitySession', value: token, sameSite: 'None' as const, secure: true, httpOnly: true, domain: `.${projectId}.api.sanity.io`, path: '/', } }
4,532
0
petrpan-code/sanity-io/sanity/perf/runner
petrpan-code/sanity-io/sanity/perf/runner/utils/getDeviceInfo.ts
import os from 'os' export function getDeviceInfo() { const [avg1m, avg5m, avg10m] = os.loadavg() return { type: os.type(), platform: os.platform(), version: os.version(), release: os.release(), hostname: os.hostname(), arch: os.arch(), memory: {total: os.totalmem(), free: os.freemem()}...
4,533
0
petrpan-code/sanity-io/sanity/perf/runner
petrpan-code/sanity-io/sanity/perf/runner/utils/gitUtils.ts
import execa from 'execa' import {partition, uniq} from 'lodash' const placeholders = { commit: '%H', abbreviatedCommit: '%h', tree: '%T', abbreviatedTree: '%t', parent: '%P', abbreviatedParent: '%p', refs: '%D', encoding: '%e', subject: '%s', sanitizedSubjectLine: '%f', body: '%b', commitNotes...
4,534
0
petrpan-code/sanity-io/sanity/perf/runner
petrpan-code/sanity-io/sanity/perf/runner/utils/sanityIdIfy.ts
import {deburr} from 'lodash' export function sanityIdify(input: string) { return deburr(input) .replace(/[^a-zA-Z0-9_-]+/g, '_') .replace(/^-/, '') }
4,535
0
petrpan-code/sanity-io/sanity/perf/runner
petrpan-code/sanity-io/sanity/perf/runner/utils/testIds.ts
type TestId<T extends string> = T & {__brand: 'test-id'} const VALID_ID = /^[a-z0-9_-]+$/ function isValidSanityId(id: string) { return VALID_ID.test(id) } function defineId<T extends string>(testId: T) { if (!isValidSanityId(testId)) { throw new Error( `"${testId}" is not a valid test ID. A test ID mu...
4,536
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/studio/README.md
## Performance Studio This is a purpose-made Sanity Studio used to capture various performance cases. - Prefer creating new separate schema types instead of modifying existing ones. This way we ensure that when we run a performance test against an older deployment, the schema is exactly the same.
4,537
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/studio/package.json
{ "name": "perf-studio", "version": "3.20.1", "private": true, "description": "Sanity Studio with various test cases for tracking performance", "license": "MIT", "author": "Sanity.io <hello@sanity.io>", "scripts": { "build": "sanity build", "clean": "rimraf .sanity dist", "dev": "sanity dev --...
4,538
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/studio/sanity.cli.ts
import {defineCliConfig} from 'sanity/cli' import {STUDIO_DATASET, STUDIO_PROJECT_ID} from '../config/constants' export default defineCliConfig({ api: { projectId: STUDIO_PROJECT_ID, dataset: STUDIO_DATASET, }, })
4,539
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/studio/sanity.config.ts
/// <reference types="vite/client" /> import {defineConfig, defineDocumentFieldAction, PluginOptions} from 'sanity' import {deskTool} from 'sanity/desk' import {useCallback} from 'react' import {STUDIO_DATASET, STUDIO_PROJECT_ID} from '../config/constants' import {simple} from './schema/simple' import {deepObject} from...
4,540
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/studio/tsconfig.json
{ "extends": "../../tsconfig.settings.json", "compilerOptions": { "jsx": "react-jsx", "esModuleInterop": true } }
4,541
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/studio/turbo.json
{ "$schema": "https://turbo.build/schema.json", "extends": ["//"], "pipeline": { "build": { "outputs": [".sanity/**", "dist/**"] } } }
4,542
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/studio/vercel.json
{ "version": 2, "routes": [ { "handle": "filesystem" }, { "src": "/workshop/frame/(.*)", "dest": "/workshop/frame/index.html" }, { "src": "/(.*)", "dest": "/index.html" } ] }
4,543
0
petrpan-code/sanity-io/sanity/perf/studio
petrpan-code/sanity-io/sanity/perf/studio/schema/deepArray.ts
/** * Note: Perf test schemas are immutable - instead of modifying a schema, create a new one and suffix the name with a version number. */ export const deepArray = { type: 'document', name: 'deepArray', fields: [ { name: 'text', type: 'string', }, { name: 'deep', type: 'arra...
4,544
0
petrpan-code/sanity-io/sanity/perf/studio
petrpan-code/sanity-io/sanity/perf/studio/schema/deepArrayReferences.ts
/** * Note: Perf test schemas are immutable - instead of modifying a schema, create a new one and suffix the name with a version number. */ export const deepArrayReferences = { type: 'document', name: 'deepArrayReference', fields: [ { name: 'text', type: 'string', }, { name: 'deep'...
4,545
0
petrpan-code/sanity-io/sanity/perf/studio
petrpan-code/sanity-io/sanity/perf/studio/schema/deepArrayString.ts
/** * Note: Perf test schemas are immutable - instead of modifying a schema, create a new one and suffix the name with a version number. */ export const deepArrayString = { type: 'document', name: 'deepArrayString', fields: [ { name: 'text', type: 'string', }, { name: 'deep', ...
4,546
0
petrpan-code/sanity-io/sanity/perf/studio
petrpan-code/sanity-io/sanity/perf/studio/schema/deepObject.ts
/** * Note: Perf test schemas are immutable - instead of modifying a schema, create a new one and suffix the name with a version number. * */ export const deepObject = { type: 'document', name: 'deepObject', fields: [ { name: 'title', type: 'string', }, { name: 'deep', type:...
4,547
0
petrpan-code/sanity-io/sanity/perf/studio
petrpan-code/sanity-io/sanity/perf/studio/schema/largeDocument.ts
import {defineField} from 'sanity' /** * Note: Perf test schemas are immutable - instead of modifying a schema, create a new one and suffix the name with a version number. * */ export const largeDocument = { type: 'document', name: 'largeDocument', fields: [ defineField({ name: 'contentBlocks', ...
4,548
0
petrpan-code/sanity-io/sanity/perf/studio
petrpan-code/sanity-io/sanity/perf/studio/schema/simple.ts
/** * Note: Perf test schemas are immutable - instead of modifying a schema, create a new one and suffix the name with a version number. * */ export const simple = { type: 'document', name: 'simple', fields: [ { name: 'simple', type: 'string', }, ], }
4,549
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/tests/arrayOf1kItems.test.ts
import {range} from 'lodash' import {PerformanceTestProps} from '../runner/types' import {KNOWN_TEST_IDS} from '../runner/utils/testIds' export default { id: KNOWN_TEST_IDS['array-of-1k-items'], name: 'Performance test of array with 1k items', description: ` This test measures the general performance of an arr...
4,550
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/tests/arrayOf1kReferenceItems.test.ts
import {range} from 'lodash' import {PerformanceTestProps} from '../runner/types' import {KNOWN_TEST_IDS} from '../runner/utils/testIds' export default { id: KNOWN_TEST_IDS['array-of-1k-reference-items'], name: 'Performance test of array with 1k reference items', description: ` This test measures the general p...
4,551
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/tests/arrayOf1kStringItems.test.ts
import {range} from 'lodash' import {PerformanceTestProps} from '../runner/types' import {KNOWN_TEST_IDS} from '../runner/utils/testIds' export default { id: KNOWN_TEST_IDS['array-of-1k-string-items'], name: 'Performance test of array with 1k string items', description: ` This test measures the general perform...
4,552
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/tests/deeplyNestedObjects.test.ts
import {uuid} from '@sanity/uuid' import {Page} from '@playwright/test' import {PerformanceTestContext, PerformanceTestProps} from '../runner/types' import {KNOWN_TEST_IDS} from '../runner/utils/testIds' export default { id: KNOWN_TEST_IDS['deeply-nested-objects-test'], name: 'Typing speed test in a deeply nested ...
4,553
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/tests/largeArrayEditingAnotherField.test.ts
import {range} from 'lodash' import {PerformanceTestProps} from '../runner/types' import {KNOWN_TEST_IDS} from '../runner/utils/testIds' export default { id: KNOWN_TEST_IDS['large-array-editing-another-field'], name: 'Performance test of array with 200 items and editing another field', description: ` This test...
4,554
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/tests/largeDocumentEditing.test.ts
import {PerformanceTestProps} from '../runner/types' import {KNOWN_TEST_IDS} from '../runner/utils/testIds' import {generateParagraphs} from './helpers/utils/generateParagraphs' export default { id: KNOWN_TEST_IDS['large-document-editing'], name: 'Performance test of large document editing', description: ` Thi...
4,555
0
petrpan-code/sanity-io/sanity/perf
petrpan-code/sanity-io/sanity/perf/tests/simpleTyping.test.ts
import {uuid} from '@sanity/uuid' import {PerformanceTestContext, PerformanceTestProps} from '../runner/types' import {KNOWN_TEST_IDS} from '../runner/utils/testIds' export default { id: KNOWN_TEST_IDS['simple-typing-speed-test'], name: 'Simple typing speed test', description: ` This test measures the typing s...
4,556
0
petrpan-code/sanity-io/sanity/perf/tests
petrpan-code/sanity-io/sanity/perf/tests/helpers/index.ts
// The methods exported here will be made available on window.perf export {typingTest} from './typingTest'
4,557
0
petrpan-code/sanity-io/sanity/perf/tests
petrpan-code/sanity-io/sanity/perf/tests/helpers/register.ts
import * as perfHelpers from './index' window.perf = perfHelpers
4,558
0
petrpan-code/sanity-io/sanity/perf/tests
petrpan-code/sanity-io/sanity/perf/tests/helpers/typingTest.ts
import {triggerEditEvent} from './utils/triggerEdit' const LAG_CHECK_MS = 16 // ~60fps interface Sample { lagPerKeystroke: number timePerKeyStroke: number } export async function typingTest( inputElement: HTMLElement, options: {samples?: number; gracePeriod?: number; chars?: string} = {}, ): Promise<Sample[]> ...
4,559
0
petrpan-code/sanity-io/sanity/perf/tests/helpers
petrpan-code/sanity-io/sanity/perf/tests/helpers/utils/generateParagraphs.ts
export function generateParagraph(length = 1000): string { const words = [ 'Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'sed', 'do', 'eiusmod', 'tempor', 'incididunt', 'ut', 'labore', 'et', 'dolore', 'magna', ...
4,560
0
petrpan-code/sanity-io/sanity/perf/tests/helpers
petrpan-code/sanity-io/sanity/perf/tests/helpers/utils/triggerEdit.ts
function triggerInsertTextEvent(element: HTMLElement, nextValue: string) { if (!element.contentEditable) { throw new Error('Cannot trigger insert text event on non-contenteditable element') } element.dispatchEvent( new InputEvent('beforeinput', { bubbles: true, cancelable: true, inputTyp...
4,561
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/.eslintrc
{ "rules": { "@typescript-eslint/no-var-requires": "off", "import/no-dynamic-require": "off", "no-console": "off", "no-sync": "off", "no-process-exit": "off" } }
4,562
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/depcheck.ts
#!/usr/bin/env node /* eslint-disable import/no-dynamic-require, no-process-env */ import path from 'path' import fs from 'fs' import chalk from 'chalk' import depcheck, {Node} from 'depcheck' const cwd = path.resolve(process.cwd(), process.argv[2] || '.') const manifest = JSON.parse(fs.readFileSync(`${cwd}/package.j...
4,563
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/etl.ts
import path from 'path' import cac from 'cac' import ora from 'ora' import {createClient} from '@sanity/client' import {SanityTSDocConfigOptions, _loadConfig, extract, load, transform} from '@sanity/tsdoc' import chalk from 'chalk' const cli = cac('yarn etl') cli .command('[packageName]', 'Extract, transform, and l...
4,564
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/normalizeDependencyVersions.ts
/* eslint-disable no-sync, no-console, id-length */ import fs from 'node:fs' import path from 'node:path' import semver from 'semver' import chalk from 'chalk' import glob from 'glob' interface LernaConfig { packages: string[] } interface PackageJson { name: string } const corePkg: PackageJson = JSON.parse( fs...
4,565
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/normalizePackageFields.ts
import uniq from 'lodash/uniq' import {PackageManifest} from './types' import transformPkgs from './utils/transformPkgs' const COMMON_KEYWORDS = ['sanity', 'cms', 'headless', 'realtime', 'content'] const supportedNodeVersionRange = '>=14.18.0' transformPkgs((pkgManifest: PackageManifest, {relativeDir}) => { const ...
4,566
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/printReleaseNotesTemplate.ts
import execa from 'execa' import yargs from 'yargs' import {hideBin} from 'yargs/helpers' const flags = yargs(hideBin(process.argv)).argv as Record<string, any> const revParsed = execa.commandSync('git rev-parse --abbrev-ref HEAD', {shell: true}).stdout.trim() const isFromV3 = revParsed === 'v3' || revParsed === 'v3-...
4,567
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/symlinkDependencies.js
#!/usr/bin/env node /* eslint-disable no-sync, no-console, strict */ /** * ************************************************************** * This script needs to stay as a CommonJS/JavaScript file * (it's executed in node by the `CLI unit tests`, and possibly other places) * *****************************************...
4,568
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/tsconfig.json
{ "include": ["./**/*.ts", "./**/*.tsx", "./**/*.js", "./**/*.jsx", "./**/*.json"], "extends": "../tsconfig.settings.json", "compilerOptions": { "resolveJsonModule": true } }
4,569
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/types.ts
export interface PackageManifest { name: string private?: boolean version: string exports?: Record<string, Record<string, string>> dependencies?: Record<string, string> devDependencies?: Record<string, string> engines?: Record<string, string> keywords?: string[] } export interface Package { path: str...
4,570
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/scripts/updateLicenses.ts
/** * Copies the ./LICENSE-file to each package folder (warning - will overwrite every license file in all monorepo packages packages) */ import {promises as fs} from 'fs' import path from 'path' import readPackages from './utils/readPackages' const readLicense = fs.readFile(path.join(process.cwd(), 'LICENSE'), 'ut...
4,571
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/doc-report/docClient.ts
import {type SanityClient, createClient} from '@sanity/client' import {sanityIdify} from '../utils/sanityIdify' import {readEnv} from '../utils/envVars' export type KnownEnvVar = 'DOCS_REPORT_DATASET' | 'DOCS_REPORT_TOKEN' export function createDocClient(dataset: string): SanityClient { return createClient({ pr...
4,572
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/doc-report/docReport.ts
import fs from 'fs/promises' import path from 'path' import {groupBy} from 'lodash' import {combineLatest, map} from 'rxjs' import prettier from 'prettier' import {startTimer} from '../utils/startTimer' import {readEnv} from '../utils/envVars' import {KnownEnvVar, createDocClient} from './docClient' const QUERY = `*[_...
4,573
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/doc-report/docReportCleanup.ts
import {sanityIdify} from '../utils/sanityIdify' import {startTimer} from '../utils/startTimer' import {readEnv} from '../utils/envVars' import {KnownEnvVar, createDocClient} from './docClient' const DATASET = readEnv<KnownEnvVar>('DOCS_REPORT_DATASET') const studioMetricsClient = createDocClient(DATASET) const timer...
4,574
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/doc-report/docReportCreate.ts
import path from 'path' import fs from 'fs' import ts, {type JSDoc, type JSDocComment, SyntaxKind} from 'typescript' import { at, createIfNotExists, type Mutation, patch, SanityEncoder, set, setIfMissing, upsert, } from '@bjoerge/mutiny' import {filter, map, mergeMap, of, tap} from 'rxjs' import readPac...
4,575
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/e2e/cleanup.ts
import {sanityIdify} from '../utils/sanityIdify' import {startTimer} from '../utils/startTimer' import {readEnv} from '../utils/envVars' import {KnownEnvVar, createE2EClient} from './e2eClient' const DATASET = readEnv<KnownEnvVar>('SANITY_E2E_DATASET') const studioE2EClient = createE2EClient(DATASET) const timer = st...
4,576
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/e2e/e2eClient.ts
import {type SanityClient, createClient} from '@sanity/client' import {sanityIdify} from '../utils/sanityIdify' import {readEnv} from '../utils/envVars' export type KnownEnvVar = | 'SANITY_E2E_DATASET' | 'SANITY_E2E_PROJECT_ID' | 'SANITY_E2E_SESSION_TOKEN' export function createE2EClient(dataset: string): Sanit...
4,577
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/e2e/setup.ts
import {readEnv} from '../utils/envVars' import {sanityIdify} from '../utils/sanityIdify' import {startTimer} from '../utils/startTimer' import {KnownEnvVar, createE2EClient} from './e2eClient' const dataset = sanityIdify(readEnv<KnownEnvVar>('SANITY_E2E_DATASET')) const studioE2EClient = createE2EClient(readEnv<Know...
4,578
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/publish/tarball.ts
import {spawn} from 'child_process' import fs from 'fs/promises' import path from 'path' import chalk from 'chalk' import globby from 'globby' main().catch((err) => { console.error(chalk.red(err)) process.exit(1) }) /** * This script will "publish" all the npm modules in the monorepo to tarballs (.tgz) in * `<m...
4,579
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/utils/envVars.ts
export function readEnv<KnownEnvVar extends keyof NodeJS.ProcessEnv>(name: KnownEnvVar): string { const val = findEnv<KnownEnvVar>(name) if (val === undefined) { throw new Error(`Missing required environment variable "${name}"`) } return val } export function findEnv<KnownEnvVar extends keyof NodeJS.Proces...
4,580
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/utils/getPackagePaths.ts
/* eslint-disable no-sync */ import fs from 'node:fs' import path from 'node:path' import glob from 'glob' interface LernaConfig { packages: string[] } const config: LernaConfig = JSON.parse( fs.readFileSync(path.join(__dirname, '..', '..', 'lerna.json'), 'utf8'), ) if (!('packages' in config) || !Array.isArray(...
4,581
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/utils/loadEnvFiles.ts
/* eslint-disable no-process-env, no-sync */ import fs from 'fs' import path from 'path' import dotenv from 'dotenv' /** * Load environment variables from .env files, mirroring the behavior of Vite. * * @returns Array of environment file paths loaded. */ export function loadEnvFiles() { const mode = process.env....
4,582
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/utils/readPackages.ts
/* eslint-disable no-sync */ import fs from 'fs' import path from 'path' import {Package} from '../types' import {getManifestPaths} from './getPackagePaths' const rootPath = path.join(__dirname, '..', '..') export default function readPackages(): Package[] { return getManifestPaths().map((file) => { const fileP...
4,583
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/utils/sanityIdify.ts
import {deburr} from 'lodash' export function sanityIdify(input: string): string { return deburr(input) .replace(/[^a-zA-Z0-9_-]+/g, '_') .replace(/^-/, '') }
4,584
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/utils/startTimer.ts
import ora from 'ora' export function startTimer(label: string): {end: () => void} { const spinner = ora(label).start() const start = Date.now() return { end: () => spinner.succeed(`${label} (${formatMs(Date.now() - start)})`), } } function formatMs(ms: number) { return ms < 1000 ? `${ms}ms` : `${(ms / ...
4,585
0
petrpan-code/sanity-io/sanity/scripts
petrpan-code/sanity-io/sanity/scripts/utils/transformPkgs.ts
/* eslint-disable no-sync */ import fs from 'fs' import {PackageManifest} from '../types' import readPackages from './readPackages' /** * @internal */ export default function transformPkgs( mapFn: (pkg: PackageManifest, options: {relativeDir: string}) => PackageManifest, ): void { readPackages().forEach((pkg) =>...
4,586
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/test/config.cjs
'use strict' /* eslint-disable tsdoc/syntax */ const path = require('path') const {escapeRegExp, omit} = require('lodash') const devAliases = require('../dev/aliases.cjs') /** Regex for matching file extensions. */ const RE_EXT = /\.[0-9a-z]+$/i /** Path to the root of the Sanity monorepo. */ const ROOT_PATH = path...
4,587
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/test/jsdom.jest.env.ts
import JSDOMEnvironment from 'jest-environment-jsdom' export default class JSDOMEnvironmentWithDomRange extends JSDOMEnvironment { public async setup(): Promise<void> { await super.setup() if (typeof this.global.TextEncoder === 'undefined') { const {TextEncoder, TextDecoder} = require('util') thi...
4,588
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/test/resolver.cjs
'use strict' module.exports = (path, options) => { // Call the defaultResolver, so we leverage its cache, error handling, etc. return options.defaultResolver(path, { ...options, // Use packageFilter to process parsed `package.json` before the resolution (see https://www.npmjs.com/package/resolve#resolveid-...
4,589
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/test/sanity-env.d.ts
/// <reference types="@sanity/types/parts" />
4,590
0
petrpan-code/sanity-io/sanity
petrpan-code/sanity-io/sanity/test/setup.ts
import path from 'path' import dotenv from 'dotenv' dotenv.config({path: path.resolve(__dirname, '../.env')}) if (typeof window !== 'undefined') { // https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom Object.defineProperty(window, 'matchMedia', { writable: true, value: ...
4,591
0
petrpan-code/sanity-io/sanity/test
petrpan-code/sanity-io/sanity/test/e2e/README.md
# E2E Testing in the Studio ## Required Env Variables The tests expects to find the below env variables. Either define it in your shell, or add it to the `.env.local` file in the repository root. - `SANITY_E2E_SESSION_TOKEN`: Before you get started with writing and running tests, you need to get hold of a token - ei...
4,592
0
petrpan-code/sanity-io/sanity/test
petrpan-code/sanity-io/sanity/test/e2e/env.ts
/* eslint-disable no-process-env */ /* eslint-disable no-process-exit */ import {loadEnvFiles} from '../../scripts/utils/loadEnvFiles' loadEnvFiles() const SANITY_E2E_SESSION_TOKEN = process.env.SANITY_E2E_SESSION_TOKEN! const SANITY_E2E_PROJECT_ID = process.env.SANITY_E2E_PROJECT_ID! const SANITY_E2E_DATASET = proc...
4,593
0
petrpan-code/sanity-io/sanity/test
petrpan-code/sanity-io/sanity/test/e2e/globalSetup.ts
import {chromium, type FullConfig} from '@playwright/test' const INIT_TIMEOUT_MS = 120000 const FALLBACK_URL = 'http://localhost:3339/' /** * Global setup for all end-to-end tests. * Because the development server can be ready to receive requests but has not * precompiled javascript, we want to wait here until the...
4,594
0
petrpan-code/sanity-io/sanity/test/e2e
petrpan-code/sanity-io/sanity/test/e2e/helpers/constants.ts
export const STALE_TEST_THRESHOLD_MS = 10000
4,595
0
petrpan-code/sanity-io/sanity/test/e2e
petrpan-code/sanity-io/sanity/test/e2e/helpers/createUniqueDocument.ts
import {SanityClient, SanityDocument, SanityDocumentStub} from '@sanity/client' import {uuid} from '@sanity/uuid' export async function createUniqueDocument( client: SanityClient, {_type, _id, ...restProps}: SanityDocumentStub, ): Promise<Partial<SanityDocument>> { const doc = { _type, _id: _id || uuid()...
4,596
0
petrpan-code/sanity-io/sanity/test/e2e
petrpan-code/sanity-io/sanity/test/e2e/helpers/index.ts
export * from './sanityClient' export * from './createUniqueDocument' export * from './constants'
4,597
0
petrpan-code/sanity-io/sanity/test/e2e
petrpan-code/sanity-io/sanity/test/e2e/helpers/sanityClient.ts
import {createClient} from '@sanity/client' import {uuid} from '@sanity/uuid' import {SANITY_E2E_SESSION_TOKEN, SANITY_E2E_DATASET, SANITY_E2E_PROJECT_ID} from '../env' import {SanityClient} from 'sanity' export class TestContext { client: SanityClient constructor(client: SanityClient) { this.client = client ...
4,598
0
petrpan-code/sanity-io/sanity/test/e2e/tests
petrpan-code/sanity-io/sanity/test/e2e/tests/default-layout/navbar.spec.ts
import {test, expect} from '@playwright/test' test.describe('@sanity/default-layout: Navbar', () => { test('render ActionModal on top of pane headers in desk tool', async ({page}) => { page.goto('/test/content') await expect(page.locator('data-testid=navbar')).toBeVisible() }) })
4,599