Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit 74cf6dd

Browse files
committed
Test host through DI
1 parent 95aa343 commit 74cf6dd

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

typescript/src/processors/readTypeScriptModules/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ export class ReadTypeScriptModules implements Processor {
5555
ignoreExportsMatching: Array<string|RegExp> = ['__esModule'];
5656
ignoreExportsRegexes: RegExp[] = [];
5757

58-
/**
59-
* Whether multiple leading comments of a TypeScript node should be concatenated or not.
60-
* By default, multiple leading comments for a node will be concatenated.
61-
*/
62-
concatLeadingNodeComments = true;
63-
6458
constructor(
6559
private tsParser: TsParser,
6660
private host: Host,

typescript/src/services/ts-host/host.spec.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1+
import { Dgeni, Package } from 'dgeni';
12
import { TsParser } from '../TsParser';
23
import { Host } from './host';
34

5+
const mockPackage = require('../../mocks/mockPackage');
46
const path = require('canonical-path');
57

68
describe('Host', () => {
9+
const basePath = path.resolve(__dirname, '../../mocks/tsParser');
10+
711
let host: Host;
812
let parser: TsParser;
9-
let basePath: string;
1013

11-
beforeEach(() => {
12-
host = new Host();
13-
parser = new TsParser(require('dgeni/lib/mocks/log')(false));
14-
basePath = path.resolve(__dirname, '../../mocks/tsParser');
15-
});
14+
/**
15+
* Creates the Host instance through Dgeni dependency injection. Also allows passing a function
16+
* that will run in Dgeni's configuration lifecycle and allows modifying the host factory.
17+
*/
18+
function setupTestDgeniInstance(configureFn: (host: Host) => void) {
19+
const testPackage = mockPackage() as Package;
20+
21+
testPackage.config((tsHost: Host) => configureFn(tsHost));
22+
23+
const dgeni = new Dgeni([testPackage]);
24+
const injector = dgeni.configureInjector();
25+
26+
// Load factories from the Dgeni injector.
27+
host = injector.get('tsHost');
28+
parser = injector.get('tsParser');
29+
}
1630

1731
it("should read content of a declaration", () => {
32+
setupTestDgeniInstance(h => h.concatMultipleLeadingComments = true);
33+
1834
const parseInfo = parser.parse(['multipleLeadingComments.ts'], basePath);
1935
const module = parseInfo.moduleSymbols[0];
2036
const declaration = module.exportArray[0].valueDeclaration!;
@@ -24,6 +40,8 @@ describe('Host', () => {
2440
});
2541

2642
it('should be able to disable leading comment concatenation', () => {
43+
setupTestDgeniInstance(h => h.concatMultipleLeadingComments = false);
44+
2745
const parseInfo = parser.parse(['multipleLeadingComments.ts'], basePath);
2846
const module = parseInfo.moduleSymbols[0];
2947
const declaration = module.exportArray[0].valueDeclaration!;

0 commit comments

Comments
 (0)