forked from englercj/tsd-jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
38 lines (31 loc) · 1.15 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import * as fs from 'fs';
import * as path from 'path';
import { expect } from 'chai';
import { renderSync } from './render';
const DEST_DIR = path.resolve(path.join(__dirname, '../_temp'));
const DATA_DIR = path.resolve(path.join(__dirname, '../fixtures'));
const EXPECT_DIR = path.resolve(path.join(__dirname, '../expected'));
const CONFIG_PATH = path.resolve(path.join(__dirname, '../../jsdoc-conf.json'));
before(() => {
// create the temp dir to store types in
try {
fs.mkdirSync(DEST_DIR);
} catch (e) { /* Do Nothing */ }
});
export function compileJsdoc(sourcePath: string) {
renderSync({
files: sourcePath,
cache: false,
destination: DEST_DIR,
configure: CONFIG_PATH
});
}
export function expectJsDoc(fileName: string) {
const destPath = path.join(DEST_DIR, `types.d.ts`);
const dataPath = path.join(DATA_DIR, `${fileName}.js`);
const expectPath = path.join(EXPECT_DIR, `${fileName}.d.ts`);
compileJsdoc(dataPath);
const destStr = fs.readFileSync(destPath, 'utf8');
const expectStr = fs.readFileSync(expectPath, 'utf8');
expect(destStr.trim()).to.equal(expectStr.trim());
}