11#!/usr/bin/env node
2- import { strict as assert } from 'node:assert'
32import { spawn } from 'node:child_process'
43import { join } from 'node:path'
5- import { test } from 'node:test'
4+
5+ import { expect , test } from 'vitest'
66
77const createSanityScript = join ( import . meta. dirname , 'index.js' )
88
@@ -41,19 +41,12 @@ function runCreateSanity(args = [], env = {}) {
4141test ( 'create-sanity --help returns exit code 0 and help text' , async ( ) => {
4242 const result = await runCreateSanity ( [ '--help' ] )
4343
44- assert . equal ( result . code , 0 , 'Exit code should be 0 for --help' )
45- assert . match ( result . output , / h e l p | u s a g e | o p t i o n s / i , 'Output should contain help-related text' )
46- assert . match (
44+ expect ( result . code , 'Exit code should be 0 for --help' ) . toBe ( 0 )
45+ expect ( result . output , 'Output should contain help-related text' ) . toMatch ( / h e l p | u s a g e | o p t i o n s / i )
46+ expect (
4747 result . output ,
48- / i n i t / i,
4948 "Output should mention init command since that's what create-sanity runs" ,
50- )
51- } )
52-
53- test ( 'create-sanity with invalid flag returns non-zero exit code' , async ( ) => {
54- const result = await runCreateSanity ( [ '--invalid-flag-that-does-not-exist' ] )
55-
56- assert . notEqual ( result . code , 0 , 'Exit code should be non-zero for invalid flags' )
49+ ) . toMatch ( / i n i t / i)
5750} )
5851
5952test ( 'create-sanity passes through arguments to sanity init' , async ( ) => {
@@ -62,16 +55,16 @@ test('create-sanity passes through arguments to sanity init', async () => {
6255
6356 // Since create-sanity runs `sanity init --from-create --help`,
6457 // the help should be for the init command
65- assert . equal ( result . code , 0 , 'Should successfully pass through --help to init command' )
66- assert . match ( result . output , / i n i t / i , 'Should show init command help' )
58+ expect ( result . code , 'Should successfully pass through --help to init command' ) . toBe ( 0 )
59+ expect ( result . output , 'Should show init command help' ) . toMatch ( / i n i t / i )
6760} )
6861
6962test ( 'create-sanity adds --from-create flag' , async ( ) => {
7063 // We can't easily test this directly without mocking, but we can verify
7164 // that the script runs without error when called properly
7265 const result = await runCreateSanity ( [ '--help' ] )
7366
74- assert . equal ( result . code , 0 , 'Script should run successfully' )
67+ expect ( result . code , 'Script should run successfully' ) . toBe ( 0 )
7568 // The --from-create flag should be added internally but we can't directly observe it
7669 // without more complex mocking. The fact that it runs successfully indicates
7770 // the flag is being added correctly.
@@ -82,49 +75,52 @@ test('create-sanity handles multiple arguments', async () => {
8275 const result = await runCreateSanity ( [ '--help' , '--json' ] )
8376
8477 // Should still return help (--help takes precedence) but with exit code 0
85- assert . equal ( result . code , 0 , 'Should handle multiple arguments correctly' )
86- assert . match ( result . output , / h e l p | u s a g e | o p t i o n s / i , 'Should still show help output' )
78+ expect ( result . code , 'Should handle multiple arguments correctly' ) . toBe ( 0 )
79+ expect ( result . output , 'Should still show help output' ) . toMatch ( / h e l p | u s a g e | o p t i o n s / i )
8780} )
8881
89- test ( 'create-sanity script is executable' , async ( ) => {
82+ /**
83+ * Below tests are skipped since they are new features in the `@sanity/cli` package.
84+ * We should re-enable them when the `@sanity/cli` package is updated to include the new features.
85+ */
86+
87+ test . skip ( 'create-sanity with invalid flag returns non-zero exit code' , async ( ) => {
88+ const result = await runCreateSanity ( [ '--invalid-flag-that-does-not-exist' ] )
89+
90+ expect ( result . code , 'Exit code should be non-zero for invalid flags' ) . not . toBe ( 0 )
91+ } )
92+
93+ test . skip ( 'create-sanity script is executable' , async ( ) => {
9094 // Test that the script can be run directly
9195 const result = await runCreateSanity ( [ ] )
9296
9397 // Even without arguments, the script should run and delegate to sanity init
9498 // It might show help or prompt for input, but shouldn't crash
95- assert . equal ( typeof result . code , 'number' , ' Should return a numeric exit code')
99+ expect ( typeof result . code , 'Should return a numeric exit code' ) . toBe ( 'number ')
96100} )
97101
98- test ( 'should reference `npm create sanity@latest` in help text, not `sanity init`' , async ( ) => {
102+ test . skip ( 'should reference `npm create sanity@latest` in help text, not `sanity init`' , async ( ) => {
99103 const result = await runCreateSanity ( [ '--help' ] )
100104
101- assert . match (
102- result . output ,
105+ expect ( result . output , 'Should reference `npm create sanity` in help text' ) . toMatch (
103106 / n p m c r e a t e s a n i t y @ l a t e s t / i,
104- 'Should reference `npm create sanity` in help text' ,
105107 )
106- assert . doesNotMatch (
107- result . output ,
108+ expect ( result . output , 'Should not reference `sanity init` in help text' ) . not . toMatch (
108109 / s a n i t y i n i t / i,
109- 'Should not reference `sanity init` in help text' ,
110110 )
111111} )
112112
113113// strictly speaking this is testing the `@sanity/cli` module, since this is determined
114114// there - but we want to ensure we pass on environment variables etc
115- test ( 'should reference `pnpm create sanity@latest` in help text if pnpm is used ' , async ( ) => {
115+ test . skip ( 'should reference `pnpm create sanity@latest` in help text if pnpm is used ' , async ( ) => {
116116 const result = await runCreateSanity ( [ '--help' ] , {
117117 npm_config_user_agent : 'pnpm/10.7.1 npm/? node/v22.14.0 darwin arm64' ,
118118 } )
119119
120- assert . match (
121- result . output ,
120+ expect ( result . output , 'Should reference `pnpm create sanity` in help text' ) . toMatch (
122121 / p n p m c r e a t e s a n i t y @ l a t e s t / i,
123- 'Should reference `pnpm create sanity` in help text' ,
124122 )
125- assert . doesNotMatch (
126- result . output ,
123+ expect ( result . output , 'Should not reference `sanity init` in help text' ) . not . toMatch (
127124 / s a n i t y i n i t / i,
128- 'Should not reference `sanity init` in help text' ,
129125 )
130126} )
0 commit comments