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

resolve conflicts in "feat/jest24" PR #230

Closed
wants to merge 4 commits into from

Conversation

virtuoushub
Copy link

Brought in latest from the master branch and used ts-jest@24.0.0

To resolve conflicts in #224

iRoyPeleg and others added 4 commits February 7, 2019 08:42
This PR introduces jsdom v13 as default test environment for jest-preset-angular. This is achieved by
* Adding [jest-environment-jsdom-thirteen](https://github.com/theneva/jest-environment-jsdom-thirteen) as dependency
* Adding `testEnvironment: 'jest-environment-jsdom-thirteen' to `jest-preset.js`
* Removing Web Storage API mocks from `example/jestGlobalmocks.ts`
* Adding instructions in README Troubleshooting to configure usage of jsdom v11 (one line in jest configuration)

I added tests in a second commit to confirm it works, but I think they do not have to end up in the repository, as they basically test, what is already tested in jsdom itself.


Closes thymikee#216
@virtuoushub virtuoushub changed the title Feat/jest24 resolve conflicts in "feat/jest24" PR Feb 19, 2019
@virtuoushub
Copy link
Author

Not sure why ci/circleci: install-test-example failed:

#!/bin/bash -eo pipefail
cd example
yarn test:ci
yarn test:coverage

yarn run v1.13.0
$ jest --runInBand
● Validation Error:

  Module jest-preset-angular should have "jest-preset.js" or "jest-preset.json" file at the root.

  Configuration Documentation:
  https://jestjs.io/docs/configuration.html

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code 1

When I run it locally:

 foo@bar  F:\oo\jest-preset-angular   feat/jest24 ≣                                                                                                      [09:22:19 PM]
❯ pwd

Path
----
F:\oo\jest-preset-angular


 foo@bar  F:\oo\jest-preset-angular   feat/jest24 ≣                                                                                                      [09:22:20 PM]
❯ cd .\example\
 foo@bar  F:\oo\jest-preset-angular\example   feat/jest24 ≣                                                                                              [09:22:23 PM]
❯ yarn test:ci
yarn run v1.13.0
$ jest --runInBand
ts-jest[versions] (WARN) Version 24.0.0 of jest installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=22.0.0 <24.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
 PASS  src/app/service/hero.service.spec.ts
 PASS  src/app/app.component.spec.ts
 PASS  src/app/on-push/on-push.component.spec.ts
 PASS  src/app/heroes/heroes.component.spec.ts
 PASS  src/app/simple/simple.component.spec.ts
 PASS  src/app/calc/calc.component.spec.ts

Test Suites: 6 passed, 6 total
Tests:       17 passed, 17 total
Snapshots:   6 passed, 6 total
Time:        4.433s
Ran all test suites.
Done in 5.72s.
 foo@bar  F:\oo\jest-preset-angular\example   feat/jest24 ≣                                                                                              [09:22:32 PM]
❯ yarn test:coverage
yarn run v1.13.0
$ jest --coverage
ts-jest[versions] (WARN) Version 24.0.0 of jest installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=22.0.0 <24.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
ts-jest[versions] (WARN) Version 24.0.0 of jest installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=22.0.0 <24.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
ts-jest[versions] (WARN) Version 24.0.0 of jest installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=22.0.0 <24.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
ts-jest[versions] (WARN) Version 24.0.0 of jest installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=22.0.0 <24.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
ts-jest[versions] (WARN) Version 24.0.0 of jest installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=22.0.0 <24.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
ts-jest[versions] (WARN) Version 24.0.0 of jest installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=22.0.0 <24.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
 PASS  src/app/service/hero.service.spec.ts
 PASS  src/app/calc/calc.component.spec.ts
 PASS  src/app/simple/simple.component.spec.ts
 PASS  src/app/on-push/on-push.component.spec.ts
 PASS  src/app/heroes/heroes.component.spec.ts
 PASS  src/app/app.component.spec.ts
------------------------|----------|----------|----------|----------|-------------------|
File                    |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------------------|----------|----------|----------|----------|-------------------|
All files               |    96.94 |       50 |     87.5 |     96.1 |                   |
 src                    |       75 |      100 |        0 |       75 |                   |
  jestGlobalMocks.ts    |    66.67 |      100 |        0 |    66.67 |              7,19 |
  setupJest.ts          |      100 |      100 |      100 |      100 |                   |
 src/app                |      100 |      100 |      100 |      100 |                   |
  app.component.html    |      100 |      100 |      100 |      100 |                   |
  app.component.ts      |      100 |      100 |      100 |      100 |                   |
 src/app/calc           |      100 |      100 |      100 |      100 |                   |
  calc.component.ts     |      100 |      100 |      100 |      100 |                   |
 src/app/heroes         |      100 |      100 |      100 |      100 |                   |
  heroes.component.html |      100 |      100 |      100 |      100 |                   |
  heroes.component.ts   |      100 |      100 |      100 |      100 |                   |
 src/app/on-push        |      100 |      100 |      100 |      100 |                   |
  on-push.component.ts  |      100 |      100 |      100 |      100 |                   |
 src/app/service        |    95.45 |      100 |    83.33 |    94.44 |                   |
  hero.service.ts       |    95.45 |      100 |    83.33 |    94.44 |                20 |
 src/app/simple         |      100 |      100 |      100 |      100 |                   |
  simple.component.html |      100 |      100 |      100 |      100 |                   |
  simple.component.ts   |      100 |      100 |      100 |      100 |                   |
 src/lib/testing        |      100 |       50 |      100 |      100 |                   |
  config.helpers.ts     |      100 |       50 |      100 |      100 |                10 |
  index.ts              |      100 |      100 |      100 |      100 |                   |
------------------------|----------|----------|----------|----------|-------------------|

Test Suites: 6 passed, 6 total
Tests:       17 passed, 17 total
Snapshots:   6 passed, 6 total
Time:        6.112s
Ran all test suites.
Done in 7.48s.
 foo@bar  F:\oo\jest-preset-angular\example   feat/jest24 ≣                                                                                              [09:22:44 PM]

@ahnpnl
Copy link
Collaborator

ahnpnl commented Feb 19, 2019

Could it be cache related ?

@wtho
Copy link
Collaborator

wtho commented Feb 19, 2019

I get the same error when I checkout your branch in a clean workspace and run

yarn install
cd example
yarn install
yarn test:ci

I cannot tell you what exactly triggers this error, but whenever I had this error before, something with the jest config in the example project or in node_modules/jest-preset-angular/jest-preset.js did not work out. Jest does not give more information why it does not like the configuration though (@thymikee might be an enhancement for jest some time)

@thymikee
Copy link
Owner

Inspected a bit and this is what happens:

TypeError: Cannot read property 'concat' of undefined
    at Object.<anonymous> (<<REPLACE>>/jest-preset-angular/example/node_modules/jest-preset-angular/jest-preset.js:21:55)

Looks like ts-jest/presets has no defaults now. Also, the defaults can be obtained through jest-config, but I think the easiest is to go with a custom array. Something like ['ts', 'js', 'json', 'html'] makes sense, becuase this project doesn't need to resolve neither tsx, nor jsx nor node.

Anyway, the kulshekhar/ts-jest#957 was merged and released as stable too quickly, it still has issues around Babel resolution.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Feb 19, 2019

it's kind of weird because v24 generated changelog doesn't include anything about no defaults.

@wtho
Copy link
Collaborator

wtho commented Feb 19, 2019

Actually it has defaults, but it only contains the transform-declaration, no moduleFileExtensions.

A dirty workaround (till we figure out what changed) would be:

(defaults.moduleFileExtensions || []).concat(['html'])

@thymikee
Copy link
Owner

it's kind of weird because v24 generated changelog doesn't include anything about no defaults.

It's likely a bug

(defaults.moduleFileExtensions || []).concat(['html'])

This is not a good workaround, as Jest will only resolve to html files :D

@thymikee
Copy link
Owner

Btw, feel free to send a PR to Jest. Should be as easy as adding this diff:

diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js
index 4c2bee56f..f938d520e 100644
--- a/packages/jest-config/src/normalize.js
+++ b/packages/jest-config/src/normalize.js
@@ -95,9 +95,11 @@ const setupPreset = (
     // $FlowFixMe
     preset = (require(presetModule): InitialOptions);
   } catch (error) {
-    if (error instanceof SyntaxError) {
+    if (error instanceof SyntaxError || error instanceof TypeError) {
       throw createConfigError(
-        `  Preset ${chalk.bold(presetPath)} is invalid:\n  ${error.message}`,
+        `  Preset ${chalk.bold(presetPath)} is invalid:\n\n  ${
+          error.message
+        }\n  ${error.stack}`,
       );
     }

And updating/adding a test and a changelog. Free contribution is waiting! 😄

@thymikee
Copy link
Owner

And the output looks like this:

screenshot 2019-02-19 at 11 42 47

@wtho
Copy link
Collaborator

wtho commented Feb 19, 2019

The culprit is here 😅 :

kulshekhar/ts-jest@1d67101#diff-ad00ea7d7e62419810391b7b4dfaadf0L11

The default config from the jest-config package is not loaded anymore.

@thymikee
Copy link
Owner

Heh, yea, it's now not necessary. Forgot about it. Anyway, we should set moduleFileExtensions to be the best match for Angular (so the resolution is as quick as possible)

@virtuoushub
Copy link
Author

closing this pull request as it's inclusion of ts-jest@^24.0.0 was premature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants