Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@sanity/test
Advanced tools
Readme
@sanity/test
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 - 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.SANITY_E2E_PROJECT_ID
: Project ID of the studioSANITY_E2E_DATASET
: Dataset name of the studioRun 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:
npx playwright init
This command will create a default configuration file and install Playwright as a dependency in your project.
Paste the provided code into your playwright.config.ts
file:
import {defineConfig} from '@playwright/test'
import {createPlaywrightConfig} from '@sanity/test'
const CI = process.env.CI // Assuming CI is set in your environment
const playwrightConfig = createPlaywrightConfig({
projectId: process.env.SANITY_E2E_PROJECT_ID!,
token: process.env.SANITY_E2E_SESSION_TOKEN!,
playwrightOptions(config) {
return {
...config,
webServer: {
...config.webServer,
command: CI ? 'yarn e2e:start' : 'yarn e2e:dev',
},
}
},
})
export default defineConfig(playwrightConfig)
Add 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.
import {globalSetup} from '@sanity/test'
export default globalSetup
Note: the default file for global setup is at './test/e2e/globalSetup'
path. This can be changed in the playwright.config.ts
Start Writing Tests: There are multiple ways to write Playwright tests:
Using 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
Using the VSCode Extension: If you prefer, you can use the Playwright extension for Visual Studio Code to write and manage your tests.
Manually Writing Tests: Write test scripts manually in your test files, using the Playwright API.
Run the Tests: Once your tests are written, you can run them using the Playwright CLI. A common command to run tests is:
npx playwright test
interface SanityFixtures {
/**
* This provides a Sanity client that can be used to interact with Sanity.
*
* @example
* ```ts
* function getRemoteValue() {
* return sanityClient
* .getDocument(`drafts.${documentId}`)
* .then((doc) => (doc ? doc.simple : null))
* }
*```
*/
sanityClient: SanityClient
/**
* This fixture is used to create a new document in the dataset.
* It will create a new document with a unique name and return the document.
* It also navigates to the document given the path
*
* @example
* ```ts
* const documentId = await createDraftDocument('/test/content/input-ci;textsTest')
* ```
*/
createDraftDocument: (navigationPath: string) => Promise<string>
}
FAQs
Sanity Testing Package
We found that @sanity/test demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 44 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).