Skip to content

Commit

Permalink
Use different current directories for internal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kulshekhar committed Oct 6, 2017
1 parent 051a2d3 commit f98651c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ function readCompilerOptions(configPath: string) {
return parsedConfig.options;
}

function getStartDir(): string {
// This is needed because of the way our tests are structured.
// If this is being executed as a library (under node_modules)
// we want to start with the project directory that's three
// levels above.
// If t his is being executed from the test suite, we want to start
// in the directory of the test

const grandparent = path.resolve(__dirname, '..', '..');
if (grandparent.endsWith('/node_modules')) {
return path.resolve(grandparent, '..');
}
return '.';
}

function getPathToClosestTSConfig(
startDir?: string,
previousDir?: string,
Expand All @@ -122,7 +137,7 @@ function getPathToClosestTSConfig(
// find and return the path to the first encountered tsconfig.json file

if (!startDir) {
return getPathToClosestTSConfig('.');
return getPathToClosestTSConfig(getStartDir());
}

const tsConfigPath = path.join(startDir, 'tsconfig.json');
Expand Down

0 comments on commit f98651c

Please sign in to comment.