Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cli): remove v2 fixtures and bump timeouts #7974

Merged
merged 4 commits into from
Dec 9, 2024
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 .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
1 change: 0 additions & 1 deletion packages/@sanity/cli/test/__fixtures__/v2/.env

This file was deleted.

3 changes: 0 additions & 3 deletions packages/@sanity/cli/test/__fixtures__/v2/.env.development

This file was deleted.

4 changes: 0 additions & 4 deletions packages/@sanity/cli/test/__fixtures__/v2/.env.production

This file was deleted.

2 changes: 0 additions & 2 deletions packages/@sanity/cli/test/__fixtures__/v2/.gitignore

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions packages/@sanity/cli/test/__fixtures__/v2/components/MyLogo.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions packages/@sanity/cli/test/__fixtures__/v2/config/.checksums

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions packages/@sanity/cli/test/__fixtures__/v2/document.json

This file was deleted.

26 changes: 0 additions & 26 deletions packages/@sanity/cli/test/__fixtures__/v2/package.json

This file was deleted.

30 changes: 0 additions & 30 deletions packages/@sanity/cli/test/__fixtures__/v2/sanity.json

This file was deleted.

38 changes: 0 additions & 38 deletions packages/@sanity/cli/test/__fixtures__/v2/schema.js

This file was deleted.

11 changes: 0 additions & 11 deletions packages/@sanity/cli/test/__fixtures__/v2/script.js

This file was deleted.

18 changes: 1 addition & 17 deletions packages/@sanity/cli/test/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny nit: this comment looks to be redundant now?

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'))
Expand Down
17 changes: 4 additions & 13 deletions packages/@sanity/cli/test/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand All @@ -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',
Expand Down
8 changes: 3 additions & 5 deletions packages/@sanity/cli/test/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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())
Expand Down
4 changes: 1 addition & 3 deletions packages/@sanity/cli/test/graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/cli/test/shared/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 1 addition & 5 deletions packages/@sanity/cli/test/shared/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 0 additions & 6 deletions packages/@sanity/cli/test/shared/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions packages/@sanity/cli/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
Loading