-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use code fences to document props in readme
improve readme test: now includes checking readme lists correct type and default value for primitive-type props
- Loading branch information
Showing
5 changed files
with
114 additions
and
31 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
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 |
---|---|---|
@@ -1,16 +1,28 @@ | ||
import Masonry from '$lib' | ||
import { readFileSync } from 'fs' | ||
import { expect, test } from 'vitest' | ||
import Masonry from '../src/lib' | ||
|
||
test(`readme documents all props`, () => { | ||
const readme = readFileSync(`readme.md`, `utf8`) | ||
const readme = readFileSync(`readme.md`, `utf8`) | ||
|
||
test(`readme documents all props and their correct types and defaults`, () => { | ||
const instance = new Masonry({ | ||
target: document.body, | ||
props: { items: [] }, | ||
}) | ||
const { props, ctx } = instance.$$ | ||
|
||
for (const prop of Object.keys(instance.$$.props)) { | ||
expect(readme).to.contain(`- \`${prop}: `) | ||
for (const [prop, ctx_idx] of Object.entries(props)) { | ||
let default_val = ctx[ctx_idx as number] | ||
const type: string = typeof default_val | ||
|
||
if (type === `string`) default_val = `'${default_val}'` | ||
|
||
if ([`string`, `number`, `boolean`].includes(type)) { | ||
const expected = `1. \`\`\`ts\n ${prop}: ${type} = ${default_val}\n \`\`\`` | ||
|
||
expect(readme).to.contain(expected) | ||
} else { | ||
expect(readme).to.contain(`1. \`\`\`ts\n ${prop}: `) | ||
} | ||
} | ||
}) |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"extends": "./.svelte-kit/tsconfig.json", | ||
"compilerOptions": { | ||
"strict": true, | ||
"module": "esnext", | ||
|