diff --git a/.env.example b/.env.example index 8f03c8d450e..45ac2a721cb 100644 --- a/.env.example +++ b/.env.example @@ -14,3 +14,6 @@ SANITY_E2E_BASE_URL=http://localhost:3339 # Whether or not to run the end to end tests in headless mode. Defaults to true, but sometimes # you might want to see the browser in action, in which case you can set this to `false`. HEADLESS=true + +# Token for running CLI tests locally +SANITY_CI_CLI_AUTH_TOKEN_STAGING= diff --git a/packages/@sanity/cli/test/__fixtures__/v2/.env b/packages/@sanity/cli/test/__fixtures__/v2/.env deleted file mode 100644 index 125090cd3fe..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/.env +++ /dev/null @@ -1 +0,0 @@ -SANITY_STUDIO_FROM_DOTENV="this-should-never-be-used" diff --git a/packages/@sanity/cli/test/__fixtures__/v2/.env.development b/packages/@sanity/cli/test/__fixtures__/v2/.env.development deleted file mode 100644 index ac541681da7..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/.env.development +++ /dev/null @@ -1,3 +0,0 @@ -SANITY_STUDIO_MODE=development -SANITY_STUDIO_FROM_DOTENV="this-should-be-development" -SANITY_INTERNAL_ENV=staging diff --git a/packages/@sanity/cli/test/__fixtures__/v2/.env.production b/packages/@sanity/cli/test/__fixtures__/v2/.env.production deleted file mode 100644 index 777d2563a90..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/.env.production +++ /dev/null @@ -1,4 +0,0 @@ -SANITY_STUDIO_MODE=production -SANITY_STUDIO_FROM_DOTENV="this-should-be-production" -# This is for running tests against the staging API -SANITY_INTERNAL_ENV=staging diff --git a/packages/@sanity/cli/test/__fixtures__/v2/.gitignore b/packages/@sanity/cli/test/__fixtures__/v2/.gitignore deleted file mode 100644 index 67af58370bf..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -dist -package-lock.json diff --git a/packages/@sanity/cli/test/__fixtures__/v2/components/MyLogo.module.css b/packages/@sanity/cli/test/__fixtures__/v2/components/MyLogo.module.css deleted file mode 100644 index 38f846a75cf..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/components/MyLogo.module.css +++ /dev/null @@ -1,3 +0,0 @@ -.logo { - background: green; -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/components/MyLogo.tsx b/packages/@sanity/cli/test/__fixtures__/v2/components/MyLogo.tsx deleted file mode 100644 index 4cc798ca0c4..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/components/MyLogo.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import styles from './MyLogo.module.css' - -const fromDotEnv = process.env.SANITY_STUDIO_FROM_DOTENV || 'notset' - -// Test that we can import CSS modules and that they get bundled -export function MyLogo() { - return ( -
- Hello -
- ) -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/config/.checksums b/packages/@sanity/cli/test/__fixtures__/v2/config/.checksums deleted file mode 100644 index 090c90f1d93..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/config/.checksums +++ /dev/null @@ -1,7 +0,0 @@ -{ - "#": "Used by Sanity to keep track of configuration file checksums, do not delete or modify!", - "@sanity/default-layout": "bb034f391ba508a6ca8cd971967cbedeb131c4d19b17b28a0895f32db5d568ea", - "@sanity/default-login": "6fb6d3800aa71346e1b84d95bbcaa287879456f2922372bb0294e30b968cd37f", - "@sanity/form-builder": "b38478227ba5e22c91981da4b53436df22e48ff25238a55a973ed620be5068aa", - "@sanity/data-aspects": "d199e2c199b3e26cd28b68dc84d7fc01c9186bf5089580f2e2446994d36b3cb6" -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/data-aspects.json b/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/data-aspects.json deleted file mode 100644 index d64838e727e..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/data-aspects.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "listOptions": {} -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/default-layout.json b/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/default-layout.json deleted file mode 100644 index 4d8b87f4d52..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/default-layout.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "toolSwitcher": { - "order": [], - "hidden": [] - } -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/default-login.json b/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/default-login.json deleted file mode 100644 index 2680ad8bae8..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/default-login.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "providers": { - "mode": "append", - "redirectOnSingle": false, - "entries": [] - } -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/form-builder.json b/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/form-builder.json deleted file mode 100644 index b97a6a6d9d7..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/config/@sanity/form-builder.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "images": { - "directUploads": true - } -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/document.json b/packages/@sanity/cli/test/__fixtures__/v2/document.json deleted file mode 100644 index 11cab74221f..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/document.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "_id": "drafts.magnus-carlsen", - "_type": "person", - "name": "Magnus Carlsen" -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/package.json b/packages/@sanity/cli/test/__fixtures__/v2/package.json deleted file mode 100644 index 89748c699af..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "v2-studio", - "version": "0.0.1", - "private": true, - "description": "A Sanity v2 studio for CI testing.", - "keywords": [ - "fixture" - ], - "license": "MIT", - "author": "Sanity.io ", - "scripts": { - "build": "sanity build", - "start": "sanity start" - }, - "dependencies": { - "@sanity/base": "^2.33.3", - "@sanity/cli": "^2.33.3", - "@sanity/core": "^2.33.3", - "@sanity/default-layout": "^2.33.3", - "@sanity/default-login": "^2.33.3", - "@sanity/desk-tool": "^2.33.3", - "react": "17.0.2", - "react-dom": "17.0.2", - "styled-components": "^6.1.0" - } -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/sanity.json b/packages/@sanity/cli/test/__fixtures__/v2/sanity.json deleted file mode 100644 index 7f21850e51b..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/sanity.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "root": true, - "project": { - "name": "v2 studio" - }, - "apiHost": "https://api.sanity.work", - "api": { - "projectId": "1d4femd5", - "dataset": "production" - }, - "plugins": [ - "@sanity/base", - "@sanity/default-layout", - "@sanity/default-login", - "@sanity/desk-tool" - ], - "server": { - "port": 3334 - }, - "parts": [ - { - "name": "part:@sanity/base/schema", - "path": "schema" - }, - { - "implements": "part:@sanity/base/brand-logo", - "path": "./components/MyLogo.tsx" - } - ] -} diff --git a/packages/@sanity/cli/test/__fixtures__/v2/schema.js b/packages/@sanity/cli/test/__fixtures__/v2/schema.js deleted file mode 100644 index 9ae03aa33ca..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/schema.js +++ /dev/null @@ -1,38 +0,0 @@ -/* eslint-disable import/no-unresolved */ -import schemaTypes from 'all:part:@sanity/base/schema-type' -import createSchema from 'part:@sanity/base/schema-creator' - -export default createSchema({ - name: 'v2-schema', - types: schemaTypes.concat([ - { - name: 'person', - title: 'Person', - type: 'document', - fields: [ - { - name: 'name', - title: 'Name', - type: 'string', - }, - { - name: 'slug', - title: 'Slug', - type: 'slug', - options: { - source: 'name', - maxLength: 100, - }, - }, - { - name: 'image', - title: 'Image', - type: 'image', - options: { - hotspot: true, - }, - }, - ], - }, - ]), -}) diff --git a/packages/@sanity/cli/test/__fixtures__/v2/script.js b/packages/@sanity/cli/test/__fixtures__/v2/script.js deleted file mode 100644 index d5bcd3a60c3..00000000000 --- a/packages/@sanity/cli/test/__fixtures__/v2/script.js +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint-disable import/no-unresolved, no-console */ -// Tests that `sanity exec` in v2 can import parts, and use a preconfigured client -import client from 'part:@sanity/base/client' - -client - .withConfig({apiVersion: '2022-09-09', apiHost: 'https://api.sanity.work'}) - .users.getById('me') - .then( - (user) => console.log(JSON.stringify({user, env: process.env}, null, 2)), - (err) => console.error(err), - ) diff --git a/packages/@sanity/cli/test/build.test.ts b/packages/@sanity/cli/test/build.test.ts index b46f713b87d..db1d468a23c 100644 --- a/packages/@sanity/cli/test/build.test.ts +++ b/packages/@sanity/cli/test/build.test.ts @@ -27,23 +27,7 @@ describeCliTest('CLI: `sanity build` / `sanity deploy`', () => { expect(result.code).toBe(0) // These _could_ theoretically change, but is unlikely to with v2 being in support mode - if (version === 'v2') { - const builtHtml = await readFile(path.join(studioPath, 'out/index.html'), 'utf8') - const builtJs = await readFile( - path.join(studioPath, 'out/static/js/app.bundle.js'), - 'utf8', - ) - const builtCss = await readFile(path.join(studioPath, 'out/static/css/main.css'), 'utf8') - expect(builtHtml).toContain('id="sanityBody"') - expect(builtJs).toContain('Restoring Sanity Studio') - expect(builtCss).toContain('Spinner_sanity') - - // `.env` behavior is different in v2 - only the environment file is used - // (`.env.development` / `.env.production`) - not `.env`. Also, it always - // defaults to `development` unless `SANITY_ACTIVE_ENV` or `NODE_ENV` is set - expect(builtJs).not.toContain('this-should-never-be-used') - expect(builtJs).toContain('this-should-be-development') - } else if (version === 'v3') { + if (version === 'v3') { const files = await readdir(path.join(studioPath, 'out', 'static')) const jsPath = files.find((file) => file.startsWith('sanity-') && file.endsWith('.js')) const cssPath = files.find((file) => file.endsWith('.css')) diff --git a/packages/@sanity/cli/test/dev.test.ts b/packages/@sanity/cli/test/dev.test.ts index b0c2433bf9d..f5768883bf4 100644 --- a/packages/@sanity/cli/test/dev.test.ts +++ b/packages/@sanity/cli/test/dev.test.ts @@ -12,19 +12,18 @@ describeCliTest('CLI: `sanity dev`', () => { describe.each(studioVersions)('%s', (version) => { test('start', async () => { const testRunArgs = getTestRunArgs(version) - const expectedFiles = - version === 'v2' ? [] : ['static/favicon.ico', 'favicon.ico', 'static/favicon.svg'] + const expectedFiles = ['static/favicon.ico', 'favicon.ico', 'static/favicon.svg'] const {html: startHtml, fileHashes} = await testServerCommand({ - command: version === 'v2' ? 'start' : 'dev', + command: 'dev', port: testRunArgs.port, args: ['--port', `${testRunArgs.port}`], cwd: path.join(studiosPath, version), - expectedTitle: version === 'v2' ? `${version} studio` : 'Sanity Studio', + expectedTitle: 'Sanity Studio', expectedFiles, }) - expect(startHtml).toContain(version === 'v2' ? 'id="sanityBody"' : 'id="sanity"') + expect(startHtml).toContain('id="sanity"') for (const file of expectedFiles) { expect(fileHashes.get(file)).not.toBe(null) @@ -39,10 +38,6 @@ describeCliTest('CLI: `sanity dev`', () => { }) test('start with custom document component', async () => { - if (version === 'v2') { - return - } - const testRunArgs = getTestRunArgs(version) const {html: startHtml} = await testServerCommand({ command: 'dev', @@ -59,10 +54,6 @@ describeCliTest('CLI: `sanity dev`', () => { }) test('start with custom document component, in prod mode', async () => { - if (version === 'v2') { - return - } - const testRunArgs = getTestRunArgs(version) const {html: startHtml} = await testServerCommand({ command: 'dev', diff --git a/packages/@sanity/cli/test/exec.test.ts b/packages/@sanity/cli/test/exec.test.ts index 0f3f2ee1e1b..264125e715f 100644 --- a/packages/@sanity/cli/test/exec.test.ts +++ b/packages/@sanity/cli/test/exec.test.ts @@ -5,10 +5,8 @@ import {getCliUserEmail, runSanityCmdCommand, studioVersions} from './shared/env describeCliTest('CLI: `sanity exec`', () => { describe.each(studioVersions)('%s', (version) => { - const script = version === 'v2' ? 'script.js' : 'script.ts' - testConcurrent('sanity exec', async () => { - const result = await runSanityCmdCommand(version, ['exec', script]) + const result = await runSanityCmdCommand(version, ['exec', 'script.ts']) const data = JSON.parse(result.stdout.trim()) expect(Object.keys(data.user)).toHaveLength(0) // Check that we load from .env.development @@ -17,7 +15,7 @@ describeCliTest('CLI: `sanity exec`', () => { }) testConcurrent('sanity exec --with-user-token', async () => { - const result = await runSanityCmdCommand(version, ['exec', script, '--with-user-token']) + const result = await runSanityCmdCommand(version, ['exec', 'script.ts', '--with-user-token']) const data = JSON.parse(result.stdout.trim()) expect(data.user.email).toBe(await getCliUserEmail()) // Check that we load from .env.development @@ -26,7 +24,7 @@ describeCliTest('CLI: `sanity exec`', () => { }) testConcurrent('sanity exec with env override', async () => { - const result = await runSanityCmdCommand(version, ['exec', script], { + const result = await runSanityCmdCommand(version, ['exec', 'script.ts'], { env: {SANITY_ACTIVE_ENV: 'production'}, }) const data = JSON.parse(result.stdout.trim()) diff --git a/packages/@sanity/cli/test/graphql.test.ts b/packages/@sanity/cli/test/graphql.test.ts index 9a7dc006a8e..b7c23261cc0 100644 --- a/packages/@sanity/cli/test/graphql.test.ts +++ b/packages/@sanity/cli/test/graphql.test.ts @@ -8,9 +8,7 @@ describeCliTest('CLI: `sanity graphql`', () => { describeCliTest.each(studioVersions)('%s', (version) => { const testRunArgs = getTestRunArgs(version) const graphqlDataset = testRunArgs.graphqlDataset - const deployFlags = ['--force', '--dataset', graphqlDataset].concat( - version === 'v2' ? ['--no-playground'] : [], - ) + const deployFlags = ['--force', '--dataset', graphqlDataset] const client = testClient.withConfig({dataset: graphqlDataset}) testConcurrent('graphql deploy', async () => { diff --git a/packages/@sanity/cli/test/shared/describe.ts b/packages/@sanity/cli/test/shared/describe.ts index cedb2635cbc..00cec36e823 100644 --- a/packages/@sanity/cli/test/shared/describe.ts +++ b/packages/@sanity/cli/test/shared/describe.ts @@ -9,7 +9,7 @@ export const describeCliTest: typeof describe.skip = cliUserToken && hasBuiltCli ? describe : describe.skip // test.concurrent() runs even if the parent describe is skipped, so we need to wrap it as well -export const testConcurrent = (name: string, testFn: ProvidesCallback, timeout = 30000): void => { +export const testConcurrent = (name: string, testFn: ProvidesCallback, timeout = 60000): void => { const tester = cliUserToken && hasBuiltCli ? test.concurrent : test.concurrent.skip return tester(name, testFn, timeout) } diff --git a/packages/@sanity/cli/test/shared/environment.ts b/packages/@sanity/cli/test/shared/environment.ts index 1b6cb4b41fd..de12facde53 100644 --- a/packages/@sanity/cli/test/shared/environment.ts +++ b/packages/@sanity/cli/test/shared/environment.ts @@ -13,7 +13,7 @@ export const cliApiHost = 'https://api.sanity.work' export const hasBuiltCli = existsSync(path.join(__dirname, '..', '..', 'lib', 'cli.js')) export const fixturesPath = path.join(__dirname, '..', '__fixtures__') -export const studioVersions = ['v2', 'v3'] as const +export const studioVersions = ['v3'] as const export const doCleanup = false export const baseTestPath = path.join(tmpdir(), 'sanity-cli-test') export const testIdPath = path.join(baseTestPath, 'test-id.txt') @@ -82,10 +82,6 @@ const getTestId = () => { * once for node current. */ function getPort(version: string): number { - if (version === 'v2') { - return 3334 - } - if (process.release.lts) { return 4333 } diff --git a/packages/@sanity/cli/test/shared/globalSetup.ts b/packages/@sanity/cli/test/shared/globalSetup.ts index 70c21b374a7..eaa4a9fd6f2 100644 --- a/packages/@sanity/cli/test/shared/globalSetup.ts +++ b/packages/@sanity/cli/test/shared/globalSetup.ts @@ -89,12 +89,6 @@ function prepareStudios() { await mkdir(destinationPath, {recursive: true}) await copy(`${sourceStudioPath}/**/{*,.*}`, destinationPath, {dereference: true}) - - if (version === 'v2') { - await exec(npmPath, ['install', '--no-package-lock', '--legacy-peer-deps'], { - cwd: destinationPath, - }) - } if (version === 'v3') { // We'll want to test the actual integration with the monorepo packages, // instead of the versions that is available on npm, so we'll symlink them before running npm install diff --git a/packages/@sanity/cli/vitest.config.mts b/packages/@sanity/cli/vitest.config.mts index 8266470689a..b48d657579f 100644 --- a/packages/@sanity/cli/vitest.config.mts +++ b/packages/@sanity/cli/vitest.config.mts @@ -1,4 +1,10 @@ import {defineConfig} from '@repo/test-config/vitest' +// needed for globalSetup +import dotenv from 'dotenv' + +dotenv.config({ + path: [`${__dirname}/../../../.env.local`, `${__dirname}/../../../.env`], +}) export default defineConfig({ test: {