-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsnapshot.test.ts
More file actions
82 lines (74 loc) · 2.74 KB
/
snapshot.test.ts
File metadata and controls
82 lines (74 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { generateFromSchema, readDoc as readDocument } from '../utils';
import { describe, expect, it } from 'vitest';
function stabilize(content: string): string {
return content
.replaceAll(/(· Generated: )\d{4}-\d{2}-\d{2}/gu, '$1<REDACTED>')
.replaceAll(
/zenstack-schema-[\da-f-]+\.zmodel/gu,
'zenstack-schema-<UUID>.zmodel',
)
.replaceAll(
/[^\s"')`]*[/\\]zenstack-schema-[^\s"')`]+\.zmodel/gu,
'<REDACTED>.zmodel',
)
.replaceAll(
/\*\*Duration\*\* \| [\d.]+ ms/gu,
'**Duration** | <REDACTED> ms',
)
.replaceAll(
/\*\*Generated\*\* \| \d{4}-\d{2}-\d{2}/gu,
'**Generated** | <REDACTED>',
)
.replaceAll(
/Generated:\*\* \d{4}-\d{2}-\d{2}/gu,
'Generated:** <REDACTED>',
);
}
describe('documentation plugin: snapshot', () => {
it('snapshot: full representative schema output', async () => {
const tmpDir = await generateFromSchema(`
/// User roles in the system.
enum Role {
/// Administrator with full access
ADMIN
/// Standard user
USER
}
/// Represents a registered user.
model User {
id String @id @default(cuid())
/// User's email address.
email String @unique @email
/// Display name shown in the UI.
name String
role Role
posts Post[]
@@allow('read', true)
@@deny('delete', true)
@@index([email])
@@meta('doc:category', 'Identity')
@@meta('doc:since', '1.0')
}
/// A blog post.
model Post {
id String @id @default(cuid())
/// The post title.
title String
content String?
author User @relation(fields: [authorId], references: [id])
authorId String
@@meta('doc:category', 'Content')
}
`);
const indexContent = stabilize(readDocument(tmpDir, 'index.md'));
const userDocument = stabilize(readDocument(tmpDir, 'models', 'User.md'));
const postDocument = stabilize(readDocument(tmpDir, 'models', 'Post.md'));
const roleDocument = stabilize(readDocument(tmpDir, 'enums', 'Role.md'));
const relDocument = stabilize(readDocument(tmpDir, 'relationships.md'));
expect(indexContent).toMatchSnapshot('index.md');
expect(userDocument).toMatchSnapshot('models/User.md');
expect(postDocument).toMatchSnapshot('models/Post.md');
expect(roleDocument).toMatchSnapshot('enums/Role.md');
expect(relDocument).toMatchSnapshot('relationships.md');
});
});