Write tests to demonstrate how baseUrl + pathMapping to node_modules behaves

This commit is contained in:
Sheetal Nandi 2018-08-14 15:46:51 -07:00
parent 62e6e6ae27
commit a32f62b310
5 changed files with 72 additions and 0 deletions

View file

@ -0,0 +1,14 @@
//// [tests/cases/compiler/pathMappingBasedModuleResolution_withExtension_MapedToNodeModules.ts] ////
//// [foobar.js]
module.exports = { a: 10 };
//// [a.ts]
import foobar from "foo/bar/foobar.js";
//// [/bin/node_modules/foo/bar/foobar.js]
module.exports = { a: 10 };
//// [/bin/a.js]
"use strict";
exports.__esModule = true;

View file

@ -0,0 +1,11 @@
=== /a.ts ===
import foobar from "foo/bar/foobar.js";
>foobar : Symbol(foobar, Decl(a.ts, 0, 6))
=== /node_modules/foo/bar/foobar.js ===
module.exports = { a: 10 };
>module.exports : Symbol("/node_modules/foo/bar/foobar", Decl(foobar.js, 0, 0))
>module : Symbol(export=, Decl(foobar.js, 0, 0))
>exports : Symbol(export=, Decl(foobar.js, 0, 0))
>a : Symbol(a, Decl(foobar.js, 0, 18))

View file

@ -0,0 +1,10 @@
[
"======== Resolving module 'foo/bar/foobar.js' from '/a.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo/bar/foobar.js'.",
"'paths' option is specified, looking for a pattern to match module name 'foo/bar/foobar.js'.",
"Module name 'foo/bar/foobar.js', matched pattern '*'.",
"Trying substitution 'node_modules/*', candidate module location: 'node_modules/foo/bar/foobar.js'.",
"File '/node_modules/foo/bar/foobar.js' exist - use it as a name resolution result.",
"======== Module name 'foo/bar/foobar.js' was successfully resolved to '/node_modules/foo/bar/foobar.js'. ========"
]

View file

@ -0,0 +1,14 @@
=== /a.ts ===
import foobar from "foo/bar/foobar.js";
>foobar : { a: number; }
=== /node_modules/foo/bar/foobar.js ===
module.exports = { a: 10 };
>module.exports = { a: 10 } : { a: number; }
>module.exports : { a: number; }
>module : { "/node_modules/foo/bar/foobar": { a: number; }; }
>exports : { a: number; }
>{ a: 10 } : { a: number; }
>a : number
>10 : 10

View file

@ -0,0 +1,23 @@
// @noImplicitReferences: true
// @traceResolution: true
// @allowJs: true
// @esModuleInterop: true
// @fullEmitPaths: true
// @Filename: /node_modules/foo/bar/foobar.js
module.exports = { a: 10 };
// @Filename: /a.ts
import foobar from "foo/bar/foobar.js";
// @Filename: /tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["node_modules/*", "src/types"]
},
"allowJs": true,
"outDir": "bin"
}
}