Skip to content

Commit ea6d42b

Browse files
Merge branch 'main' into joan/order-from-config
2 parents 5523f95 + 3fbbe99 commit ea6d42b

File tree

10 files changed

+729
-3
lines changed

10 files changed

+729
-3
lines changed

packages/types/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
"dist"
1515
],
1616
"scripts": {
17-
"build": "tsc -b"
17+
"build": "tsc -b tsconfig.build.json",
18+
"test": "vitest"
1819
},
1920
"dependencies": {
2021
"zod": "3.23.8"
2122
},
2223
"devDependencies": {
23-
"typescript": "^5.4.5"
24+
"typescript": "^5.4.5",
25+
"vitest": "^1.6.0"
2426
}
2527
}

packages/types/src/files-ref.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { folderPathToFilesRef } from './files-ref.js';
3+
4+
describe('folderPathToFilesRef', () => {
5+
const testCases = [
6+
['path/to/folder', 'path-to-folder.json'],
7+
['path/to///folder', 'path-to-folder.json'],
8+
['files', 'files.json'],
9+
['path/to/folder_2', 'path-to-folder2.json'],
10+
['path\\to\\folder', 'path-to-folder.json'],
11+
['path\\to\\\\\\folder', 'path-to-folder.json'],
12+
];
13+
14+
testCases.forEach(([folderPath, expectedFilesRef]) => {
15+
it(`should return the files ref for a given folder path - ${folderPath}`, () => {
16+
const filesRef = folderPathToFilesRef(folderPath);
17+
18+
expect(filesRef).toBe(expectedFilesRef);
19+
});
20+
});
21+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { chapterSchema } from './chapter.js';
3+
4+
describe('chapterSchema', () => {
5+
it('should validate a valid chapter object', () => {
6+
expect(() =>
7+
chapterSchema.parse({
8+
title: 'Chapter 1',
9+
type: 'chapter',
10+
slug: 'chapter-one',
11+
}),
12+
).not.toThrow();
13+
});
14+
15+
it('should validate a chapter object without optional properties', () => {
16+
expect(() =>
17+
chapterSchema.parse({
18+
title: 'Chapter 1',
19+
type: 'chapter',
20+
}),
21+
).not.toThrow();
22+
});
23+
24+
it('should throw an error for a chapter object with invalid type', () => {
25+
expect(() =>
26+
chapterSchema.parse({
27+
title: 'Chapter 1',
28+
type: 'invalid',
29+
}),
30+
).toThrow();
31+
});
32+
33+
it('should throw an error for a chapter object with missing type property', () => {
34+
expect(() =>
35+
chapterSchema.parse({
36+
title: 'Chapter 1',
37+
}),
38+
).toThrow();
39+
});
40+
});

0 commit comments

Comments
 (0)