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

SchematicTestRunner.runExternalSchematic fails with "The encoded data was not valid for encoding utf-8" #27643

Closed
1 task done
daniel-sc opened this issue May 15, 2024 · 3 comments · Fixed by #27644
Closed
1 task done
Labels

Comments

@daniel-sc
Copy link

daniel-sc commented May 15, 2024

Command

other

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

17.0.0

Description

With v18.0.0-rc.1 under some conditions (which exactly is unclear to me) SchematicTestRunner.runExternalSchematic fails with the following error: "The encoded data was not valid for encoding utf-8"

See e.g. https://github.com/daniel-sc/ng-extract-i18n-merge/actions/runs/9091527710/job/24986317152?pr=111

The exact same test runs fine with angular 17: https://github.com/daniel-sc/ng-extract-i18n-merge/actions/runs/9091527710/job/24986316954?pr=111

This is the line were it fails: https://github.com/daniel-sc/ng-extract-i18n-merge/blob/master/schematics/ng-add/index.spec.ts#L45 (unsure why the first invocation succeeds..)

Minimal Reproduction

  1. Checkout branch angular-18 from https://github.com/daniel-sc/ng-extract-i18n-merge
  2. remove package-lock.json
  3. run npm i --save-exact "@angular-devkit/architect@0.1800.0-rc.1" "@angular-devkit/core@18.0.0-rc.1" "@angular-devkit/schematics@18.0.0-rc.1" "@schematics/angular@18.0.0-rc.1" "@angular-devkit/build-angular@18.0.0-rc.1" "@angular/core@18.0.0-rc.1" "@angular/compiler-cli@18.0.0-rc.1"
  4. run npm run build
  5. run npm run test-coverage

Exception or Error

The encoded data was not valid for encoding utf-8
TypeError: The encoded data was not valid for encoding utf-8
    at TextDecoder.decode (node:internal/encoding:449:16)
    at C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\rules\template.js:38:44
    at C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\rules\base.js:135:23
    at C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\rules\base.js:89:20
    at C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\rules\base.js:113:30
    at C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:278:13
    at C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:51:61
    at Array.forEach (<anonymous>)
    at HostDirEntry.visit (C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:51:43)
    at HostCreateTree.visit (C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:277:19)
    at C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\rules\base.js:109:14
    at callRuleAsync (C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\rules\call.js:77:24)
    at C:\projekte\ng-extract-i18n-merge\node_modules\@angular-devkit\schematics\src\rules\call.js:69:63
    at doInnerSub (C:\projekte\ng-extract-i18n-merge\node_modules\rxjs\src\internal\operators\mergeInternals.ts:71:15)
    at outerNext (C:\projekte\ng-extract-i18n-merge\node_modules\rxjs\src\internal\operators\mergeInternals.ts:53:58)
    at OperatorSubscriber._this._next (C:\projekte\ng-extract-i18n-merge\node_modules\rxjs\src\internal\operators\OperatorSubscriber.ts:70:13)
    at OperatorSubscriber.Object.<anonymous>.Subscriber.next (C:\projekte\ng-extract-i18n-merge\node_modules\rxjs\src\internal\Subscriber.ts:75:12)
    at C:\projekte\ng-extract-i18n-merge\node_modules\rxjs\src\internal\operators\mergeInternals.ts:85:24
    at OperatorSubscriber._this._next (C:\projekte\ng-extract-i18n-merge\node_modules\rxjs\src\internal\operators\OperatorSubscriber.ts:70:13)
    at OperatorSubscriber.Object.<anonymous>.Subscriber.next (C:\projekte\ng-extract-i18n-merge\node_modules\rxjs\src\internal\Subscriber.ts:75:12)
    at C:\projekte\ng-extract-i18n-merge\node_modules\rxjs\src\internal\observable\innerFrom.ts:90:24

Your Environment

Angular CLI: 17.3.3
Node: 20.12.0
Package Manager: npm 10.5.0
OS: win32 x64

Angular: 18.0.0-rc.1
... compiler-cli, core

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1800.0-rc.1
@angular-devkit/core         18.0.0-rc.1
@angular-devkit/schematics   18.0.0-rc.1
@schematics/angular          18.0.0-rc.1
typescript                   5.4.5

Anything else relevant?

No response

@alan-agius4
Copy link
Collaborator

alan-agius4 commented May 15, 2024

This is caused by a long standing bug in Jest which causes instanceof not to work correctly.

See: jestjs/jest#2549

For context this is happening due to the changes in #27570

@daniel-sc
Copy link
Author

@alan-agius4 thanks for the pointers!

It would be great if this could be adressed, as this breaks unit tests of schematics with jest and probably impacts some libraries..

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue May 15, 2024
…atic fails with "The encoded data was not valid for encoding utf-8"

When using Jest instanceof does not work correctly. See: jestjs/jest#2549

Closes: angular#27643
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue May 15, 2024
…matic` fails with "The encoded data was not valid for encoding utf-8"

When using Jest instanceof does not work correctly. See: jestjs/jest#2549

Closes: angular#27643
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue May 15, 2024
…matic` fails with "The encoded data was not valid for encoding utf-8"

When using Jest instanceof does not work correctly. See: jestjs/jest#2549

Closes: angular#27643
alan-agius4 added a commit that referenced this issue May 15, 2024
…matic` fails with "The encoded data was not valid for encoding utf-8"

When using Jest instanceof does not work correctly. See: jestjs/jest#2549

Closes: #27643
alan-agius4 added a commit that referenced this issue May 15, 2024
…matic` fails with "The encoded data was not valid for encoding utf-8"

When using Jest instanceof does not work correctly. See: jestjs/jest#2549

Closes: #27643
(cherry picked from commit 7b52b98)
alan-agius4 added a commit that referenced this issue May 15, 2024
…matic` fails with "The encoded data was not valid for encoding utf-8"

When using Jest instanceof does not work correctly. See: jestjs/jest#2549

Closes: #27643
(cherry picked from commit 7b52b98)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants