Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4.0.0-beta.0: extends in tsconfig.json does not work as expected. #144

Open
yohodopo opened this issue Jan 9, 2019 · 11 comments
Open

V4.0.0-beta.0: extends in tsconfig.json does not work as expected. #144

yohodopo opened this issue Jan 9, 2019 · 11 comments
Assignees
Labels

Comments

@yohodopo
Copy link
Contributor

yohodopo commented Jan 9, 2019

tsConfig.json

{
  "extends": "./.temp/tsconfig-base.json"
}

tsconfig-base.json


{
  "include": ["../src/**/*", "../types/**/*.d.ts", "./loader-types.d.ts", "./client-types.d.ts"],
  "exclude": ["../src/**/*.spec.ts", "../src/**/*.spec.js"],
  "compilerOptions": {
    "strict": true,
    "skipLibCheck": true,
    "module": "esnext",
    "target": "es6",
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "lib": ["dom", "es6", "dom.iterable", "scripthost"],
    "noEmitHelpers": true,
    "importHelpers": true,
    "inlineSources": true,
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "baseUrl": ".",
    "paths": {
      "~ngAppModule": ["./ng-app-module"]
    },
    "outDir": "../dist/",
    "rootDir": "../src"
  }
}

When I tried debugging this issue, it logs
{"extends":"./.temp/tsconfig-base.json","compilerOptions":{}} at https://github.com/vuejs/vue-jest/blob/master/lib/compilers/typescript-compiler.js#L11

related to #118

@eddyerburgh eddyerburgh added the bug label Jan 9, 2019
@ibuchan72390
Copy link

I can confirm this issue as well. I have been attempting to implement testing in Nuxt leveraging Jest. The default recommended config for nuxt-ts is:

{
  "extends": "./node_modules/nuxt-ts/tsconfig.nuxt-ts.json"
}

Eventually I chased it down to a failure to load the extended attributes into the referenced object as previously mentioned by @yohodopo

@FeliciousX
Copy link

can confirm this is happening aswell :(

i was trying to debug why my typescript decorator is having it's 3rd argument as undefined in the test but has value in app code.

NOTE The Property Descriptor will be undefined if your script target is less than ES5.

I assumed it was in vue-jest because it was trying to test a .vue file with lang="ts"

I tried tweaking the tsConfig option for vue-jest and finally managed to reproduce it if i didn't extend my config.. which is where my target option lies

@IlCallo
Copy link

IlCallo commented Apr 29, 2020

From what I read, vue-jest v3 uses a very old package to resolve tsconfig.json, needed before TypeScript exposed config resolution features.
This package doesn't support configuration inheritance. A PR has been started, but never finished and merged.

I found this bug while making Quasar framework work nicely with TS and Jest, in which a esModuleInterop property from a preset configuration wasn't being picked up in the extending configuration, while everything worked fine when adding the property directly on the former.

Anyway, seems like the new V4 will support ts-jest which should manage inheritance correctly (it used native TS configuration management), so I guess the problem will be solved in some time.

Cya!

@vegerot
Copy link

vegerot commented Nov 30, 2020

I am using "@vue/cli-service": "4.5.8", and still experience this issue.

To test I:

  1. Made a valid tsconfig.json (without extends), ran my test suite, and they passed
  2. moved tsconfig.json to tsconfig.base.json and created tsconfig.json with contents:
{
  "extends": "./tsconfig.base.json"
}
  1. Ran tests again, and they fail

@mdo2
Copy link

mdo2 commented Mar 15, 2021

I am using "@vue/cli-service": "4.5.8", and still experience this issue.

To test I:

  1. Made a valid tsconfig.json (without extends), ran my test suite, and they passed
  2. moved tsconfig.json to tsconfig.base.json and created tsconfig.json with contents:
{
  "extends": "./tsconfig.base.json"
}
  1. Ran tests again, and they fail

Same here!

Please, provide some feedback

@mjeanroy
Copy link

mjeanroy commented Mar 17, 2021

Hi,

I encoutered the same issue, and I wrote this workaround in my jest.config.js:

const path = require('path');
const tsc = require('typescript');

module.exports = {
  globals: {
    'vue-jest': {
      tsConfig: extractTsConfig(),
    },
  },
};

function extractTsConfig() {
  const tsConfigPath = tsc.findConfigFile(process.cwd(), (fileName) => tsc.sys.fileExists(fileName));
  if (!tsConfigPath) {
      return;
  }

  const loaded = tsc.readConfigFile(tsConfigPath, (file) => tsc.sys.readFile(file));
  if (loaded.error) {
      throw new Error(loaded.error);
  }

  const basePath = path.dirname(tsConfigPath);
  const parsedConfig = tsc.parseJsonConfigFileContent(loaded.config, tsc.sys, basePath);
  if (parsedConfig.errors.length > 0) {
      throw new Error(`Errors occurred while reading ${tsConfigPath}: ${parsedConfig.errors}`);
  }

  return {
    compilerOptions: parsedConfig.options,
  };
}

I would be happy to open a PR with a more general fix if it interests someone.

@vegerot
Copy link

vegerot commented Mar 17, 2021

@mjeanroy I am interested

@mjeanroy
Copy link

Hi @lmiller1990,
Would you be interested in a PR to fix this issue?
Or is there any plan in a next release, so a fix like this would be useless?

@lmiller1990
Copy link
Member

Yes this would be welcome, I can do a release if we have a fix!

@mjeanroy
Copy link

mjeanroy commented Mar 25, 2021

Hi @lmiller1990,

I just look at the code on the master branch and it looks like this issue is fixed with version 4.0.0 (not tested, but, as already said by @IlCallo, since it uses ts-jest to resolve ts config, it should be fixed).

The main problem is that version ^3.0.7 is the version currently shipped with latest @vue/cli-plugin-unit-jest, so it may be an issue for some users until a new major version of @vue/cli-plugin-unit-jest is released.

Are you still interested in a fix for the vue-jest@^3.0.7 branch or do you prefer to wait for a new major version of vue-cli?

@lmiller1990
Copy link
Member

lmiller1990 commented Mar 26, 2021

3.x has not been updated in a long time. Even if you fix it, updating vue-cli would need to happen as well.

I don't think it makes sense to update 3.x at this point. People should just upgrade to 4.x. If you like, you could open an issue in vue-cli to update the plugin to 4.x. I don't think this is a major breaking change so it shouldn't be too much trouble.

Also I think we need to review/merge this up? #324

@nogic1008 nogic1008 self-assigned this Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants