diff --git a/source/lib/config.ts b/source/lib/config.ts index eefb39cd..8e9e19b7 100644 --- a/source/lib/config.ts +++ b/source/lib/config.ts @@ -56,7 +56,9 @@ function getOptionsFromTsConfig(cwd: string): CompilerOptions { return parseJsonSourceFileConfigFileContent( readJsonConfigFile(configPath, sys.readFile), sys, - path.basename(configPath) + path.basename(configPath), + undefined, + configPath, ).options; } diff --git a/source/test/fixtures/ts-config-extends/config/base-config.json b/source/test/fixtures/ts-config-extends/config/base-config.json new file mode 100644 index 00000000..d1819f05 --- /dev/null +++ b/source/test/fixtures/ts-config-extends/config/base-config.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "strict": false + } +} diff --git a/source/test/fixtures/ts-config-extends/index.d.ts b/source/test/fixtures/ts-config-extends/index.d.ts new file mode 100644 index 00000000..6f3a1c51 --- /dev/null +++ b/source/test/fixtures/ts-config-extends/index.d.ts @@ -0,0 +1 @@ +export default function (foo: number): number | null; diff --git a/source/test/fixtures/ts-config-extends/index.js b/source/test/fixtures/ts-config-extends/index.js new file mode 100644 index 00000000..0d06f8dd --- /dev/null +++ b/source/test/fixtures/ts-config-extends/index.js @@ -0,0 +1,3 @@ +module.exports.default = foo => { + return foo > 0 ? foo : null; +}; diff --git a/source/test/fixtures/ts-config-extends/index.test-d.ts b/source/test/fixtures/ts-config-extends/index.test-d.ts new file mode 100644 index 00000000..58042641 --- /dev/null +++ b/source/test/fixtures/ts-config-extends/index.test-d.ts @@ -0,0 +1,12 @@ +import {expectType} from '../../..'; +import aboveZero from '.'; + +expectType(aboveZero(1)); + +function lookupHeadphonesManufacturer(color: 'blue' | 'black'): string { + if (color === 'blue') { + return 'beats'; + } else { + 'bose'; + } +} diff --git a/source/test/fixtures/ts-config-extends/package.json b/source/test/fixtures/ts-config-extends/package.json new file mode 100644 index 00000000..de6dc1db --- /dev/null +++ b/source/test/fixtures/ts-config-extends/package.json @@ -0,0 +1,3 @@ +{ + "name": "foo" +} diff --git a/source/test/fixtures/ts-config-extends/tsconfig.json b/source/test/fixtures/ts-config-extends/tsconfig.json new file mode 100644 index 00000000..d8776207 --- /dev/null +++ b/source/test/fixtures/ts-config-extends/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "./config/base-config", + "compilerOptions": { + "noImplicitReturns": true + } +} diff --git a/source/test/fixtures/utils.ts b/source/test/fixtures/utils.ts index cab9e6e7..0f05d31f 100644 --- a/source/test/fixtures/utils.ts +++ b/source/test/fixtures/utils.ts @@ -11,20 +11,20 @@ type Expectation = [number, number, 'error' | 'warning', string, (string | RegEx * @param expectations - Expected diagnostics. */ export const verify = (t: ExecutionContext, diagnostics: Diagnostic[], expectations: Expectation[]) => { - t.true(diagnostics.length === expectations.length); + t.deepEqual(diagnostics.length, expectations.length, 'Received different count of diagnostics than expected!'); for (const [index, diagnostic] of diagnostics.entries()) { - t.is(diagnostic.line, expectations[index][0]); - t.is(diagnostic.column, expectations[index][1]); - t.is(diagnostic.severity, expectations[index][2]); - t.is(diagnostic.message, expectations[index][3]); + t.is(diagnostic.line, expectations[index][0], `"line" for diagnostic ${index} doesn't match!`); + t.is(diagnostic.column, expectations[index][1], `"column" for diagnostic ${index} doesn't match!`); + t.is(diagnostic.severity, expectations[index][2], `"severity" for diagnostic ${index} doesn't match!`); + t.is(diagnostic.message, expectations[index][3], `"message" for diagnostic ${index} doesn't match!`); const filename = expectations[index][4]; if (typeof filename === 'string') { - t.is(diagnostic.fileName, filename); + t.is(diagnostic.fileName, filename, `"fileName" for diagnostic ${index} doesn't match!`); } else if (typeof filename === 'object') { - t.regex(diagnostic.fileName, filename); + t.regex(diagnostic.fileName, filename, `"fileName" for diagnostic ${index} doesn't match!`); } } }; diff --git a/source/test/test.ts b/source/test/test.ts index 7a837805..d949c146 100644 --- a/source/test/test.ts +++ b/source/test/test.ts @@ -305,3 +305,11 @@ test('fails if typings file is not found in the specified path', async t => { t.is(error.message, 'The type definition `unknown.d.ts` does not exist. Create one and try again.'); }); + +test('includes extended config files along with found ones', async t => { + const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/ts-config-extends')}); + + verify(t, diagnostics, [ + [6, 64, 'error', 'Not all code paths return a value.'], + ]); +});