-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dev): remove dependency on resolve order for linking in markdown … (
#599) Co-authored-by: Guillaume Chau <[email protected]>
- Loading branch information
Showing
6 changed files
with
113 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { createWriteStream, unlinkSync } from 'node:fs' | ||
import path from 'node:path' | ||
import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest' | ||
import { createMarkdownFilesWatcher } from '../markdown.js' | ||
import { watchStories } from '../stories.js' | ||
import { Context, createContext } from '../context.js' | ||
|
||
describe('markdown', async () => { | ||
vi.spyOn(process, 'cwd').mockReturnValue(path.resolve(__dirname, './markdown')) | ||
|
||
let ctx: Context | ||
let storyWatcher: Awaited<ReturnType<typeof watchStories>> | ||
|
||
beforeEach(async () => { | ||
ctx = await createContext({ | ||
mode: 'dev', | ||
}) | ||
|
||
// create watch stories to set context root etc. | ||
storyWatcher = await watchStories(ctx) | ||
}) | ||
|
||
afterEach(() => { | ||
storyWatcher.close() | ||
}) | ||
|
||
test('should not throw error or depend on - resolve order for linking', async () => { | ||
// FileWatcher should pickup the test markdown files (test1 and test2) | ||
// test1 links to test2 (issue previously as test1 resolved first) | ||
// test 2 links to test1 | ||
const { stop } = await createMarkdownFilesWatcher(ctx) | ||
expect(ctx.markdownFiles.length).toEqual(2) | ||
stop() | ||
}) | ||
|
||
test('should render html from md', async () => { | ||
const { stop } = await createMarkdownFilesWatcher(ctx) | ||
expect(ctx.markdownFiles[0].html).toContain('<p>') | ||
stop() | ||
}) | ||
|
||
test('should throw error on missing [md] story file.', async () => { | ||
const testFile3 = '/markdown/test3.story.md' | ||
const writer = createWriteStream(__dirname.concat(testFile3)) | ||
// link to missing file. | ||
writer.write( | ||
'<!-- File should link to test1 file. -->\n' + | ||
'# Test3\n\n' + | ||
'Link to test 4\n' + | ||
'[TEST](./test4.story.md)\n') | ||
writer.end() | ||
await new Promise(resolve => writer.on('finish', resolve)) | ||
|
||
// create markdownWatcher and check for error | ||
await expect(async () => createMarkdownFilesWatcher(ctx)).rejects.toThrowError() | ||
// delete test file, so failures are removed as well. | ||
unlinkSync(__dirname.concat(testFile3)) | ||
}) | ||
}) |
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,7 @@ | ||
<!-- File should link to test2 file. --> | ||
<!-- File should return test2 successfully, even though test1 loads before test2. --> | ||
|
||
# Test1 | ||
|
||
Link to test 2 | ||
[Test2](./test2.story.md) |
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,5 @@ | ||
<!-- File should link to test1 file. --> | ||
# Test2 | ||
|
||
Link to test 1 | ||
[Test1](./test1.story.md) |
10 changes: 6 additions & 4 deletions
10
packages/histoire/src/node/tree.spec.ts → .../histoire/src/node/__tests__/tree.spec.ts
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