Skip to content

Commit

Permalink
fix(@angular-devkit/schematics): SchematicTestRunner.runExternalSchem…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
alan-agius4 committed May 15, 2024
1 parent 9ce8fef commit d94ab9d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/angular_devkit/schematics/src/tree/host-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,12 @@ export class HostTree implements Tree {
// With the `fatal` option enabled, invalid data will throw a TypeError
return decoder.decode(data);
} catch (e) {
if (e instanceof TypeError) {
// The second part should not be needed. But Jest does not support instanceof correctly.
// See: https://github.com/jestjs/jest/issues/2549
if (
e instanceof TypeError ||
(e as NodeJS.ErrnoException).code === 'ERR_ENCODING_INVALID_ENCODED_DATA'
) {
throw new Error(`Failed to decode "${path}" as UTF-8 text.`);
}
throw e;
Expand Down

0 comments on commit d94ab9d

Please sign in to comment.