import { describe, expect, test } from 'vitest'; import { createCompiler, mdToGJS } from './gjs-md.js'; const compiler = createCompiler({}); describe('md to gjs', () => { test('it works', async () => { const virtualModulesByMarkdownFile = new Map>(); const result = await mdToGJS( `# Heading inline code \`\` ## code fence \`\`\`hbs live \`\`\` `, { compiler, id: 'test.gjs.md', virtualModulesByMarkdownFile, } ); expect(virtualModulesByMarkdownFile).toMatchInlineSnapshot(` Map { "test.gjs.md" => Map { "kolay/virtual:live:repl_1.gjs.hbs" => { "code": "", "flavor": null, "format": "hbs", "meta": "live", "placeholderId": "repl_1", }, }, } `); expect(result.code).toMatchInlineSnapshot(` "import { template as template_fd9b2463e5f141cfb5666b64daa1f11a } from "@ember/template-compiler"; import repl_1 from 'kolay/virtual:live:repl_1.gjs.hbs'; export default template_fd9b2463e5f141cfb5666b64daa1f11a(\`

Heading

inline code <Portal @to="popover">

code fence

\`, { eval () { return eval(arguments[0]); } }); " `); }); test('it allows top-level component invocation', async () => { const virtualModulesByMarkdownFile = new Map>(); const result = await mdToGJS( `# Heading `, { compiler, id: 'test.gjs.md', virtualModulesByMarkdownFile, scope: ` import { APIDocs, CommentQuery, ComponentSignature, HelperSignature, ModifierSignature } from 'kolay'; import { Shadowed } from 'ember-primitives/components/shadowed'; import { InViewport } from 'ember-primitives/viewport'; `, } ); expect(virtualModulesByMarkdownFile).toMatchInlineSnapshot(` Map { "test.gjs.md" => Map {}, } `); expect(result.code).toMatchInlineSnapshot(` "import { template as template_fd9b2463e5f141cfb5666b64daa1f11a } from "@ember/template-compiler"; import { APIDocs, CommentQuery, ComponentSignature, HelperSignature, ModifierSignature } from 'kolay'; import { Shadowed } from 'ember-primitives/components/shadowed'; import { InViewport } from 'ember-primitives/viewport'; export default template_fd9b2463e5f141cfb5666b64daa1f11a(\`

Heading

\`, { eval () { return eval(arguments[0]); } }); " `); }); test('handles a big dog with top-level component invocation', async () => { const virtualModulesByMarkdownFile = new Map>(); const result = await mdToGJS( ` # \`handlePotentialIndexVisit\` When using \`addRoutes()\`, navigating to a group URL (e.g. \`/Runtime\`) lands on an index route. If that group doesn't have an explicit index page, the user sees a blank page. \`handlePotentialIndexVisit\` solves this by automatically redirecting to the first page in the group. ## Usage Call it in the \`beforeModel\` hook of your page route: \`\`\`ts // routes/page.ts import Route from '@ember/routing/route'; import { handlePotentialIndexVisit } from 'kolay'; import type RouterService from '@ember/routing/router-service'; type Transition = ReturnType; export default class PageRoute extends Route { beforeModel(transition: Transition) { handlePotentialIndexVisit(this, transition); } } \`\`\` This pairs with \`addRoutes()\` in your router: \`\`\`js import { addRoutes } from 'kolay'; Router.map(function () { addRoutes(this); }); \`\`\` When a user visits \`/Runtime\` and the \`Runtime\` group has pages, they'll be redirected to the first page (e.g. \`/Runtime/docs/component-signature.md\`) instead of seeing a blank index. ## API Reference `, { compiler, id: 'test.gjs.md', virtualModulesByMarkdownFile, scope: ` import { APIDocs, CommentQuery, ComponentSignature, HelperSignature, ModifierSignature } from 'kolay'; import { Shadowed } from 'ember-primitives/components/shadowed'; import { InViewport } from 'ember-primitives/viewport'; `, } ); expect(virtualModulesByMarkdownFile).toMatchInlineSnapshot(` Map { "test.gjs.md" => Map {}, } `); expect(result.code).toMatchInlineSnapshot(` "import { template as template_fd9b2463e5f141cfb5666b64daa1f11a } from "@ember/template-compiler"; import { APIDocs, CommentQuery, ComponentSignature, HelperSignature, ModifierSignature } from 'kolay'; import { Shadowed } from 'ember-primitives/components/shadowed'; import { InViewport } from 'ember-primitives/viewport'; export default template_fd9b2463e5f141cfb5666b64daa1f11a(\`

handlePotentialIndexVisit

When using addRoutes(), navigating to a group URL (e.g. /Runtime) lands on an index route. If that group doesn't have an explicit index page, the user sees a blank page. handlePotentialIndexVisit solves this by automatically redirecting to the first page in the group.

Usage

Call it in the beforeModel hook of your page route:

// routes/page.ts
      import Route from '@ember/routing/route';
      import { handlePotentialIndexVisit } from 'kolay';

      import type RouterService from '@ember/routing/router-service';

      type Transition = ReturnType<RouterService['transitionTo']>;

      export default class PageRoute extends Route {
        beforeModel(transition: Transition) {
          handlePotentialIndexVisit(this, transition);
        }
      }
      

This pairs with addRoutes() in your router:

import { addRoutes } from 'kolay';

      Router.map(function () {
        addRoutes(this);
      });
      

When a user visits /Runtime and the Runtime group has pages, they'll be redirected to the first page (e.g. /Runtime/docs/component-signature.md) instead of seeing a blank index.

API Reference

\`, { eval () { return eval(arguments[0]); } }); " `); }); });