|
| 1 | +import fs from 'node:fs/promises' |
| 2 | +import path from 'node:path' |
| 3 | + |
| 4 | +import {describe, expect} from '@jest/globals' |
| 5 | + |
| 6 | +import templates from '../src/actions/init-project/templates' |
| 7 | +import {describeCliTest, testConcurrent} from './shared/describe' |
| 8 | +import {baseTestPath, cliProjectId, getTestRunArgs, runSanityCmdCommand} from './shared/environment' |
| 9 | + |
| 10 | +describeCliTest('CLI: `sanity init v3`', () => { |
| 11 | + describe.each(Object.keys(templates))('for template %s', (template) => { |
| 12 | + testConcurrent('adds autoUpdates: true to cli config', async () => { |
| 13 | + const version = 'v3' |
| 14 | + const testRunArgs = getTestRunArgs(version) |
| 15 | + const outpath = `test-template-${template}-${version}` |
| 16 | + |
| 17 | + await runSanityCmdCommand(version, [ |
| 18 | + 'init', |
| 19 | + '--y', |
| 20 | + '--project', |
| 21 | + cliProjectId, |
| 22 | + '--dataset', |
| 23 | + testRunArgs.dataset, |
| 24 | + '--template', |
| 25 | + template, |
| 26 | + '--output-path', |
| 27 | + `${baseTestPath}/${outpath}`, |
| 28 | + '--package-manager', |
| 29 | + 'manual', |
| 30 | + ]) |
| 31 | + |
| 32 | + const cliConfig = await fs.readFile( |
| 33 | + path.join(baseTestPath, outpath, 'sanity.cli.ts'), |
| 34 | + 'utf-8', |
| 35 | + ) |
| 36 | + |
| 37 | + expect(cliConfig).toContain(`projectId: '${cliProjectId}'`) |
| 38 | + expect(cliConfig).toContain(`dataset: '${testRunArgs.dataset}'`) |
| 39 | + expect(cliConfig).toContain(`autoUpdates: true`) |
| 40 | + }) |
| 41 | + }) |
| 42 | + |
| 43 | + testConcurrent('adds autoUpdates: true to cli config for javascript projects', async () => { |
| 44 | + const version = 'v3' |
| 45 | + const testRunArgs = getTestRunArgs(version) |
| 46 | + const outpath = `test-template-${version}` |
| 47 | + |
| 48 | + await runSanityCmdCommand(version, [ |
| 49 | + 'init', |
| 50 | + '--y', |
| 51 | + '--project', |
| 52 | + cliProjectId, |
| 53 | + '--dataset', |
| 54 | + testRunArgs.dataset, |
| 55 | + '--output-path', |
| 56 | + `${baseTestPath}/${outpath}`, |
| 57 | + '--package-manager', |
| 58 | + 'manual', |
| 59 | + '--no-typescript', |
| 60 | + ]) |
| 61 | + |
| 62 | + const cliConfig = await fs.readFile(path.join(baseTestPath, outpath, 'sanity.cli.js'), 'utf-8') |
| 63 | + |
| 64 | + expect(cliConfig).toContain(`projectId: '${cliProjectId}'`) |
| 65 | + expect(cliConfig).toContain(`dataset: '${testRunArgs.dataset}'`) |
| 66 | + expect(cliConfig).toContain(`autoUpdates: true`) |
| 67 | + }) |
| 68 | + |
| 69 | + testConcurrent('adds autoUpdates: false to cli config if flag provided', async () => { |
| 70 | + const version = 'v3' |
| 71 | + const testRunArgs = getTestRunArgs(version) |
| 72 | + const outpath = `test-template-${version}` |
| 73 | + |
| 74 | + await runSanityCmdCommand(version, [ |
| 75 | + 'init', |
| 76 | + '--y', |
| 77 | + '--project', |
| 78 | + cliProjectId, |
| 79 | + '--dataset', |
| 80 | + testRunArgs.dataset, |
| 81 | + '--output-path', |
| 82 | + `${baseTestPath}/${outpath}`, |
| 83 | + '--package-manager', |
| 84 | + 'manual', |
| 85 | + '--no-auto-updates', |
| 86 | + ]) |
| 87 | + |
| 88 | + const cliConfig = await fs.readFile(path.join(baseTestPath, outpath, 'sanity.cli.ts'), 'utf-8') |
| 89 | + |
| 90 | + expect(cliConfig).toContain(`projectId: '${cliProjectId}'`) |
| 91 | + expect(cliConfig).toContain(`dataset: '${testRunArgs.dataset}'`) |
| 92 | + expect(cliConfig).toContain(`autoUpdates: false`) |
| 93 | + }) |
| 94 | +}) |
0 commit comments