@@ -4,46 +4,18 @@ import recursive_output from "./fixtures/recursive_output";
44
55import * as path from "path" ;
66
7- import {
8- get_base_documentation ,
9- get_package_documentation ,
10- rc_read_file ,
11- transform_files ,
12- } from "./get_content" ;
7+ import { rc_read_file , transform_files } from "./get_content" ;
138
14- const repo = path . join ( __dirname , "fixtures" , "repo-1" ) ;
15- const repo2 = path . join ( __dirname , "fixtures" , "repo-2" ) ;
169const repo3 = path . join ( __dirname , "fixtures" , "repo-3" ) ;
1710
18- const get_docs = suite ( "get_base_documentation" ) ;
19- const get_pkg_docs = suite ( "get_package_documentation" ) ;
2011const recrusive_read = suite ( "rc_read_file" ) ;
2112const transform = suite ( "transform_files" ) ;
2213
2314recrusive_read ( "recursively reads file and dirs" , async ( ) => {
2415 const content = await rc_read_file ( repo3 ) ;
25- // console.log(JSON.stringify(content, null, 2));
2616 assert . equal ( content , recursive_output ) ;
2717} ) ;
2818
29- get_docs . skip ( "gets the api documentation correctly" , async ( ) => {
30- const content = await get_base_documentation ( "documentation" , repo ) ;
31-
32- assert . equal ( content && content . docs , [
33- [ "01-one.md" , "file-one\n" ] ,
34- [ "02-two.md" , "file-two\n" ] ,
35- [ "03-three.md" , "file-three\n" ] ,
36- [ "04-four.md" , "file-four\n" ] ,
37- ] ) ;
38- } ) ;
39-
40- get_docs . skip ( "get base documentation when it is a root readme" , async ( ) => {
41- const content = await get_base_documentation ( "documentation" , repo2 ) ;
42- assert . equal ( content && content . docs , [
43- [ "standard-package" , "repo-2 docs\n" ] ,
44- ] ) ;
45- } ) ;
46-
4719transform ( "transforms basic docs" , ( ) => {
4820 const files = {
4921 name : "repo" ,
@@ -467,30 +439,152 @@ transform("transforms examples", () => {
467439 ] ) ;
468440} ) ;
469441
470- get_pkg_docs . skip (
471- "get documentation for packages ignoring invalid packages" ,
472- async ( ) => {
473- const content = await get_package_documentation ( "packages" , repo ) ;
442+ transform ( "transforms package readmes" , ( ) => {
443+ const files = {
444+ name : "repo-3" ,
445+ is_dir : true ,
446+ content : [
447+ {
448+ name : "packages" ,
449+ is_dir : true ,
450+ content : [
451+ {
452+ name : "random-extra-files" ,
453+ is_dir : true ,
454+ content : [
455+ {
456+ name : "README.md" ,
457+ is_dir : false ,
458+ content : "random-extra-files\n" ,
459+ } ,
460+ { name : "bipbopboom.whatever" , is_dir : false , content : "" } ,
461+ {
462+ name : "package.json" ,
463+ is_dir : false ,
464+ content : '{\n\t"name": "random-extra-files"\n}\n' ,
465+ } ,
466+ {
467+ name : "src" ,
468+ is_dir : true ,
469+ content : [ { name : "hello.bopbop" , is_dir : false , content : "" } ] ,
470+ } ,
471+ ] ,
472+ } ,
473+ {
474+ name : "standard-package" ,
475+ is_dir : true ,
476+ content : [
477+ {
478+ name : "README.md" ,
479+ is_dir : false ,
480+ content : "standard-package\n" ,
481+ } ,
482+ {
483+ name : "package.json" ,
484+ is_dir : false ,
485+ content : '{\n\t"name": "standard-package"\n}\n' ,
486+ } ,
487+ ] ,
488+ } ,
489+ ] ,
490+ } ,
491+ ] ,
492+ } ;
493+ const output = transform_files ( files , "packages" , "documentation" , "svelte" ) ;
494+ assert . equal ( output , [
495+ [
496+ "random-extra-files" ,
497+ {
498+ docs : [
499+ {
500+ name : "README.md" ,
501+ content : "random-extra-files\n" ,
502+ } ,
503+ { name : "bipbopboom.whatever" , content : "" } ,
504+ {
505+ name : "package.json" ,
506+ content : '{\n\t"name": "random-extra-files"\n}\n' ,
507+ } ,
508+ {
509+ name : "src" ,
510+ content : [ { name : "hello.bopbop" , content : "" } ] ,
511+ } ,
512+ ] ,
513+ } ,
514+ ] ,
515+ [
516+ "standard-package" ,
517+ {
518+ docs : [
519+ {
520+ name : "README.md" ,
521+ content : "standard-package\n" ,
522+ } ,
523+ {
524+ name : "package.json" ,
525+ content : '{\n\t"name": "standard-package"\n}\n' ,
526+ } ,
527+ ] ,
528+ } ,
529+ ] ,
530+ ] ) ;
531+ } ) ;
532+
533+ transform ( "get docs from root readme when no documentation folder" , ( ) => {
534+ const files = {
535+ name : "repo-3" ,
536+ is_dir : true ,
537+ content : [
538+ { name : "README.md" , is_dir : false , content : "standard-package\n" } ,
539+ {
540+ name : "package.json" ,
541+ is_dir : false ,
542+ content : '{\n\t"name": "standard-package"\n}\n' ,
543+ } ,
544+ ] ,
545+ } ;
546+
547+ const output = transform_files ( files , "" , "" , "some-package" ) ;
474548
475- assert . equal ( content , [
476- [ "random-extra-files" , "random-extra-files\n" ] ,
477- [ "standard-package" , "standard-package\n" ] ,
478- ] ) ;
479- }
480- ) ;
549+ assert . equal ( output , [
550+ [
551+ "some-package" ,
552+ {
553+ docs : [ { name : "README.md" , content : "standard-package\n" } ] ,
554+ } ,
555+ ] ,
556+ ] ) ;
557+ } ) ;
558+
559+ transform ( "increments the heading level of readme md files" , ( ) => {
560+ const files = {
561+ name : "repo-3" ,
562+ is_dir : true ,
563+ content : [
564+ {
565+ name : "README.md" ,
566+ is_dir : false ,
567+ content : "# standard-package\n## hello" ,
568+ } ,
569+ {
570+ name : "package.json" ,
571+ is_dir : false ,
572+ content : '{\n\t"name": "standard-package"\n}\n' ,
573+ } ,
574+ ] ,
575+ } ;
481576
482- get_pkg_docs . skip (
483- "get documentation for packages optionally ignoring certain package" ,
484- async ( ) => {
485- const content = await get_package_documentation ( "packages" , repo , {
486- ignore : [ "standard-package" ] ,
487- } ) ;
577+ const output = transform_files ( files , "" , "" , "some-package" ) ;
488578
489- assert . equal ( content , [ [ "random-extra-files" , "random-extra-files\n" ] ] ) ;
490- }
491- ) ;
579+ assert . equal ( output , [
580+ [
581+ "some-package" ,
582+ {
583+ docs : [ { name : "README.md" , content : "### hello" } ] ,
584+ } ,
585+ ] ,
586+ ] ) ;
587+ } ) ;
492588
493- get_docs . run ( ) ;
494- get_pkg_docs . run ( ) ;
495589recrusive_read . run ( ) ;
496590transform . run ( ) ;
0 commit comments