-
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.
fix: various reflection path resolution fixes, better test code blocks
- Loading branch information
Showing
44 changed files
with
1,255 additions
and
284 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { JSDOM } from 'jsdom'; | ||
|
||
export const formatExpanded = ( file: string, content: string ) => `<details class="code-block" open=""><summary><p>From ${file}</p></summary>${content}\n</details>`; | ||
export const checkDef = ( dom: JSDOM, id: string, codeBlock: string ) => { | ||
const link = dom.window.document.getElementById( id ); | ||
expect( link ).toBeTruthy(); | ||
const section = link!.parentElement; | ||
expect( section ).toBeTruthy(); | ||
const blocks = section!.querySelectorAll( '.code-block' ); | ||
expect( blocks ).toHaveLength( 1 ); | ||
const block = blocks[0]!; | ||
expect( block.outerHTML ).toEqual( codeBlock ); | ||
}; |
523 changes: 523 additions & 0 deletions
523
packages/plugin-code-blocks/__tests__/integration/__snapshots__/monorepo.spec.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
286 changes: 286 additions & 0 deletions
286
packages/plugin-code-blocks/__tests__/integration/__snapshots__/simple.spec.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
159 changes: 0 additions & 159 deletions
159
packages/plugin-code-blocks/__tests__/integration/__snapshots__/test.spec.ts.snap
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
packages/plugin-code-blocks/__tests__/integration/monorepo.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { readFile } from 'fs/promises'; | ||
import { resolve } from 'path'; | ||
|
||
import { JSDOM } from 'jsdom'; | ||
|
||
import { formatHtml, runPlugin } from '@knodes/typedoc-plugintestbed'; | ||
|
||
import { checkDef, formatExpanded } from '../helpers'; | ||
|
||
const rootDir = resolve( __dirname, '../mock-fs/monorepo' ); | ||
jest.setTimeout( 30000 ); | ||
beforeEach( () => { | ||
process.chdir( rootDir ); | ||
} ); | ||
describe( 'Real behavior', () => { | ||
it( 'should render correctly', async () => { | ||
await runPlugin( rootDir, resolve( __dirname, '../../src/index' ) ); | ||
const testJson = '<pre><code class="language-json">'+ | ||
'<span class="hl-0">{</span><span class="hl-1">"Hello"</span><span class="hl-0">: </span><span class="hl-2">"World"</span><span class="hl-0">}</span>\n'+ | ||
'</code></pre>'; | ||
const testJsonA = testJson.replace( 'Hello', 'pkg' ).replace( 'World', 'a' ); | ||
const testJsonB = testJson.replace( 'Hello', 'pkg' ).replace( 'World', 'b' ); | ||
|
||
const pkgA = await readFile( resolve( rootDir, 'docs/modules/pkg_a.html' ), 'utf-8' ); | ||
const domA = new JSDOM( pkgA ); | ||
checkDef( domA, 'testInProjA', formatExpanded( './packages/a/blocks/test.json', testJsonA ) ); | ||
checkDef( domA, 'testInProjB', formatExpanded( './packages/b/blocks/test.json', testJsonB ) ); | ||
checkDef( domA, 'testNoPrefixImplicitInBlocks', formatExpanded( './packages/a/blocks/test.json', testJsonA ) ); | ||
checkDef( domA, 'testNoPrefixInBlocks', formatExpanded( './packages/a/blocks/test.json', testJsonA ) ); | ||
expect( pkgA ).toMatch( /<link\s+rel="stylesheet"\s+href="([^"]*?\/)?assets\/code-blocks\.css"\s*\/>/ ); | ||
expect( formatHtml( pkgA ) ).toMatchSnapshot(); | ||
|
||
const pkgB = await readFile( resolve( rootDir, 'docs/modules/pkg_b.html' ), 'utf-8' ); | ||
const domB = new JSDOM( pkgB ); | ||
checkDef( domB, 'testInProjA', formatExpanded( './packages/a/blocks/test.json', testJsonA ) ); | ||
checkDef( domB, 'testInProjB', formatExpanded( './packages/b/blocks/test.json', testJsonB ) ); | ||
checkDef( domB, 'testNoPrefixImplicitInBlocks', formatExpanded( './packages/b/blocks/test.json', testJsonB ) ); | ||
checkDef( domB, 'testNoPrefixInBlocks', formatExpanded( './packages/b/blocks/test.json', testJsonB ) ); | ||
expect( pkgB ).toMatch( /<link\s+rel="stylesheet"\s+href="([^"]*?\/)?assets\/code-blocks\.css"\s*\/>/ ); | ||
expect( formatHtml( pkgB ) ).toMatchSnapshot(); | ||
} ); | ||
} ); |
32 changes: 32 additions & 0 deletions
32
packages/plugin-code-blocks/__tests__/integration/simple.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { readFile } from 'fs/promises'; | ||
import { resolve } from 'path'; | ||
|
||
import { JSDOM } from 'jsdom'; | ||
|
||
import { formatHtml, runPlugin } from '@knodes/typedoc-plugintestbed'; | ||
|
||
import { checkDef, formatExpanded } from '../helpers'; | ||
|
||
const rootDir = resolve( __dirname, '../mock-fs/simple' ); | ||
jest.setTimeout( 30000 ); | ||
beforeEach( () => { | ||
process.chdir( rootDir ); | ||
} ); | ||
describe( 'Real behavior', () => { | ||
it( 'should render correctly', async () => { | ||
await runPlugin( rootDir, resolve( __dirname, '../../src/index' ) ); | ||
const c = await readFile( resolve( rootDir, 'docs/modules.html' ), 'utf-8' ); | ||
const dom = new JSDOM( c ); | ||
const testJson = '<pre><code class="language-json">'+ | ||
'<span class="hl-0">{</span><span class="hl-1">"Hello"</span><span class="hl-0">: </span><span class="hl-2">"World"</span><span class="hl-0">}</span>\n'+ | ||
'</code></pre>'; | ||
const testJsonFooBar = testJson.replace( 'Hello', 'Foo' ).replace( 'World', 'Bar' ); | ||
checkDef( dom, 'testProjImplicitInBlocks', formatExpanded( './blocks/test.json', testJson ) ); | ||
checkDef( dom, 'testProjInBlocks', formatExpanded( './blocks/test.json', testJson ) ); | ||
checkDef( dom, 'testNoPrefixImplicitInBlocks', formatExpanded( './blocks/test.json', testJson ) ); | ||
checkDef( dom, 'testNoPrefixInBlocks', formatExpanded( './blocks/test.json', testJson ) ); | ||
checkDef( dom, 'testRel', formatExpanded( './src/test.json', testJsonFooBar ) ); | ||
expect( c ).toMatch( /<link\s+rel="stylesheet"\s+href="([^"]*?\/)?assets\/code-blocks\.css"\s*\/>/ ); | ||
expect( formatHtml( c ) ).toMatchSnapshot(); | ||
} ); | ||
} ); |
37 changes: 0 additions & 37 deletions
37
packages/plugin-code-blocks/__tests__/integration/test.spec.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/blocks/test.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 @@ | ||
{"pkg": "a"} |
4 changes: 4 additions & 0 deletions
4
packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/package.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,4 @@ | ||
{ | ||
"name": "pkg-a", | ||
"typedocMain": "./src" | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/a/src/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const stub = () => 1; | ||
|
||
// #region inExplicitPackage | ||
/** | ||
* A test code block targetting project A | ||
* | ||
* {@codeblock ~pkg-a/test.json} | ||
*/ | ||
export const testInProjA = stub; | ||
|
||
/** | ||
* A test code block targetting project B | ||
* | ||
* {@codeblock ~pkg-b/test.json} | ||
*/ | ||
export const testInProjB = stub; | ||
// #endregion | ||
|
||
// #region inPackage | ||
/** | ||
* A test code block for unprefixed path implicitly in blocks directory | ||
* | ||
* {@codeblock test.json} | ||
*/ | ||
export const testNoPrefixImplicitInBlocks = stub; | ||
|
||
/** | ||
* A test code block for unprefixed path in blocks directory | ||
* | ||
* {@codeblock blocks/test.json} | ||
*/ | ||
export const testNoPrefixInBlocks = stub; | ||
// #endregion |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/blocks/test.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 @@ | ||
{"pkg": "b"} |
4 changes: 4 additions & 0 deletions
4
packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/package.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,4 @@ | ||
{ | ||
"name": "pkg-b", | ||
"typedocMain": "./src" | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/src/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const stub = () => 1; | ||
|
||
// #region inExplicitPackage | ||
/** | ||
* A test code block targetting project A | ||
* | ||
* {@codeblock ~pkg-a/test.json} | ||
*/ | ||
export const testInProjA = stub; | ||
|
||
/** | ||
* A test code block targetting project B | ||
* | ||
* {@codeblock ~pkg-b/test.json} | ||
*/ | ||
export const testInProjB = stub; | ||
// #endregion | ||
|
||
// #region inPackage | ||
/** | ||
* A test code block for unprefixed path implicitly in blocks directory | ||
* | ||
* {@codeblock test.json} | ||
*/ | ||
export const testNoPrefixImplicitInBlocks = stub; | ||
|
||
/** | ||
* A test code block for unprefixed path in blocks directory | ||
* | ||
* {@codeblock blocks/test.json} | ||
*/ | ||
export const testNoPrefixInBlocks = stub; | ||
// #endregion |
7 changes: 7 additions & 0 deletions
7
packages/plugin-code-blocks/__tests__/mock-fs/monorepo/packages/b/tsconfig.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,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "CommonJS" | ||
}, | ||
"include": ["**/*.ts"] | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/plugin-code-blocks/__tests__/mock-fs/monorepo/tsconfig.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,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "CommonJS" | ||
}, | ||
"include": ["**/*.ts"] | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/plugin-code-blocks/__tests__/mock-fs/monorepo/typedoc.js
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 @@ | ||
module.exports = { | ||
'entryPoints': [ | ||
'packages/*', | ||
], | ||
'entryPointStrategy': 'packages', | ||
'pluginCodeBlocks:source': 'blocks', | ||
}; |
Empty file.
Oops, something went wrong.