Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 6d9d3d0

Browse files
committed
fix: Make typeRoot test more thorough, add global declaration test
1 parent 96d6c47 commit 6d9d3d0

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/test/project-manager.test.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,37 @@ function testWithRootUri(rootUri: string): void {
4343
const localfs = new MapFileSystem(new Map([
4444
[rootUri + 'project/package.json', '{"name": "package-name-1"}'],
4545
[rootUri + 'project/tsconfig.json', '{ "compilerOptions": { "typeRoots": ["../types"]} }'],
46-
[rootUri + 'project/file.ts', 'console.log(GLOBALCONSTANT);'],
46+
[rootUri + 'project/node_modules/%40types/mocha/index.d.ts', 'declare var describe { (description: string, spec: () => void): void; }'],
47+
[rootUri + 'project/file.ts', 'describe("test", () => console.log(GLOBALCONSTANT));'],
4748
[rootUri + 'types/types.d.ts', 'declare var GLOBALCONSTANT=1;']
4849

4950
]))
5051
const updater = new FileSystemUpdater(localfs, memfs)
5152
projectManager = new ProjectManager(rootPath, memfs, updater, true)
5253
})
54+
5355
it('loads files from typeRoots', async () => {
54-
await projectManager.ensureReferencedFiles(rootUri + 'project/file.ts').toPromise()
55-
memfs.getContent(rootUri + 'project/file.ts')
56-
memfs.getContent(rootUri + 'types/types.d.ts')
56+
const sourceFileUri = rootUri + 'project/file.ts'
57+
const typeRootFileUri = rootUri + 'types/types.d.ts'
58+
await projectManager.ensureReferencedFiles(sourceFileUri).toPromise()
59+
memfs.getContent(typeRootFileUri)
60+
61+
const config = projectManager.getConfiguration(uri2path(sourceFileUri), 'ts')
62+
const host = config.getHost()
63+
const typeDeclarationPath = uri2path(typeRootFileUri)
64+
assert.includeMembers(host.getScriptFileNames(), [typeDeclarationPath])
65+
})
66+
67+
it('loads mocha global type declarations', async () => {
68+
const sourceFileUri = rootUri + 'project/file.ts'
69+
const mochaDeclarationFileUri = rootUri + 'project/node_modules/%40types/mocha/index.d.ts'
70+
await projectManager.ensureReferencedFiles(sourceFileUri).toPromise()
71+
memfs.getContent(mochaDeclarationFileUri)
72+
73+
const config = projectManager.getConfiguration(uri2path(sourceFileUri), 'ts')
74+
const host = config.getHost()
75+
const mochaFilePath = uri2path(mochaDeclarationFileUri)
76+
assert.includeMembers(host.getScriptFileNames(), [mochaFilePath])
5777
})
5878
})
5979

0 commit comments

Comments
 (0)