@@ -6,6 +6,21 @@ import * as path from 'path';
66import { parseMarkup , cssUri } from '../markupParser' ;
77import * as fs from 'fs' ;
88
9+ const TEST_FILES_ROOT = path . join ( __dirname , "../../src/test/testfiles" ) ;
10+ const FIXTURES_ROOT = path . join ( __dirname , "../../src/test/resources/fixtures" ) ;
11+
12+ function walkdirSync ( dir : string ) : string [ ] {
13+ return fs . readdirSync ( dir ) . reduce ( function ( result : string [ ] , file ) {
14+ let name = path . join ( dir , file ) ;
15+ let isDir = fs . statSync ( name ) . isDirectory ( ) ;
16+ return result . concat ( isDir ? walkdirSync ( name ) : [ name ] ) ;
17+ } , [ ] ) ;
18+ }
19+
20+ function isConfluence ( element : string , index : number , array : string [ ] ) : boolean {
21+ return ( element . endsWith ( ".confluence" ) ) ;
22+ }
23+
924// Defines a Mocha test suite to group tests of similar kind together
1025suite ( "markupParser Tests" , function ( ) {
1126
@@ -20,10 +35,26 @@ suite("markupParser Tests", function () {
2035 }
2136 } ) ;
2237
23- test ( "Test render headers" , function ( ) {
24- const testFile = vscode . Uri . file ( path . join ( __dirname , "../../src/test/testfiles/nix/scoped/headings.confluence" ) ) ;
25- const expected = '<p><h1>Heading 1</h1></p><p><h2>Heading 2</h2></p><p><h3>Heading 3</h3></p><p><h4>Heading 4</h4></p><p><h5>Heading 5</h5></p><p><h6>Heading 6</h6></p>'
26- const content = fs . readFileSync ( testFile . fsPath , 'utf8' ) ;
27- assert . equal ( parseMarkup ( testFile , content ) , expected ) ;
38+ walkdirSync ( TEST_FILES_ROOT ) . filter ( isConfluence ) . forEach ( fullFilePath => {
39+ const fileName = path . basename ( fullFilePath ) ;
40+ const dirName = path . dirname ( fullFilePath ) ;
41+
42+ let typeDir = path . basename ( dirName ) ;
43+ let scopedDir = ''
44+ if ( dirName . endsWith ( 'scoped' ) ) {
45+ scopedDir = path . basename ( dirName ) ;
46+ typeDir = path . basename ( path . dirname ( dirName ) ) ;
47+ }
48+
49+ const testName = "Render testfile: " + path . join ( typeDir , scopedDir , fileName )
50+ test ( testName , function ( ) {
51+ const fixtureFile = path . join ( FIXTURES_ROOT , scopedDir , fileName . replace ( 'confluence' , 'html' ) ) ;
52+ const fixtureContent = fs . readFileSync ( fixtureFile , 'utf8' ) ;
53+
54+ const testFileUri = vscode . Uri . file ( fullFilePath ) ;
55+ const confluenceContent = fs . readFileSync ( testFileUri . fsPath , 'utf8' ) ;
56+
57+ assert . equal ( parseMarkup ( testFileUri , confluenceContent ) , fixtureContent ) ;
58+ } ) ;
2859 } ) ;
2960} ) ;
0 commit comments