test(ivy): support chdir() on the compiler's filesystem abstraction (#33828)
This commit adds the ability to change directories using the compiler's internal filesystem abstraction. This is a prerequisite for writing tests which are sensitive to the current working directory. In addition to supporting the `chdir()` operation, this commit also fixes `getDefaultLibLocation()` for mock filesystems to not assume `node_modules` is in the current directory, but to resolve it similarly to how Node does by progressively looking higher in the directory tree. PR Close #33828
This commit is contained in:
@ -35,7 +35,8 @@ export class NgtscTestEnvironment {
|
||||
/**
|
||||
* Set up a new testing environment.
|
||||
*/
|
||||
static setup(files?: Folder): NgtscTestEnvironment {
|
||||
static setup(files?: Folder, workingDir: AbsoluteFsPath = absoluteFrom('/')):
|
||||
NgtscTestEnvironment {
|
||||
const fs = getFileSystem();
|
||||
if (files !== undefined && fs instanceof MockFileSystem) {
|
||||
fs.init(files);
|
||||
@ -44,7 +45,8 @@ export class NgtscTestEnvironment {
|
||||
const host = new AugmentedCompilerHost(fs);
|
||||
setWrapHostForTest(makeWrapHost(host));
|
||||
|
||||
const env = new NgtscTestEnvironment(fs, fs.resolve('/built'), absoluteFrom('/'));
|
||||
const env = new NgtscTestEnvironment(fs, fs.resolve('/built'), workingDir);
|
||||
fs.chdir(workingDir);
|
||||
|
||||
env.write(absoluteFrom('/tsconfig-base.json'), `{
|
||||
"compilerOptions": {
|
||||
@ -54,7 +56,6 @@ export class NgtscTestEnvironment {
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"outDir": "built",
|
||||
"rootDir": ".",
|
||||
"baseUrl": ".",
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
|
Reference in New Issue
Block a user