Skip to content

Commit 4abb18b

Browse files
committed
fix(@angular-devkit/schematics): SchematicTestRunner.runExternalSchematic 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
1 parent 9ce8fef commit 4abb18b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/angular_devkit/schematics/src/tree/host-tree.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ export class HostTree implements Tree {
304304
// With the `fatal` option enabled, invalid data will throw a TypeError
305305
return decoder.decode(data);
306306
} catch (e) {
307-
if (e instanceof TypeError) {
307+
// The second part should not be needed. But Jest does not support instanceof correctly.
308+
// See: https://github.com/jestjs/jest/issues/2549
309+
if (
310+
e instanceof TypeError ||
311+
(e as NodeJS.ErrnoException).code === 'ERR_ENCODING_INVALID_ENCODED_DATA'
312+
) {
308313
throw new Error(`Failed to decode "${path}" as UTF-8 text.`);
309314
}
310315
throw e;

0 commit comments

Comments
 (0)