{"_id":"@sanity/test","_rev":"102-f95e589a5003640c8ec3d291331b13e7","name":"@sanity/test","dist-tags":{"latest":"0.0.1-alpha.1"},"versions":{"0.0.1-alpha.1":{"name":"@sanity/test","version":"0.0.1-alpha.1","keywords":["playwright","sanity","testing"],"author":{"name":"Sanity.io","email":"hello@sanity.io"},"license":"MIT","_id":"@sanity/test@0.0.1-alpha.1","maintainers":[{"name":"sergeisarviro","email":"sergei@sanity.io"},{"name":"ash","email":"ashley@juice49.com"},{"name":"indrek.karner","email":"indrek.karner@sanity.io"},{"name":"cngonzalez-sanity","email":"carolina@sanity.io"},{"name":"rdunk","email":"rupert@rupertdunk.com"},{"name":"rneatherway-sanity","email":"robin.neatherway@sanity.io"},{"name":"ricokahler","email":"ricokahler@me.com"},{"name":"pedro-sanity","email":"pedro@sanity.io"},{"name":"jonabc","email":"jon.ruskin@gmail.com"},{"name":"kenjonespizza","email":"ken@sanity.io"},{"name":"pauloborgesf","email":"paulo@sanity.io"},{"name":"binoy14","email":"me@binoy.io"},{"name":"simen.svale","email":"simen@sanity.io"},{"name":"svirs","email":"shur@sanity.io"},{"name":"josh_sanity_io","email":"josh@sanity.io"},{"name":"joneidejohnsen","email":"jon@sanity.io"},{"name":"nina.andal","email":"nina@sanity.io"},{"name":"rankers","email":"richardankers@gmail.com"},{"name":"snorreeb","email":"snorre.e.brekke@gmail.com"},{"name":"mattcraig","email":"matt@sanity.io"},{"name":"vincentquigley","email":"vincent@sanity.io"},{"name":"stipsan","email":"stipsan@gmail.com"},{"name":"michael-sanity","email":"michael@sanity.io"},{"name":"rubioz","email":"jarubc@gmail.com"},{"name":"tonina","email":"zhelyazkova.tonina@gmail.com"},{"name":"ritasdias","email":"anarita151@gmail.com"},{"name":"simeonsanity","email":"simeon@sanity.io"},{"name":"kmelve","email":"knut.melvaer@gmail.com"},{"name":"bjoerge","email":"bjoerge@gmail.com"},{"name":"rexxars","email":"espen@hovlandsdal.com"},{"name":"skogsmaskin","email":"per.kristian.nordnes@gmail.com"},{"name":"robinpyon","email":"robin@robinpyon.com"},{"name":"mariuslundgard","email":"studio@mariuslundgard.com"},{"name":"sanity-io","email":"developers@sanity.io"},{"name":"evenw","email":"even@sanity.io"},{"name":"radhe_sanity","email":"radhe@sanity.io"},{"name":"rbotten","email":"rbotten@gmail.com"},{"name":"judofyr","email":"judofyr@gmail.com"},{"name":"obliadp","email":"orjan@sanity.io"},{"name":"dcilke","email":"dain.cilke@gmail.com"},{"name":"fredcarlsen","email":"fred@superbig.co"},{"name":"hermanw","email":"herman@sanity.io"},{"name":"sgulseth","email":"sgulseth@gmail.com"},{"name":"atombender","email":"npm@purefiction.net"}],"homepage":"https://www.sanity.io/","bugs":{"url":"https://github.com/sanity-io/test/issues"},"bin":{"sanity-test":"bin/sanity-test"},"dist":{"shasum":"35b0847b7b10a547f281ffe4615f53a8296e0bee","tarball":"https://registry.npmjs.org/@sanity/test/-/test-0.0.1-alpha.1.tgz","fileCount":29,"integrity":"sha512-o2X2Veh9YWyVK/Iou/cToSS6ufcTLREoCVMcvBQbSqCFUIGaN1Ko3zxChJMWdf39dyaJ/ixMKtc8pciF/tL6Sw==","signatures":[{"sig":"MEYCIQC8hbA0KUB+creWt21r+XmISzVw95W8KCFW1/DCBidlqgIhAPunaEJ/O09ZQcpZlNc81vjBHBwpzKCb0SYjVQ3nID+A","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":72984},"main":"./lib/src/index.js","_from":"file:sanity-test-0.0.1-alpha.1.tgz","types":"./lib/src/index.d.ts","module":"./lib/index.esm.js","source":"./src/index.ts","exports":{".":{"node":{"import":"./lib/index.cjs.mjs","module":"./lib/index.esm.js"},"types":"./lib/src/index.d.ts","import":"./lib/index.esm.js","source":"./src/index.ts","default":"./lib/index.esm.js","require":"./lib/src/index.js"},"./package.json":"./package.json"},"scripts":{"lint":"eslint --ext .ts,.tsx src","build":"pkg-utils build --tsconfig tsconfig.lib.json","clean":"rimraf lib","watch":"pkg-utils watch --tsconfig tsconfig.lib.json","prebuild":"run-s clean","build:cli":"pkg-utils build --tsconfig tsconfig.lib.json","check:package":"pkg-utils --strict --tsconfig tsconfig.lib.json"},"_npmUser":{"name":"sanity-io","email":"developers@sanity.io"},"_resolved":"/tmp/0d6c16158f499f93ffdb15b6cf875339/sanity-test-0.0.1-alpha.1.tgz","_integrity":"sha512-o2X2Veh9YWyVK/Iou/cToSS6ufcTLREoCVMcvBQbSqCFUIGaN1Ko3zxChJMWdf39dyaJ/ixMKtc8pciF/tL6Sw==","commitlint":{"extends":["@commitlint/config-conventional"]},"repository":{"url":"git+https://github.com/sanity-io/test.git","type":"git"},"_npmVersion":"10.2.3","description":"Sanity Testing Package","directories":{},"lint-staged":{"*":["prettier --write --cache --ignore-unknown"]},"_nodeVersion":"20.10.0","browserslist":["last 2 versions and fully supports es6-module","maintained node versions"],"dependencies":{"cac":"^6.7.12","@sanity/uuid":"^3.0.1","@sanity/client":"^6.8.6","@playwright/test":"^1.39.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"husky":"^8.0.0","eslint":"^8.0.1","rimraf":"^5.0.5","prettier":"^3.1.1","typescript":"^5.3.3","@types/node":"^20.10.4","lint-staged":"^15.2.0","npm-run-all":"^4.1.5","@commitlint/cli":"^18.4.3","eslint-plugin-n":"^15.0.0 || ^16.0.0 ","@sanity/pkg-utils":"^3.3.5","eslint-plugin-import":"^2.29.0","eslint-plugin-promise":"^6.0.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.0.1","@typescript-eslint/parser":"^6.13.2","@commitlint/config-conventional":"^18.4.3","@typescript-eslint/eslint-plugin":"^6.4.0","eslint-config-standard-with-typescript":"^42.0.0"},"_npmOperationalInternal":{"tmp":"tmp/test_0.0.1-alpha.1_1702410589750_0.6037561562429243","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-12-12T19:49:49.674Z","modified":"2026-04-08T15:18:31.599Z","0.0.1-alpha.1":"2023-12-12T19:49:50.014Z"},"bugs":{"url":"https://github.com/sanity-io/test/issues"},"author":{"name":"Sanity.io","email":"hello@sanity.io"},"license":"MIT","homepage":"https://www.sanity.io/","keywords":["playwright","sanity","testing"],"repository":{"url":"git+https://github.com/sanity-io/test.git","type":"git"},"description":"Sanity Testing Package","maintainers":[{"email":"svc.npm@sanity.io","name":"sanity-svc.npm"},{"email":"developers@sanity.io","name":"sanity-io"}],"readme":"# `@sanity/test`\n\n## Required Env Variables\n\nThe 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.\n\n- `SANITY_E2E_SESSION_TOKEN`: Before you get started with writing and running tests, you need to get hold of a token - either using your own Sanity user token (`sanity debug --secrets` will give you the CLI token provided you are logged in `sanity login`), or by creating a project API token using https://sanity.io/manage.\n- `SANITY_E2E_PROJECT_ID`: Project ID of the studio\n- `SANITY_E2E_DATASET`: Dataset name of the studio\n\n## Setup\n\n#### 1. Initialize Playwright\n\nRun Playwright Init Command: Start by initializing Playwright in your project. This sets up the necessary configuration and dependencies. Run the following command in your project directory:\n\n```bash\nnpx playwright init\n```\n\nThis command will create a default configuration file and install Playwright as a dependency in your project.\n\n#### 2. Configure Playwright\n\nPaste the provided code into your `playwright.config.ts` file:\n\n```ts\nimport {defineConfig} from '@playwright/test'\nimport {createPlaywrightConfig} from '@sanity/test'\n\nconst CI = process.env.CI // Assuming CI is set in your environment\n\nconst playwrightConfig = createPlaywrightConfig({\n  projectId: process.env.SANITY_E2E_PROJECT_ID!,\n  token: process.env.SANITY_E2E_SESSION_TOKEN!,\n  playwrightOptions(config) {\n    return {\n      ...config,\n      webServer: {\n        ...config.webServer,\n        command: CI ? 'yarn e2e:start' : 'yarn e2e:dev',\n      },\n    }\n  },\n})\n\nexport default defineConfig(playwrightConfig)\n```\n\n#### 3. Implement Global Setup\n\nAdd a Global Setup File: The global setup file is used for setting up global preconditions for your tests. The `@sanity/test` package adds default function that authenticates the user to the studio.\n\n```ts\nimport {globalSetup} from '@sanity/test'\n\nexport default globalSetup\n```\n\n_Note: the default file for global setup is at `'./test/e2e/globalSetup'` path. This can be changed in the `playwright.config.ts`_\n\n#### 5. Write and Run Tests\n\nStart Writing Tests: There are multiple ways to write Playwright tests:\n\nUsing Playwright Codegen: Run `sanity-test codegen` to open an interactive browser session and generate test scripts based on your interactions with the browser. Note: the env variables are required for codegen to work\n\nUsing the VSCode Extension: If you prefer, you can use the Playwright extension for Visual Studio Code to write and manage your tests.\n\nManually Writing Tests: Write test scripts manually in your test files, using the Playwright API.\n\nRun the Tests: Once your tests are written, you can run them using the Playwright CLI. A common command to run tests is:\n\n```bash\nnpx playwright test\n```\n\n## Custom Fixtures\n\n````ts\ninterface SanityFixtures {\n  /**\n   * This provides a Sanity client that can be used to interact with Sanity.\n   *\n   * @example\n   * ```ts\n   * function getRemoteValue() {\n   *  return sanityClient\n   *    .getDocument(`drafts.${documentId}`)\n   *    .then((doc) => (doc ? doc.simple : null))\n   * }\n   *```\n   */\n  sanityClient: SanityClient\n  /**\n   * This fixture is used to create a new document in the dataset.\n   * It will create a new document with a unique name and return the document.\n   * It also navigates to the document given the path\n   *\n   * @example\n   * ```ts\n   * const documentId = await createDraftDocument('/test/content/input-ci;textsTest')\n   * ```\n   */\n  createDraftDocument: (navigationPath: string) => Promise<string>\n}\n````\n","readmeFilename":"README.md"}