-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into upgrade-pkg-utils-v5
- Loading branch information
Showing
8 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/@sanity/cli/test/__fixtures__/v3/folder-typegen.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"schema": "./components" | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/@sanity/cli/test/__fixtures__/v3/missing-typegen.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"schema": "./custom-schema.json" | ||
} |
84 changes: 84 additions & 0 deletions
84
packages/@sanity/cli/test/__fixtures__/v3/working-schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
[ | ||
{ | ||
"name": "person", | ||
"type": "document", | ||
"attributes": { | ||
"_id": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "string" | ||
} | ||
}, | ||
"_type": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "string", | ||
"value": "person" | ||
} | ||
}, | ||
"_createdAt": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "string" | ||
} | ||
}, | ||
"_updatedAt": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "string" | ||
} | ||
}, | ||
"_rev": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "string" | ||
} | ||
}, | ||
"name": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "string" | ||
}, | ||
"optional": true | ||
}, | ||
"slug": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "inline", | ||
"name": "slug" | ||
}, | ||
"optional": true | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "slug", | ||
"type": "type", | ||
"value": { | ||
"type": "object", | ||
"attributes": { | ||
"_type": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "string", | ||
"value": "slug" | ||
} | ||
}, | ||
"current": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "string" | ||
}, | ||
"optional": true | ||
}, | ||
"source": { | ||
"type": "objectAttribute", | ||
"value": { | ||
"type": "string" | ||
}, | ||
"optional": true | ||
} | ||
} | ||
} | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
packages/@sanity/cli/test/__fixtures__/v3/working-typegen.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"schema": "./working-schema.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {expect, test} from '@jest/globals' | ||
|
||
import {describeCliTest} from './shared/describe' | ||
import {runSanityCmdCommand} from './shared/environment' | ||
|
||
describeCliTest('CLI: `sanity typegen`', () => { | ||
test('sanity typegen generate: missing schema, default path', async () => { | ||
const err = await runSanityCmdCommand('v3', ['typegen', 'generate']).catch((error) => error) | ||
expect(err.code).toBe(1) | ||
expect(err.stderr).toContain('did you run "sanity schema extract"') | ||
expect(err.stderr).toContain('Schema file not found') | ||
}) | ||
|
||
test('sanity typegen generate: missing schema, custom path', async () => { | ||
const err = await runSanityCmdCommand('v3', [ | ||
'typegen', | ||
'generate', | ||
'--config-path', | ||
'missing-typegen.json', | ||
]).catch((error) => error) | ||
expect(err.code).toBe(1) | ||
expect(err.stderr).not.toContain('did you run "sanity schema extract"') | ||
expect(err.stderr).toContain('custom-schema.json') | ||
}) | ||
|
||
test('sanity typegen generate: typegen config is not a file', async () => { | ||
const err = await runSanityCmdCommand('v3', [ | ||
'typegen', | ||
'generate', | ||
'--config-path', | ||
'folder-typegen.json', | ||
]).catch((error) => error) | ||
expect(err.code).toBe(1) | ||
expect(err.stderr).toContain('Schema path is not a file') | ||
}) | ||
|
||
test('sanity typegen generate: working schema', async () => { | ||
const result = await runSanityCmdCommand('v3', [ | ||
'typegen', | ||
'generate', | ||
'--config-path', | ||
'working-typegen.json', | ||
]) | ||
|
||
expect(result.code).toBe(0) | ||
expect(result.stderr).toContain('Generated TypeScript types for 2 schema types') | ||
}) | ||
}) |